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.
-
#_default_fields ⇒ Object
Returns the value of attribute _default_fields.
-
#_required_associations ⇒ Object
Returns the value of attribute _required_associations.
-
#_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_attributes ⇒ Object
-
#default_fields(attrs) ⇒ Object
Attributes presented if no fields specified.
- #has_many(name, options = {}) ⇒ Object
- #has_one(name, options = {}) ⇒ Object
- #inherited(base) ⇒ Object
-
#required_associations(assocs) ⇒ Object
Associations that are always included.
- #serializes(name, options = {}) ⇒ Object
Instance Attribute Details
#_associations ⇒ Object
Returns the value of attribute _associations.
11 12 13 |
# File 'lib/simple_json_api/dsl.rb', line 11 def _associations @_associations end |
#_attributes ⇒ Object
Returns the value of attribute _attributes.
12 13 14 |
# File 'lib/simple_json_api/dsl.rb', line 12 def _attributes @_attributes end |
#_default_fields ⇒ Object
Returns the value of attribute _default_fields.
13 14 15 |
# File 'lib/simple_json_api/dsl.rb', line 13 def _default_fields @_default_fields end |
#_required_associations ⇒ Object
Returns the value of attribute _required_associations.
14 15 16 |
# File 'lib/simple_json_api/dsl.rb', line 14 def _required_associations @_required_associations end |
#_root_name ⇒ Object (readonly)
Returns the value of attribute _root_name.
15 16 17 |
# File 'lib/simple_json_api/dsl.rb', line 15 def _root_name @_root_name end |
Instance Method Details
#attribute(name, options = {}) ⇒ Object
30 31 32 |
# File 'lib/simple_json_api/dsl.rb', line 30 def attribute(name, = {}) register_attribute(name, ) end |
#belongs_to(name, options = {}) ⇒ Object
44 45 46 |
# File 'lib/simple_json_api/dsl.rb', line 44 def belongs_to(name, = {}) register_association(name, :belongs_to, ) end |
#default_attributes ⇒ Object
56 57 58 |
# File 'lib/simple_json_api/dsl.rb', line 56 def default_attributes @_attributes.map(&:first).join(',') end |
#default_fields(attrs) ⇒ Object
Attributes presented if no fields specified
35 36 37 |
# File 'lib/simple_json_api/dsl.rb', line 35 def default_fields(attrs) @_default_fields = attrs end |
#has_many(name, options = {}) ⇒ Object
48 49 50 |
# File 'lib/simple_json_api/dsl.rb', line 48 def has_many(name, = {}) register_association(name, :has_many, ) end |
#has_one(name, options = {}) ⇒ Object
52 53 54 |
# File 'lib/simple_json_api/dsl.rb', line 52 def has_one(name, = {}) register_association(name, :has_one, ) end |
#inherited(base) ⇒ Object
17 18 19 20 |
# File 'lib/simple_json_api/dsl.rb', line 17 def inherited(base) base._associations = [] base._attributes = [] end |
#required_associations(assocs) ⇒ Object
Associations that are always included
40 41 42 |
# File 'lib/simple_json_api/dsl.rb', line 40 def required_associations(assocs) @_required_associations = assocs end |
#serializes(name, options = {}) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/simple_json_api/dsl.rb', line 22 def serializes(name, = {}) Serializer.register_serializer( { serializer: self, resource: name }, ) @_root_name = name end |