Class: Filemaker::Model::Relations::Proxy
- Inherits:
-
Object
- Object
- Filemaker::Model::Relations::Proxy
- Defined in:
- lib/filemaker/model/relations/proxy.rb
Overview
A proxy is a class to send all unknown methods to it’s target. The target here will be the eventual associated model.
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(owner, name, options) ⇒ Proxy
constructor
A new instance of Proxy.
-
#method_missing(name, *args, &block) ⇒ Object
Rubocop will complain and ask to fallback on ‘super`, but we won’t be able to do that because the target may have method that throw exception.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #target_class ⇒ Object
Constructor Details
#initialize(owner, name, options) ⇒ Proxy
Returns a new instance of Proxy.
17 18 19 20 21 22 |
# File 'lib/filemaker/model/relations/proxy.rb', line 17 def initialize(owner, name, ) @owner = owner @name = name @options = @class_name = .fetch(:class_name) { name.to_s.classify } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Rubocop will complain and ask to fallback on ‘super`, but we won’t be able to do that because the target may have method that throw exception
32 33 34 |
# File 'lib/filemaker/model/relations/proxy.rb', line 32 def method_missing(name, *args, &block) target.send(name, *args, &block) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/filemaker/model/relations/proxy.rb', line 12 def @options end |
#owner ⇒ Object
Returns the value of attribute owner.
12 13 14 |
# File 'lib/filemaker/model/relations/proxy.rb', line 12 def owner @owner end |
#target ⇒ Object
Returns the value of attribute target.
12 13 14 |
# File 'lib/filemaker/model/relations/proxy.rb', line 12 def target @target end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
36 37 38 |
# File 'lib/filemaker/model/relations/proxy.rb', line 36 def respond_to_missing?(method_name, include_private = false) super end |
#target_class ⇒ Object
24 25 26 27 |
# File 'lib/filemaker/model/relations/proxy.rb', line 24 def target_class return @class_name if @class_name.is_a?(Class) @class_name.constantize end |