Class: JIRA::HasManyProxy
- Inherits:
-
Object
- Object
- JIRA::HasManyProxy
- Defined in:
- lib/jira/has_many_proxy.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#target_class ⇒ Object
readonly
Returns the value of attribute target_class.
Instance Method Summary collapse
-
#all ⇒ Object
Forces an HTTP request to fetch all instances of the target class that are associated with the parent.
-
#build(attrs = {}) ⇒ Object
Builds an instance of this class with the correct parent.
-
#initialize(parent, target_class, collection = []) ⇒ HasManyProxy
constructor
A new instance of HasManyProxy.
-
#method_missing(method_name) ⇒ Object
Delegate any missing methods to the collection that this proxy wraps.
Constructor Details
#initialize(parent, target_class, collection = []) ⇒ HasManyProxy
Returns a new instance of HasManyProxy.
16 17 18 19 20 |
# File 'lib/jira/has_many_proxy.rb', line 16 def initialize(parent, target_class, collection = []) @parent = parent @target_class = target_class @collection = collection end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
Delegate any missing methods to the collection that this proxy wraps
42 43 44 |
# File 'lib/jira/has_many_proxy.rb', line 42 def method_missing(method_name, ...) collection.send(method_name, ...) end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
14 15 16 |
# File 'lib/jira/has_many_proxy.rb', line 14 def collection @collection end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
13 14 15 |
# File 'lib/jira/has_many_proxy.rb', line 13 def parent @parent end |
#target_class ⇒ Object (readonly)
Returns the value of attribute target_class.
13 14 15 |
# File 'lib/jira/has_many_proxy.rb', line 13 def target_class @target_class end |
Instance Method Details
#all ⇒ Object
Forces an HTTP request to fetch all instances of the target class that are associated with the parent
37 38 39 |
# File 'lib/jira/has_many_proxy.rb', line 37 def all target_class.all(parent.client, parent.to_sym => parent) end |
#build(attrs = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/jira/has_many_proxy.rb', line 29 def build(attrs = {}) resource = target_class.new(parent.client, :attrs => attrs, parent.to_sym => parent) collection << resource resource end |