Class: OpenID::Yadis::TransformFilterMaker

Inherits:
Object
  • Object
show all
Defined in:
lib/openid/yadis/filters.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter_procs) ⇒ TransformFilterMaker

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.



75
76
77
# File 'lib/openid/yadis/filters.rb', line 75

def initialize(filter_procs)
  @filter_procs = filter_procs
end

Instance Attribute Details

#filter_procsObject (readonly)

Returns the value of attribute filter_procs.



67
68
69
# File 'lib/openid/yadis/filters.rb', line 67

def filter_procs
  @filter_procs
end

Instance Method Details

#apply_filters(endpoint) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# 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) ⇒ Object

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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