Class: Teamtailor::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/teamtailor/relationship.rb

Instance Method Summary collapse

Constructor Details

#initialize(relation_name, relationships = {}, included = {}) ⇒ Relationship

Returns a new instance of Relationship.



5
6
7
8
9
# File 'lib/teamtailor/relationship.rb', line 5

def initialize(relation_name, relationships = {}, included = {})
  @relation_name = relation_name
  @relationships = relationships
  @included = included
end

Instance Method Details

#loaded?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/teamtailor/relationship.rb', line 11

def loaded?
  !record_ids.empty?
end

#recordsObject



15
16
17
18
19
20
21
22
23
# File 'lib/teamtailor/relationship.rb', line 15

def records
  raise Teamtailor::UnloadedRelationError unless loaded?

  record_json = included.select do |k|
    record_ids.include?(k['id']) && k['type'] == record_type
  end

  Teamtailor::Parser.parse({ 'data' => record_json, 'included' => included })
end