Class: SimpleAMS::Document::Relations
- Inherits:
-
Object
- Object
- SimpleAMS::Document::Relations
- Includes:
- Enumerable
- Defined in:
- lib/simple_ams/document/relations.rb
Overview
TODO: Add memoization for the relations object (iteration + access)
Instance Method Summary collapse
- #[](key) ⇒ Object
- #available ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(options, relations) ⇒ Relations
constructor
A new instance of Relations.
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(, relations) @options = @relations = relations @serializer = .serializer @resource = .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 |
#available ⇒ Object
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(, relations.available) end |
#each ⇒ Object
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
31 32 33 |
# File 'lib/simple_ams/document/relations.rb', line 31 def empty? relations.length.zero? end |