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.
Class Method Summary collapse
-
.init(owner, name, options) ⇒ Object
Create will not return the proxy if target was NilClass.
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
39 40 41 |
# File 'lib/filemaker/model/relations/proxy.rb', line 39 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 |
Class Method Details
.init(owner, name, options) ⇒ Object
Create will not return the proxy if target was NilClass
25 26 27 28 |
# File 'lib/filemaker/model/relations/proxy.rb', line 25 def self.init(owner, name, ) new_instance = new(owner, name, ) new_instance.target.nil? ? nil : new_instance end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
43 44 45 |
# File 'lib/filemaker/model/relations/proxy.rb', line 43 def respond_to_missing?(method_name, include_private = false) super end |
#target_class ⇒ Object
30 31 32 33 34 |
# File 'lib/filemaker/model/relations/proxy.rb', line 30 def target_class return @class_name if @class_name.is_a?(Class) @class_name.constantize end |