Class: Dato::Local::JsonApiEntity
- Inherits:
-
Object
- Object
- Dato::Local::JsonApiEntity
show all
- Defined in:
- lib/dato/local/json_api_entity.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(payload, data_source) ⇒ JsonApiEntity
Returns a new instance of JsonApiEntity.
7
8
9
10
|
# File 'lib/dato/local/json_api_entity.rb', line 7
def initialize(payload, data_source)
@payload = payload
@data_source = data_source
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/dato/local/json_api_entity.rb', line 65
def method_missing(method, *arguments, &block)
return super unless arguments.empty?
if attributes.key?(method)
attributes[method]
elsif relationships.key?(method)
dereference_linkage(relationships[method][:data])
else
super
end
end
|
Instance Attribute Details
#data_source ⇒ Object
Returns the value of attribute data_source.
5
6
7
|
# File 'lib/dato/local/json_api_entity.rb', line 5
def data_source
@data_source
end
|
#payload ⇒ Object
Returns the value of attribute payload.
5
6
7
|
# File 'lib/dato/local/json_api_entity.rb', line 5
def payload
@payload
end
|
Instance Method Details
#==(other) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/dato/local/json_api_entity.rb', line 20
def ==(other)
if other.is_a? JsonApiEntity
id == other.id && type == other.type
else
false
end
end
|
#[](key) ⇒ Object
33
34
35
|
# File 'lib/dato/local/json_api_entity.rb', line 33
def [](key)
attributes[key]
end
|
#id ⇒ Object
12
13
14
|
# File 'lib/dato/local/json_api_entity.rb', line 12
def id
@payload[:id]
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
37
38
39
40
41
42
43
|
# File 'lib/dato/local/json_api_entity.rb', line 37
def respond_to_missing?(method, include_private = false)
if attributes.key?(method) || relationships.key?(method)
true
else
super
end
end
|
#to_s ⇒ Object
Also known as:
inspect
28
29
30
|
# File 'lib/dato/local/json_api_entity.rb', line 28
def to_s
"#<JsonApiEntity id=#{id} type=#{type} payload=#{payload}>"
end
|
#type ⇒ Object
16
17
18
|
# File 'lib/dato/local/json_api_entity.rb', line 16
def type
@payload[:type]
end
|