Class: SimpleAMS::Document::Relations

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/simple_ams/document/relations.rb

Overview

TODO: Add memoization for the relations object (iteration + access)

Instance Method Summary collapse

Constructor Details

#initialize(options, relations) ⇒ Relations

Returns a new instance of Relations.



7
8
9
10
11
12
# File 'lib/simple_ams/document/relations.rb', line 7

def initialize(options, relations)
  @options = options
  @relations = relations
  @serializer = options.serializer
  @resource = options.resource
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
17
18
19
# File 'lib/simple_ams/document/relations.rb', line 14

def [](key)
  found = relations.find { |relation| relation.name == key }
  return nil unless found

  relation_for(found)
end

#availableObject



35
36
37
38
39
# File 'lib/simple_ams/document/relations.rb', line 35

def available
  return @available ||= [] if relations.available.empty?

  @available ||= self.class.new(options, relations.available)
end

#eachObject



21
22
23
24
25
26
27
28
29
# File 'lib/simple_ams/document/relations.rb', line 21

def each
  return enum_for(:each) unless block_given?

  relations.each do |relation|
    yield relation_for(relation)
  end

  self
end

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/simple_ams/document/relations.rb', line 31

def empty?
  relations.length.zero?
end