Class: Rack::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-chain/version.rb,
lib/rack/chain.rb

Defined Under Namespace

Modules: Linker Classes: Link

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, filters = []) ⇒ Chain

Returns a new instance of Chain.



20
21
22
23
# File 'lib/rack/chain.rb', line 20

def initialize(endpoint, filters = [])
  @endpoint = endpoint
  @filters  = filters
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



5
6
7
# File 'lib/rack/chain.rb', line 5

def endpoint
  @endpoint
end

#filtersObject

Returns the value of attribute filters.



6
7
8
# File 'lib/rack/chain.rb', line 6

def filters
  @filters
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/rack/chain.rb', line 25

def call(env)
  Link.new(filters.reverse.inject(endpoint) do |endpt,filter|
             if filter.respond_to?(:[])
               filter[Link.new(endpt)]
             else
               filter.new(Link.new(endpt))
             end
           end).call(env)
end