Sha256: 1f593550a7962f44437362126f3b1eb3f2c1593a478fc8b6aa99538286f4cf22

Contents?: true

Size: 786 Bytes

Versions: 7

Compression:

Stored size: 786 Bytes

Contents

module Alba
  # Representing nested attribute
  # @api private
  class NestedAttribute
    # @param key_transformation [Symbol] determines how to transform keys
    # @param block [Proc] class body
    def initialize(key_transformation: :none, &block)
      @key_transformation = key_transformation
      @block = block
    end

    # @param object [Object] the object being serialized
    # @param params [Hash] params Hash inherited from Resource
    # @return [Hash] hash serialized from running the class body in the object
    def value(object:, params:)
      resource_class = Alba.resource_class
      resource_class.transform_keys(@key_transformation)
      resource_class.class_eval(&@block)
      resource_class.new(object, params: params).serializable_hash
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
alba-2.4.3 lib/alba/nested_attribute.rb
alba-3.0.2 lib/alba/nested_attribute.rb
alba-3.0.1 lib/alba/nested_attribute.rb
alba-2.4.2 lib/alba/nested_attribute.rb
alba-3.0.0 lib/alba/nested_attribute.rb
alba-2.4.1 lib/alba/nested_attribute.rb
alba-2.4.0 lib/alba/nested_attribute.rb