Class: Elements::ElementsObject
- Inherits:
-
Object
- Object
- Elements::ElementsObject
show all
- Defined in:
- lib/elements/elements_object.rb
Overview
A mapping from the resource JSON to a PORO. Assumes the existence of attributes such as ‘id`, and encourages immutability.
Constant Summary
collapse
- PERMANENT_ATTRIBUTES =
[:id].freeze
- RESERVED_FIELD_NAMES =
[:class].freeze
Instance Method Summary
collapse
Constructor Details
#initialize(id, attributes = nil) ⇒ ElementsObject
Returns a new instance of ElementsObject.
12
13
14
15
16
|
# File 'lib/elements/elements_object.rb', line 12
def initialize(id, attributes = nil)
@id = id
@attributes = attributes || {}
add_readers(attributes)
end
|
Instance Method Details
#[](key) ⇒ Object
18
19
20
|
# File 'lib/elements/elements_object.rb', line 18
def [](key)
@attributes[key.to_sym]
end
|
#as_json(*opts) ⇒ Object
26
27
28
|
# File 'lib/elements/elements_object.rb', line 26
def as_json(*opts)
@attributes.as_json(*opts)
end
|
#to_json(*opts) ⇒ Object
22
23
24
|
# File 'lib/elements/elements_object.rb', line 22
def to_json(*opts)
JSON.generate(@attributes, opts)
end
|