class Alba::Many
Representing many association
Public Instance Methods
to_hash(target, within: nil, params: {})
click to toggle source
Recursively converts objects into an Array of Hashes
@param target [Object] the object having an association method @param within [Hash] determines what associations to be serialized. If not set, it serializes all associations. @param params [Hash] user-given Hash for arbitrary data @return [Array<Hash>]
# File lib/alba/many.rb, line 12 def to_hash(target, within: nil, params: {}) @object = target.public_send(@name) @object = @condition.call(@object, params) if @condition return if @object.nil? @resource = constantize(@resource) @resource.new(@object, params: params, within: within).to_hash end