Class: SimpleAMS::Document::Relations

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

Instance Method Summary collapse

Constructor Details

#initialize(options, relations) ⇒ Relations

Returns a new instance of Relations.



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

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

Instance Method Details

#[](key) ⇒ Object



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

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

  return relation_for(found)
end

#availableObject



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

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

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

#each(&block) ⇒ Object



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

def each(&block)
  return enum_for(:each) unless block_given?

  relations.each{ |relation|
    yield relation_for(relation)
  }

  self
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  count == 0
end