Module: SimpleJsonApi::DSL
- Included in:
- Serializer
- Defined in:
- lib/simple_json_api/dsl.rb
Overview
Define the public API for creating serializers
Instance Attribute Summary collapse
-
#_associations ⇒ Object
Returns the value of attribute _associations.
-
#_attributes ⇒ Object
Returns the value of attribute _attributes.
-
#_root_name ⇒ Object
readonly
Returns the value of attribute _root_name.
Instance Method Summary collapse
- #attribute(name, options = {}) ⇒ Object
- #belongs_to(name, options = {}) ⇒ Object
- #default_fields ⇒ Object
- #has_many(name, options = {}) ⇒ Object
- #has_one(name, options = {}) ⇒ Object
- #inherited(base) ⇒ Object
- #serializes(name, options = {}) ⇒ Object
Instance Attribute Details
#_associations ⇒ Object
Returns the value of attribute _associations.
5 6 7 |
# File 'lib/simple_json_api/dsl.rb', line 5 def _associations @_associations end |
#_attributes ⇒ Object
Returns the value of attribute _attributes.
6 7 8 |
# File 'lib/simple_json_api/dsl.rb', line 6 def _attributes @_attributes end |
#_root_name ⇒ Object (readonly)
Returns the value of attribute _root_name.
7 8 9 |
# File 'lib/simple_json_api/dsl.rb', line 7 def _root_name @_root_name end |
Instance Method Details
#attribute(name, options = {}) ⇒ Object
22 23 24 |
# File 'lib/simple_json_api/dsl.rb', line 22 def attribute(name, = {}) register_attribute(name, ) end |
#belongs_to(name, options = {}) ⇒ Object
26 27 28 |
# File 'lib/simple_json_api/dsl.rb', line 26 def belongs_to(name, = {}) register_association(name, :belongs_to, ) end |
#default_fields ⇒ Object
38 39 40 |
# File 'lib/simple_json_api/dsl.rb', line 38 def default_fields @_attributes.map(&:first).join(',') end |
#has_many(name, options = {}) ⇒ Object
30 31 32 |
# File 'lib/simple_json_api/dsl.rb', line 30 def has_many(name, = {}) register_association(name, :has_many, ) end |
#has_one(name, options = {}) ⇒ Object
34 35 36 |
# File 'lib/simple_json_api/dsl.rb', line 34 def has_one(name, = {}) register_association(name, :has_one, ) end |
#inherited(base) ⇒ Object
9 10 11 12 |
# File 'lib/simple_json_api/dsl.rb', line 9 def inherited(base) base._associations = [] base._attributes = [] end |
#serializes(name, options = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/simple_json_api/dsl.rb', line 14 def serializes(name, = {}) ResourceSerializer.register_serializer( { serializer: self, resource: name }, ) @_root_name = name end |