lib/alba/one.rb in alba-0.13.1 vs lib/alba/one.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 [Hash]
def to_hash(target, params: {})
- object = target.public_send(@name)
- object = @condition.call(object, params) if @condition
- return if object.nil?
+ @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
end
end
end