lib/alba/many.rb in alba-0.11.0 vs lib/alba/many.rb in alba-0.11.1
- old
+ new
@@ -1,9 +1,14 @@
-require 'alba/association'
+require_relative 'association'
module Alba
# Representing many association
class Many < Association
+ # Recursively converts objects into an Array of Hashes
+ #
+ # @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
objects.map { |o| @resource.new(o, params: params).to_hash }
end