Class: BrightSerializer::AttributeRelation
- Defined in:
- lib/bright_serializer/attribute_relation.rb
Instance Attribute Summary
Attributes inherited from Attribute
#block, #condition, #entity, #key, #transformed_key
Instance Method Summary collapse
-
#initialize(key, serializer, condition, entity, options, &block) ⇒ AttributeRelation
constructor
A new instance of AttributeRelation.
- #serialize(serializer_instance, object, params) ⇒ Object
Methods inherited from Attribute
Constructor Details
#initialize(key, serializer, condition, entity, options, &block) ⇒ AttributeRelation
Returns a new instance of AttributeRelation.
5 6 7 8 9 10 11 |
# File 'lib/bright_serializer/attribute_relation.rb', line 5 def initialize(key, serializer, condition, entity, , &block) @serializer = serializer @options = || {} add_entity_ref!(entity) super(key, condition, entity, &block) end |
Instance Method Details
#serialize(serializer_instance, object, params) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/bright_serializer/attribute_relation.rb', line 13 def serialize(serializer_instance, object, params) return unless object merged_params = nil merged_params = (params || {}).merge(@options[:params] || {}) if params || @options[:params] value = attribute_value(serializer_instance, object, merged_params) class_serializer.new(value, params: merged_params, **@options).serializable_hash end |