lib/bright_serializer/serializer.rb in bright_serializer-0.2.2 vs lib/bright_serializer/serializer.rb in bright_serializer-0.2.3
- old
+ new
@@ -10,10 +10,11 @@
module Serializer
SUPPORTED_TRANSFORMATION = %i[camel camel_lower dash underscore].freeze
DEFAULT_OJ_OPTIONS = { mode: :compat, time_format: :ruby, use_to_json: true }.freeze
def self.included(base)
+ super
base.extend ClassMethods
base.instance_variable_set(:@attributes_to_serialize, [])
end
def initialize(object, **options)
@@ -84,10 +85,11 @@
end
def entity
{}.tap do |result|
@attributes_to_serialize.each do |attribute|
- entity_value = attribute.entity&.to_h || BrightSerializer::Entity::Base::DEFAULT_DEFINITION
+ entity_value = attribute.entity&.to_h ||
+ BrightSerializer::Entity::Base::DEFAULT_DEFINITION
result.merge!(attribute.transformed_key => entity_value)
end
end
end