Class: Hactor::HAL::LinkCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/hactor/hal/link_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  #TODO: throw/log parsing error if not hash
  @hash = hash
  @parent = options.fetch(:parent)
  @link_class = options[:link_class] || Link
  @flat_collection_class = options[:flat_collection_class] || FlatCollection
end

Instance Attribute Details

#flat_collection_classObject (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

#hashObject (readonly)

Returns the value of attribute hash.



12
13
14
# File 'lib/hactor/hal/link_collection.rb', line 12

def hash
  @hash
end

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

#parentObject (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

#allObject



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