Class: DProxy
- Inherits:
-
Object
- Object
- DProxy
- Defined in:
- lib/stack-service-base/db_ext/db_proxy.rb
Instance Method Summary collapse
- #_clone ⇒ Object
- #clone(*args, **kwargs, &block) ⇒ Object
- #indent(str) ⇒ Object
-
#initialize(dataset, model, path = [], &block) ⇒ DProxy
constructor
A new instance of DProxy.
- #method_missing(name, *args, **kwargs, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #wrap?(r) ⇒ Boolean
Constructor Details
#initialize(dataset, model, path = [], &block) ⇒ DProxy
Returns a new instance of DProxy.
6 7 8 |
# File 'lib/stack-service-base/db_ext/db_proxy.rb', line 6 def initialize(dataset, model, path = [], &block) @model, @dataset, @final, @path = model, dataset, block, path end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/stack-service-base/db_ext/db_proxy.rb', line 11 def method_missing(name, *args, **kwargs, &block) all_args = [*args, **kwargs, block:].reject(&:nil?) # indent "DProxy::#{@model} #{name}(#{all_args}) => IN" unless QUIET response = if @final && name.to_sym == :all @final.call self, *all_args else @dataset.send(name, *args, **kwargs, &block) end # indent "DProxy::#{@model} #{name}(#{all_args}) OUT => #{response.inspect}" unless QUIET wrap?(response) ? self.class.new(response, @model, @path + [name => all_args, prev: self], &@final) : response end |
Instance Method Details
#_clone ⇒ Object
30 |
# File 'lib/stack-service-base/db_ext/db_proxy.rb', line 30 alias_method :_clone, :clone |
#clone(*args, **kwargs, &block) ⇒ Object
32 33 34 |
# File 'lib/stack-service-base/db_ext/db_proxy.rb', line 32 def clone( *args, **kwargs, &block) method_missing(:clone, *args, **kwargs, &block) end |
#indent(str) ⇒ Object
10 |
# File 'lib/stack-service-base/db_ext/db_proxy.rb', line 10 def indent(str) = puts "\t" * @path.size + str |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
26 27 28 |
# File 'lib/stack-service-base/db_ext/db_proxy.rb', line 26 def respond_to_missing?(method_name, include_private = false) @dataset.respond_to?(method_name, include_private) end |