Class: Peaty::Proxy
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#options ⇒ Object
Returns the value of attribute options.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
- #filter(*args) ⇒ Object
-
#initialize(target, connection, options = {}) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(target, connection, options = {}) ⇒ Proxy
Returns a new instance of Proxy.
6 7 8 |
# File 'lib/peaty/proxy.rb', line 6 def initialize(target, connection, = {}) @target, @connection, @options = target, connection, .with_indifferent_access end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/peaty/proxy.rb', line 10 def method_missing(method, *args) return @target.method(method).unbind.bind(self).call(*args) if @target.class.respond_to?(method) = args. args << @options.merge() @target.with_connection(@connection).send(method, *args) end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
4 5 6 |
# File 'lib/peaty/proxy.rb', line 4 def connection @connection end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/peaty/proxy.rb', line 4 def @options end |
#target ⇒ Object
Returns the value of attribute target.
4 5 6 |
# File 'lib/peaty/proxy.rb', line 4 def target @target end |
Class Method Details
.build(attrs = {}) ⇒ Object
28 29 30 |
# File 'lib/peaty/proxy.rb', line 28 def self.build(attrs = {}) @target.build(@options.merge(attrs.with_indifferent_access)) end |
Instance Method Details
#filter(*args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/peaty/proxy.rb', line 17 def filter(*args) = args. .each do |(key, value)| @options[key] = Array.wrap(@options.delete(:key)).concat(Array.wrap(value)) end @options[:rest] = Array.wrap(@options.delete(:rest)).concat(args) self end |