class Alba::One
Representing one association
Public Instance Methods
to_hash(target, within: nil, params: {})
click to toggle source
Recursively converts an object into a Hash
@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 [Hash]
# File lib/alba/one.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