Class: Userlist::Push::ResourceCollection
- Inherits:
-
Object
- Object
- Userlist::Push::ResourceCollection
- Includes:
- Enumerable
- Defined in:
- lib/userlist/push/resource_collection.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#relationship ⇒ Object
readonly
Returns the value of attribute relationship.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(collection, relationship, owner, config = Userlist.config) ⇒ ResourceCollection
constructor
A new instance of ResourceCollection.
- #inverse ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(collection, relationship, owner, config = Userlist.config) ⇒ ResourceCollection
Returns a new instance of ResourceCollection.
8 9 10 11 12 13 |
# File 'lib/userlist/push/resource_collection.rb', line 8 def initialize(collection, relationship, owner, config = Userlist.config) @collection = Array(collection) @relationship = relationship @owner = owner @config = config end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
6 7 8 |
# File 'lib/userlist/push/resource_collection.rb', line 6 def collection @collection end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/userlist/push/resource_collection.rb', line 6 def config @config end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
6 7 8 |
# File 'lib/userlist/push/resource_collection.rb', line 6 def owner @owner end |
#relationship ⇒ Object (readonly)
Returns the value of attribute relationship.
6 7 8 |
# File 'lib/userlist/push/resource_collection.rb', line 6 def relationship @relationship end |
Instance Method Details
#each ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/userlist/push/resource_collection.rb', line 15 def each collection.each do |resource| resource[inverse] = owner if inverse && resource.is_a?(Hash) yield type.from_payload(resource, config) end end |
#inverse ⇒ Object
27 28 29 |
# File 'lib/userlist/push/resource_collection.rb', line 27 def inverse relationship[:inverse] end |
#type ⇒ Object
23 24 25 |
# File 'lib/userlist/push/resource_collection.rb', line 23 def type Object.const_get(relationship[:type]) end |