Class: JSONApi::ObjectSerializerDefinition
- Inherits:
-
Object
- Object
- JSONApi::ObjectSerializerDefinition
- Defined in:
- lib/json_api/object_serializer_definition.rb
Class Method Summary collapse
- .attributes(*attrs) ⇒ Object
- .base_url(url = @base_url) ⇒ Object
- .has_many(name, **config) ⇒ Object
- .has_one(name, **config) ⇒ Object
- .hashify(object, **options) ⇒ Object
- .id_attribute(attr = @id_attribute) ⇒ Object
- .inherited(specialization) ⇒ Object
- .relationship(name, **config) ⇒ Object
- .relationships(*configs) ⇒ Object
- .serialize(object, **options) ⇒ Object
- .type(type = @type) ⇒ Object
Class Method Details
.attributes(*attrs) ⇒ Object
24 25 26 27 |
# File 'lib/json_api/object_serializer_definition.rb', line 24 def attributes(*attrs) @attributes ||= [] @attributes |= attrs end |
.base_url(url = @base_url) ⇒ Object
33 34 35 |
# File 'lib/json_api/object_serializer_definition.rb', line 33 def base_url(url = @base_url) @base_url = url end |
.has_many(name, **config) ⇒ Object
56 57 58 59 |
# File 'lib/json_api/object_serializer_definition.rb', line 56 def has_many(name, **config) config[:to] = :many relationship(name, config) end |
.has_one(name, **config) ⇒ Object
51 52 53 54 |
# File 'lib/json_api/object_serializer_definition.rb', line 51 def has_one(name, **config) config[:to] = :one relationship(name, config) end |
.hashify(object, **options) ⇒ Object
11 12 13 14 |
# File 'lib/json_api/object_serializer_definition.rb', line 11 def hashify(object, **) = (**) ObjectSerializer.new.hashify(object, **) end |
.id_attribute(attr = @id_attribute) ⇒ Object
29 30 31 |
# File 'lib/json_api/object_serializer_definition.rb', line 29 def id_attribute(attr = @id_attribute) @id_attribute = attr end |
.inherited(specialization) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/json_api/object_serializer_definition.rb', line 16 def inherited(specialization) specialization.attributes(*attributes) specialization.relationships(*relationships) specialization.id_attribute(id_attribute) specialization.base_url(base_url) specialization.type(type) end |
.relationship(name, **config) ⇒ Object
41 42 43 44 |
# File 'lib/json_api/object_serializer_definition.rb', line 41 def relationship(name, **config) config[:name] = name relationships(config) end |
.relationships(*configs) ⇒ Object
46 47 48 49 |
# File 'lib/json_api/object_serializer_definition.rb', line 46 def relationships(*configs) @relationships ||= [] @relationships |= configs end |
.serialize(object, **options) ⇒ Object
6 7 8 9 |
# File 'lib/json_api/object_serializer_definition.rb', line 6 def serialize(object, **) = (**) ObjectSerializer.new.serialize(object, **) end |
.type(type = @type) ⇒ Object
37 38 39 |
# File 'lib/json_api/object_serializer_definition.rb', line 37 def type(type = @type) @type = type end |