Sha256: 7c5f38f671e85e3bbad9cc20a793feb956ae7424b6dd5606ed7a42e15bf40787

Contents?: true

Size: 533 Bytes

Versions: 1

Compression:

Stored size: 533 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(&@block)
      resource_class.transform_keys(@key_transformation)
      resource_class.new(object).serializable_hash
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alba-2.0.0 lib/alba/nested_attribute.rb