class OpenID::Yadis::TransformFilterMaker

Take a list of basic filters and makes a filter that transforms the basic filter into a top-level filter. This is mostly useful for the implementation of make_filter, which should only be needed for special cases or internal use by this library.

This object is useful for creating simple filters for services that use one URI and are specified by one Type (we expect most Types will fit this paradigm).

Creates a BasicServiceEndpoint object and apply the filter functions to it until one of them returns a value.

Attributes

filter_procs[R]

Public Class Methods

new(filter_procs) click to toggle source

Initialize the filter maker's state

filter_functions are the endpoint transformer Procs to apply to the basic endpoint. These are called in turn until one of them does not return nil, and the result of that transformer is returned.

# File lib/openid/yadis/filters.rb, line 75
def initialize(filter_procs)
  @filter_procs = filter_procs
end

Public Instance Methods

apply_filters(endpoint) click to toggle source
# File lib/openid/yadis/filters.rb, line 100
def apply_filters(endpoint)
  # Apply filter procs to an endpoint until one of them returns
  # non-nil.
  @filter_procs.each { |filter_proc|
    e = filter_proc.call(endpoint)
    if !e.nil?
      # Once one of the filters has returned an endpoint, do not
      # apply any more.
      return e
    end
  }

  return nil
end
get_service_endpoints(yadis_url, service_element) click to toggle source

Returns an array of endpoint objects produced by the filter procs.

# File lib/openid/yadis/filters.rb, line 81
def get_service_endpoints(yadis_url, service_element)
  endpoints = []

  # Do an expansion of the service element by xrd:Type and
  # xrd:URI
  Yadis::expand_service(service_element).each { |type_uris, uri, _|
    # Create a basic endpoint object to represent this
    # yadis_url, Service, Type, URI combination
    endpoint = BasicServiceEndpoint.new(
          yadis_url, type_uris, uri, service_element)

    e = apply_filters(endpoint)
    if !e.nil?
      endpoints << e
    end
  }
  return endpoints
end