class Teamtailor::Record

Attributes

data[R]
included[R]

Public Class Methods

deserialize(value) click to toggle source
# File lib/teamtailor/record.rb, line 10
def self.deserialize(value)
  payload = JSON.parse value
  new(payload["data"], payload["included"])
end
new(data, included = {}) click to toggle source
# File lib/teamtailor/record.rb, line 5
def initialize(data, included = {})
  @data = data
  @included = included
end

Public Instance Methods

method_missing(m) click to toggle source
# File lib/teamtailor/record.rb, line 22
def method_missing(m)
  if m == :id
    data.dig("id").to_i
  elsif relationship_keys.include?(m.to_s.gsub("_", "-"))
    build_relationship(m.to_s.gsub("_", "-"))
  else
    data.dig("attributes", m.to_s.gsub("_", "-"))
  end
end
serialize() click to toggle source
# File lib/teamtailor/record.rb, line 15
def serialize
  {
    data: data,
    included: included,
  }.to_json
end

Private Instance Methods

build_relationship(name) click to toggle source
# File lib/teamtailor/record.rb, line 36
def build_relationship(name)
  Teamtailor::Relationship.new(name, data.dig("relationships"), included)
end
relationship_keys() click to toggle source
# File lib/teamtailor/record.rb, line 40
def relationship_keys
  data.dig("relationships")&.keys || {}
end