lib/alba/many.rb in alba-0.13.1 vs lib/alba/many.rb in alba-1.0.0
- old
+ new
@@ -7,13 +7,14 @@
#
# @param target [Object] the object having an association method
# @param params [Hash] user-given Hash for arbitrary data
# @return [Array<Hash>]
def to_hash(target, params: {})
- objects = target.public_send(@name)
- objects = @condition.call(objects, params) if @condition
- return if objects.nil?
+ @object = target.public_send(@name)
+ @object = @condition.call(@object, params) if @condition
+ return if @object.nil?
- objects.map { |o| @resource.new(o, params: params).to_hash }
+ @resource = constantize(@resource)
+ @object.map { |o| @resource.new(o, params: params).to_hash }
end
end
end