Class: WolfCore::ApplicationSerializer
- Inherits:
-
Object
- Object
- WolfCore::ApplicationSerializer
- Defined in:
- lib/wolf_core/infrastructure/application_serializer.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- ._attributes ⇒ Object
- ._relationships ⇒ Object
- .attributes(*attrs) ⇒ Object
-
.has_many(relationship, serializer:) ⇒ Object
rubocop:disable Naming/PredicateName.
-
.has_one(relationship, serializer:) ⇒ Object
rubocop:disable Naming/PredicateName.
- .serialize(entity, options = {}) ⇒ Object
- .serialize_all(collection, options = {}) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(object, options = {}) ⇒ ApplicationSerializer
constructor
A new instance of ApplicationSerializer.
Constructor Details
#initialize(object, options = {}) ⇒ ApplicationSerializer
Returns a new instance of ApplicationSerializer.
7 8 9 10 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 7 def initialize(object, = {}) @object = object = end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 5 def object @object end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 5 def end |
Class Method Details
._attributes ⇒ Object
32 33 34 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 32 def self._attributes @_attributes ||= [] end |
._relationships ⇒ Object
36 37 38 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 36 def self._relationships @_relationships ||= {} end |
.attributes(*attrs) ⇒ Object
20 21 22 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 20 def self.attributes(*attrs) _attributes.concat(attrs.map(&:to_sym)) end |
.has_many(relationship, serializer:) ⇒ Object
rubocop:disable Naming/PredicateName
24 25 26 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 24 def self.has_many(relationship, serializer:) # rubocop:disable Naming/PredicateName _relationships[relationship.to_sym] = serializer end |
.has_one(relationship, serializer:) ⇒ Object
rubocop:disable Naming/PredicateName
28 29 30 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 28 def self.has_one(relationship, serializer:) # rubocop:disable Naming/PredicateName _relationships[relationship.to_sym] = serializer end |
.serialize(entity, options = {}) ⇒ Object
16 17 18 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 16 def self.serialize(entity, = {}) new(entity, ).as_json.with_indifferent_access end |
.serialize_all(collection, options = {}) ⇒ Object
12 13 14 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 12 def self.serialize_all(collection, = {}) collection.map { |item| serialize(item, ) } end |
Instance Method Details
#as_json ⇒ Object
40 41 42 43 44 |
# File 'lib/wolf_core/infrastructure/application_serializer.rb', line 40 def as_json(*) attributes = serialized_attributes relationships = serialized_relationships attributes.merge(relationships) end |