Class: Alba::NestedAttribute Private

Inherits:
Object
  • Object
show all
Defined in:
lib/alba/nested_attribute.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Representing nested attribute

Instance Method Summary collapse

Constructor Details

#initialize(key_transformation: :none, &block) ⇒ NestedAttribute

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of NestedAttribute.

Parameters:

  • key_transformation (Symbol) (defaults to: :none)

    determines how to transform keys

  • block (Proc)

    class body



7
8
9
10
# File 'lib/alba/nested_attribute.rb', line 7

def initialize(key_transformation: :none, &block)
  @key_transformation = key_transformation
  @block = block
end

Instance Method Details

#value(object:, params:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns hash serialized from running the class body in the object.

Parameters:

  • object (Object)

    the object being serialized

  • params (Hash)

    params Hash inherited from Resource

Returns:

  • (Hash)

    hash serialized from running the class body in the object



15
16
17
18
19
20
# File 'lib/alba/nested_attribute.rb', line 15

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