Class: Hactor::HAL::EmbeddedCollection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Instance Attribute Details

#embedded_classObject (readonly)

Returns the value of attribute embedded_class.



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

def embedded_class
  @embedded_class
end

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

#hashObject (readonly)

Returns the value of attribute hash.



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

def hash
  @hash
end

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

#allObject



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: embedded_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