Class: Lurch::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/lurch/relationship.rb,
lib/lurch/relationship/linked.rb,
lib/lurch/relationship/has_one.rb,
lib/lurch/relationship/has_many.rb

Direct Known Subclasses

HasMany, HasOne, Linked

Defined Under Namespace

Classes: HasMany, HasOne, Linked

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object



21
22
23
24
# File 'lib/lurch/relationship.rb', line 21

def method_missing(method, *arguments, &block)
  raise Errors::RelationshipNotLoaded, @relationship_key unless loaded?
  super
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/lurch/relationship.rb', line 3

def data
  @data
end

Class Method Details

.from_document(store, relationship_key, document) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
# File 'lib/lurch/relationship.rb', line 5

def self.from_document(store, relationship_key, document)
  return Relationship::HasMany.new(store, relationship_key, document) if document.key?("data") && document["data"].is_a?(Array)
  return Relationship::HasOne.new(store, relationship_key, document) if document.key?("data")
  return Relationship::Linked.new(store, relationship_key, document) if document.key?("links") && document["links"].key?("related")
  raise ArgumentError, "Invalid relationship document"
end

Instance Method Details

#loaded?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/lurch/relationship.rb', line 12

def loaded?
  !!defined?(@data)
end

#respond_to_missing?(method, all) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



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

def respond_to_missing?(method, all)
  raise Errors::RelationshipNotLoaded, @relationship_key unless loaded?
  super
end