Class: Lurch::Relationship::HasOne

Inherits:
Lurch::Relationship show all
Defined in:
lib/lurch/relationship/has_one.rb

Instance Attribute Summary

Attributes inherited from Lurch::Relationship

#data

Instance Method Summary collapse

Methods inherited from Lurch::Relationship

from_document, #loaded?, #method_missing, #respond_to_missing?

Constructor Details

#initialize(store, relationship_key, document) ⇒ HasOne

Returns a new instance of HasOne.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/lurch/relationship/has_one.rb', line 4

def initialize(store, relationship_key, document)
  @store = store
  @relationship_key = relationship_key
  if document["data"].nil?
    @data = nil
  else
    @type = Inflector.decode_type(document["data"]["type"])
    @id = document["data"]["id"]
    @data = Resource.new(@store, @type, @id)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Lurch::Relationship

Instance Method Details

#inspectObject



16
17
18
# File 'lib/lurch/relationship/has_one.rb', line 16

def inspect
  @data.nil? ? "#<#{self.class} nil>" : "#<#{self.class}[#{Inflector.classify(@type)}] id: #{@id.inspect}>"
end