class ArtemisApi::Model
Attributes
attributes[R]
client[R]
id[R]
included[R]
relationships[R]
Public Class Methods
instance_for(type, data, included, client)
click to toggle source
# File lib/artemis_api/model.rb, line 48 def instance_for(type, data, included, client) @@registered_classes[type]&.new(client, data, included) end
json_type(type = nil)
click to toggle source
# File lib/artemis_api/model.rb, line 39 def json_type(type = nil) if type @json_type = type @@registered_classes ||= {} @@registered_classes[type] = self end @json_type end
new(client, data, included = nil)
click to toggle source
# File lib/artemis_api/model.rb, line 71 def initialize(client, data, included = nil) @client = client @id = data['id'].to_i @attributes = data['attributes'] @relationships = data['relationships'] @included = included end
relationships()
click to toggle source
# File lib/artemis_api/model.rb, line 52 def relationships @relationships ||= [] end
Private Class Methods
register_relationship(name)
click to toggle source
# File lib/artemis_api/model.rb, line 58 def register_relationship(name) relationships << name.to_sym end
Public Instance Methods
inspect()
click to toggle source
# File lib/artemis_api/model.rb, line 79 def inspect vars = %i[id attributes].map { |v| "#{v}=#{send(v).inspect}" }.join(', ') vars << ", relationships={#{self.class.relationships.join(', ')}}" "<#{self.class}: #{vars}>" end
method_missing(name)
click to toggle source
Calls superclass method
# File lib/artemis_api/model.rb, line 63 def method_missing(name) respond_to_missing?(name) ? attributes[name.to_s] : super end
respond_to_missing?(name)
click to toggle source
# File lib/artemis_api/model.rb, line 67 def respond_to_missing?(name) attributes.key?(name.to_s) end