class Lurch::Resource
Attributes
id[R]
type[R]
Public Class Methods
new(store, type, id)
click to toggle source
# File lib/lurch/resource.rb, line 5 def initialize(store, type, id) @store = store @type = Inflector.decode_type(type) @id = id end
Public Instance Methods
==(other)
click to toggle source
# File lib/lurch/resource.rb, line 32 def ==(other) eql?(other) end
[](attribute)
click to toggle source
# File lib/lurch/resource.rb, line 40 def [](attribute) raise Errors::ResourceNotLoaded, resource_class_name unless loaded? resource_from_store.attribute(attribute) end
attributes()
click to toggle source
# File lib/lurch/resource.rb, line 20 def attributes raise Errors::ResourceNotLoaded, resource_class_name unless loaded? resource_from_store.attributes end
eql?(other)
click to toggle source
# File lib/lurch/resource.rb, line 36 def eql?(other) id == other.id && type == other.type end
fetch()
click to toggle source
# File lib/lurch/resource.rb, line 15 def fetch @store.from(type).find(id) self end
inspect()
click to toggle source
# File lib/lurch/resource.rb, line 50 def inspect inspection = if loaded? attributes.map { |name, value| "#{name}: #{value.inspect}" }.join(", ") else "not loaded" end "#<#{self.class}[#{resource_class_name}] id: #{id.inspect}, #{inspection}>" end
loaded?()
click to toggle source
# File lib/lurch/resource.rb, line 11 def loaded? !!resource_from_store end
relationships()
click to toggle source
# File lib/lurch/resource.rb, line 26 def relationships raise Errors::ResourceNotLoaded, resource_class_name unless loaded? resource_from_store.relationships end
resource_class_name()
click to toggle source
# File lib/lurch/resource.rb, line 46 def resource_class_name Inflector.classify(type) end
Private Instance Methods
method_missing(method, *arguments, &block)
click to toggle source
Calls superclass method
# File lib/lurch/resource.rb, line 70 def method_missing(method, *arguments, &block) raise Errors::ResourceNotLoaded, resource_class_name unless loaded? return resource_from_store.attribute(method) if resource_from_store.attribute?(method) if resource_from_store.relationship?(method) rel = resource_from_store.relationship(method) return rel.loaded? ? rel.data : rel end super end
resource_from_store()
click to toggle source
# File lib/lurch/resource.rb, line 61 def resource_from_store @store.resource_from_store(type, id) end
respond_to_missing?(method, all)
click to toggle source
Calls superclass method
# File lib/lurch/resource.rb, line 65 def respond_to_missing?(method, all) return super unless loaded? resource_from_store.attribute?(method) || resource_from_store.relationship?(method) || super end