Class: Lurch::Relationship
- Inherits:
-
Object
- Object
- Lurch::Relationship
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
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
#data ⇒ Object
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
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
12
13
14
|
# File 'lib/lurch/relationship.rb', line 12
def loaded?
!!defined?(@data)
end
|
#respond_to_missing?(method, all) ⇒ Boolean
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
|