Class: Alba::Association Private
- Inherits:
-
Object
- Object
- Alba::Association
- Defined in:
- lib/alba/association.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 association
Class Attribute Summary collapse
-
.const_cache ⇒ Object
readonly
private
cache for ‘const_get`.
Instance Attribute Summary collapse
- #name ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(name:, condition: nil, resource: nil, source: nil, with_traits: nil, params: {}, nesting: nil, key_transformation: :none, helper: nil, &block) ⇒ Association
constructor
private
A new instance of Association.
-
#key_transformation=(type) ⇒ void
private
This is the same API in ‘NestedAttribute`.
-
#to_h(target, within: nil, params: {}) ⇒ Hash
private
Recursively converts an object into a Hash.
Constructor Details
#initialize(name:, condition: nil, resource: nil, source: nil, with_traits: nil, params: {}, nesting: nil, key_transformation: :none, helper: nil, &block) ⇒ Association
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 Association.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/alba/association.rb', line 26 def initialize( name:, condition: nil, resource: nil, source: nil, with_traits: nil, params: {}, nesting: nil, key_transformation: :none, helper: nil, &block ) @name = name @condition = condition @resource = resource @source = source @with_traits = with_traits @params = params return if @resource assign_resource(nesting, key_transformation, block, helper) end |
Class Attribute Details
.const_cache ⇒ Object (readonly)
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.
cache for ‘const_get`
10 11 12 |
# File 'lib/alba/association.rb', line 10 def const_cache @const_cache end |
Instance Attribute Details
#name ⇒ Object (readonly)
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.
13 14 15 |
# File 'lib/alba/association.rb', line 13 def name @name end |
Instance Method Details
#key_transformation=(type) ⇒ void
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.
This method returns an undefined value.
This is the same API in ‘NestedAttribute`
53 54 55 |
# File 'lib/alba/association.rb', line 53 def key_transformation=(type) @resource.transform_keys(type) unless @resource.is_a?(Proc) end |
#to_h(target, within: nil, 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.
Recursively converts an object into a Hash
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/alba/association.rb', line 63 def to_h(target, within: nil, params: {}) params = params.merge(@params) object = object_from(target, params) return if object.nil? if @resource.is_a?(Proc) return to_h_with_each_resource(object, within, params) if object.is_a?(Enumerable) @resource.call(object).new(object, within: within, params: params, with_traits: @with_traits).to_h else to_h_with_constantize_resource(object, within, params) end end |