Class: Hactor::HAL::EmbeddedCollection
- Inherits:
-
Object
- Object
- Hactor::HAL::EmbeddedCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/hactor/hal/embedded_collection.rb
Instance Attribute Summary collapse
-
#embedded_class ⇒ Object
readonly
Returns the value of attribute embedded_class.
-
#flat_collection_class ⇒ Object
readonly
Returns the value of attribute flat_collection_class.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #all ⇒ Object
- #find(rel) ⇒ Object
-
#initialize(hash, options) ⇒ EmbeddedCollection
constructor
A new instance of EmbeddedCollection.
Constructor Details
#initialize(hash, options) ⇒ EmbeddedCollection
Returns a new instance of EmbeddedCollection.
16 17 18 19 20 21 22 |
# File 'lib/hactor/hal/embedded_collection.rb', line 16 def initialize(hash, ) #TODO: throw/log parsing error if not hash @hash = hash @parent = .fetch(:parent) @embedded_class = [:embedded_class] || Resource @flat_collection_class = [:flat_collection_class] || FlatCollection end |
Instance Attribute Details
#embedded_class ⇒ Object (readonly)
Returns the value of attribute embedded_class.
12 13 14 |
# File 'lib/hactor/hal/embedded_collection.rb', line 12 def @embedded_class end |
#flat_collection_class ⇒ Object (readonly)
Returns the value of attribute flat_collection_class.
12 13 14 |
# File 'lib/hactor/hal/embedded_collection.rb', line 12 def flat_collection_class @flat_collection_class end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
12 13 14 |
# File 'lib/hactor/hal/embedded_collection.rb', line 12 def hash @hash end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
12 13 14 |
# File 'lib/hactor/hal/embedded_collection.rb', line 12 def parent @parent end |
Instance Method Details
#all ⇒ Object
24 25 26 27 28 |
# File 'lib/hactor/hal/embedded_collection.rb', line 24 def all @all ||= flat_collection_class.new hash, parent: parent, item_class: end |
#find(rel) ⇒ Object
30 31 32 |
# File 'lib/hactor/hal/embedded_collection.rb', line 30 def find(rel) all.find(->{ NullResource.new }) { |resource| resource.rel == rel } end |