Class: LedgerSync::Domains::Serializer
- Inherits:
-
Serializer
- Object
- Serializer
- LedgerSync::Domains::Serializer
- Defined in:
- lib/ledger_sync/domains/serializer.rb,
lib/ledger_sync/domains/serializer/mixin.rb,
lib/ledger_sync/domains/serializer/query.rb,
lib/ledger_sync/domains/serializer/struct.rb
Defined Under Namespace
Modules: Mixin Classes: Query, Struct
Instance Method Summary collapse
- #attributes_for ⇒ Object
- #references_for ⇒ Object
-
#serialize(args = {}) ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Method Details
#attributes_for ⇒ Object
8 9 10 11 12 |
# File 'lib/ledger_sync/domains/serializer.rb', line 8 def attributes_for(*) self.class.attributes.values.select do |attr| !attr.references_many? && !attr.references_one? end end |
#references_for ⇒ Object
14 15 16 17 18 |
# File 'lib/ledger_sync/domains/serializer.rb', line 14 def references_for(*) self.class.attributes.values.select do |attr| attr.references_many? || attr.references_one? end end |
#serialize(args = {}) ⇒ Object
rubocop:disable Metrics/MethodLength
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ledger_sync/domains/serializer.rb', line 20 def serialize(args = {}) # rubocop:disable Metrics/MethodLength resource = args.fetch(:resource) ret = {} attributes_for(resource: resource).each do |serializer_attribute| ret = LedgerSync::Util::HashHelpers.deep_merge( hash_to_merge_into: ret, other_hash: serializer_attribute.hash_attribute_hash_for(resource: resource) ) end Serializer::Struct.build( ret, self.class.to_s, resource: resource, references: references_for(resource: resource) ) end |