Sha256: 738c3a198878b99af946fa1306d534226e996e7400174a4c16b4f880507bf4fe

Contents?: true

Size: 565 Bytes

Versions: 3

Compression:

Stored size: 565 Bytes

Contents

module Alba
  # Representing nested attribute
  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

    # @return [Hash]
    def value(object)
      resource_class = Alba.resource_class
      resource_class.transform_keys(@key_transformation)
      resource_class.class_eval(&@block)
      resource_class.new(object).serializable_hash
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alba-2.2.0 lib/alba/nested_attribute.rb
alba-2.1.0 lib/alba/nested_attribute.rb
alba-2.0.1 lib/alba/nested_attribute.rb