lib/alba/one.rb in alba-1.0.1 vs lib/alba/one.rb in alba-1.1.0

- old
+ new

@@ -4,17 +4,18 @@ # Representing one association class One < Association # 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] - def to_hash(target, params: {}) + 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).to_hash + @resource.new(object, params: params, within: within).to_hash end end end