Class: Faraday::RackBuilder::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday/rack_builder.rb

Overview

borrowed from ActiveSupport::Dependencies::Reference & ActionDispatch::MiddlewareStack::Middleware

Constant Summary collapse

@@constants_mutex =
Mutex.new
@@constants =
Hash.new { |h, k|
  value = k.respond_to?(:constantize) ? k.constantize : Object.const_get(k)
  @@constants_mutex.synchronize { h[k] = value }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, *args, &block) ⇒ Handler

Returns a new instance of Handler.



26
27
28
29
30
31
32
# File 'lib/faraday/rack_builder.rb', line 26

def initialize(klass, *args, &block)
  @name = klass.to_s
  if klass.respond_to?(:name)
    @@constants_mutex.synchronize { @@constants[@name] = klass }
  end
  @args, @block = args, block
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/faraday/rack_builder.rb', line 24

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/faraday/rack_builder.rb', line 37

def ==(other)
  if other.is_a? Handler
    self.name == other.name
  elsif other.respond_to? :name
    klass == other
  else
    @name == other.to_s
  end
end

#build(app) ⇒ Object



47
48
49
# File 'lib/faraday/rack_builder.rb', line 47

def build(app)
  klass.new(app, *@args, &@block)
end

#inspectObject



35
# File 'lib/faraday/rack_builder.rb', line 35

def inspect() @name end

#klassObject



34
# File 'lib/faraday/rack_builder.rb', line 34

def klass() @@constants[@name] end