Class: Hactor::HAL::LinkCollection
- Inherits:
-
Object
- Object
- Hactor::HAL::LinkCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/hactor/hal/link_collection.rb
Instance Attribute Summary collapse
-
#flat_collection_class ⇒ Object
readonly
Returns the value of attribute flat_collection_class.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#link_class ⇒ Object
readonly
Returns the value of attribute link_class.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #all ⇒ Object
- #find(rel) ⇒ Object
-
#initialize(hash, options = {}) ⇒ LinkCollection
constructor
A new instance of LinkCollection.
- #with_rel(rel) ⇒ Object
Constructor Details
#initialize(hash, options = {}) ⇒ LinkCollection
Returns a new instance of LinkCollection.
15 16 17 18 19 20 21 |
# File 'lib/hactor/hal/link_collection.rb', line 15 def initialize(hash, ={}) #TODO: throw/log parsing error if not hash @hash = hash @parent = .fetch(:parent) @link_class = [:link_class] || Link @flat_collection_class = [:flat_collection_class] || FlatCollection end |
Instance Attribute Details
#flat_collection_class ⇒ Object (readonly)
Returns the value of attribute flat_collection_class.
12 13 14 |
# File 'lib/hactor/hal/link_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/link_collection.rb', line 12 def hash @hash end |
#link_class ⇒ Object (readonly)
Returns the value of attribute link_class.
12 13 14 |
# File 'lib/hactor/hal/link_collection.rb', line 12 def link_class @link_class end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
12 13 14 |
# File 'lib/hactor/hal/link_collection.rb', line 12 def parent @parent end |
Instance Method Details
#all ⇒ Object
23 24 25 26 27 28 |
# File 'lib/hactor/hal/link_collection.rb', line 23 def all @all ||= flat_collection_class.new hash, item_class: link_class, parent: parent end |
#find(rel) ⇒ Object
30 31 32 |
# File 'lib/hactor/hal/link_collection.rb', line 30 def find(rel) all.find(->{ NullLink.new }) { |link| link.rel == rel } end |
#with_rel(rel) ⇒ Object
34 35 36 |
# File 'lib/hactor/hal/link_collection.rb', line 34 def with_rel(rel) all.select { |link| link.rel == rel } end |