Class: Typhoid::TyphoeusDecorator
- Inherits:
-
Object
- Object
- Typhoid::TyphoeusDecorator
show all
- Defined in:
- lib/typhoid/typhoeus_decorator.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of TyphoeusDecorator.
39
40
41
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 39
def initialize(source)
@source = source
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 70
def method_missing(method_name, *args, &block)
if source.respond_to? method_name
source.public_send method_name, *args, &block
else
super
end
end
|
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
37
38
39
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 37
def source
@source
end
|
Class Method Details
.decorate(typhoeus_klass) ⇒ Object
3
4
5
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 3
def self.decorate(typhoeus_klass)
@source_klass = typhoeus_klass
end
|
.inspect ⇒ Object
33
34
35
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 33
def self.inspect
"#{self.name}Decorator(#{source_klass.name})"
end
|
.method_missing(method_name, *args, &block) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 21
def self.method_missing(method_name, *args, &block)
if source_klass.respond_to? method_name
source_klass.public_send method_name, *args, &block
else
super
end
end
|
.new(*args, &block) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 11
def self.new(*args, &block)
if args.first.is_a?(self)
args.first
elsif args.first.is_a?(source_klass)
super
else
super(source_klass.new(*args, &block))
end
end
|
.respond_to?(method_name, include_private = false) ⇒ Boolean
29
30
31
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 29
def self.respond_to?(method_name, include_private = false)
source_klass.respond_to?(method_name) || super
end
|
.source_klass ⇒ Object
7
8
9
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 7
def self.source_klass
@source_klass
end
|
Instance Method Details
#==(other) ⇒ Object
43
44
45
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 43
def ==(other)
other == source
end
|
#compat(method_names, *args, &block) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 56
def compat(method_names, *args, &block)
method_to_call = Array(method_names).find { |method_name| respond_to? method_name }
if method_to_call
source.public_send method_to_call, *args, &block
else
raise TyphoeusCompatabilityError,
"Typhoeus API has changed, we don't know how to get response. We know about [:handled_response, :response]"
end
end
|
#inspect ⇒ Object
66
67
68
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 66
def inspect
"#<#{self.class.name} source: (#{source.inspect})>"
end
|
#instance_of?(klass) ⇒ Boolean
52
53
54
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 52
def instance_of?(klass)
super || source.instance_of?(klass)
end
|
#kind_of?(klass) ⇒ Boolean
Also known as:
is_a?
47
48
49
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 47
def kind_of?(klass)
super || source.kind_of?(klass)
end
|
#respond_to?(method_name, include_private = false) ⇒ Boolean
78
79
80
|
# File 'lib/typhoid/typhoeus_decorator.rb', line 78
def respond_to?(method_name, include_private = false)
source.respond_to?(method_name) || super
end
|