class Lurch::StoredResource

Public Class Methods

new(store, resource_object) click to toggle source
# File lib/lurch/stored_resource.rb, line 3
def initialize(store, resource_object)
  @store = store
  @resource_object = resource_object
end

Public Instance Methods

attribute(name) click to toggle source
# File lib/lurch/stored_resource.rb, line 28
def attribute(name)
  fixed_attributes[name.to_sym]
end
attribute?(name) click to toggle source
# File lib/lurch/stored_resource.rb, line 24
def attribute?(name)
  fixed_attributes.key?(name.to_sym)
end
attributes() click to toggle source
# File lib/lurch/stored_resource.rb, line 16
def attributes
  fixed_attributes
end
id() click to toggle source
# File lib/lurch/stored_resource.rb, line 8
def id
  @id ||= @resource_object["id"]
end
relationship(name) click to toggle source
# File lib/lurch/stored_resource.rb, line 36
def relationship(name)
  fixed_relationships[name.to_sym]
end
relationship?(name) click to toggle source
# File lib/lurch/stored_resource.rb, line 32
def relationship?(name)
  fixed_relationships.key?(name.to_sym)
end
relationships() click to toggle source
# File lib/lurch/stored_resource.rb, line 20
def relationships
  fixed_relationships
end
type() click to toggle source
# File lib/lurch/stored_resource.rb, line 12
def type
  @type ||= Inflector.decode_type(@resource_object["type"])
end

Private Instance Methods

fixed_attributes() click to toggle source
# File lib/lurch/stored_resource.rb, line 42
def fixed_attributes
  @fixed_attributes ||= resource_attributes.each_with_object({}) do |(key, value), hash|
    hash[Inflector.decode_key(key)] = value
  end
end
fixed_relationships() click to toggle source
# File lib/lurch/stored_resource.rb, line 48
def fixed_relationships
  @fixed_relationships ||= resource_relationships.each_with_object({}) do |(key, value), hash|
    relationship_key = Inflector.decode_key(key)
    hash[relationship_key] = Relationship.from_document(@store, relationship_key, value)
  end
end
resource_attributes() click to toggle source
# File lib/lurch/stored_resource.rb, line 55
def resource_attributes
  @resource_object["attributes"] || {}
end
resource_relationships() click to toggle source
# File lib/lurch/stored_resource.rb, line 59
def resource_relationships
  @resource_object["relationships"] || []
end