Class: Onsi::Model::ModelRenderer
- Inherits:
-
Object
- Object
- Onsi::Model::ModelRenderer
- Defined in:
- lib/onsi/model.rb
Overview
You shouldn’t ever have to directly interact with one of these classes.
The class that holds attributes and relationships for a model’s version.
Constant Summary collapse
- DATE_FORMAT =
The default date format for a rendered Date. (ISO-8601)
'%Y-%m-%d'.freeze
- DATETIME_FORMAT =
The default date-time format for a rendered Date and Time. (ISO-8601)
'%Y-%m-%dT%H:%M:%SZ'.freeze
Instance Attribute Summary collapse
-
#id_attr ⇒ Object
readonly
The name of the id attribute on the model.
Instance Method Summary collapse
-
#attribute(name, &block) ⇒ Object
Add an attribute to the rendered attributes.
-
#meta(name, &block) ⇒ Object
Add a metadata value to the rendered object’s meta.
-
#relationship(name, type, &block) ⇒ Object
Add a relationship to the rendered relationships.
-
#type(name = nil) ⇒ Object
The type name.
Instance Attribute Details
#id_attr ⇒ Object (readonly)
The name of the id attribute on the model
96 97 98 |
# File 'lib/onsi/model.rb', line 96 def id_attr @id_attr end |
Instance Method Details
#attribute(name, &block) ⇒ Object
Add an attribute to the rendered attributes.
140 141 142 |
# File 'lib/onsi/model.rb', line 140 def attribute(name, &block) @attributes[name.to_sym] = block || name end |
#meta(name, &block) ⇒ Object
Add a metadata value to the rendered object’s meta.
172 173 174 |
# File 'lib/onsi/model.rb', line 172 def (name, &block) @metadata[name.to_sym] = block end |
#relationship(name, type, &block) ⇒ Object
Add a relationship to the rendered relationships.
161 162 163 |
# File 'lib/onsi/model.rb', line 161 def relationship(name, type, &block) @relationships[name.to_sym] = { type: type, attr: block || name } end |
#type(name = nil) ⇒ Object
Not required. If there is no type, the class name will be used when rendering the object. (Name is underscored)
The type name.
116 117 118 119 |
# File 'lib/onsi/model.rb', line 116 def type(name = nil) @type = name if name @type end |