lib/alba/many.rb in alba-0.8.0 vs lib/alba/many.rb in alba-0.9.0
- old
+ new
@@ -1,26 +1,12 @@
+require 'alba/association'
+
module Alba
# Representing many association
- class Many
- def initialize(name:, resource: nil, &block)
- @name = name
- @resource = resource
- @block = block
- raise ArgumentError, 'resource or block is required' if @resource.nil? && @block.nil?
- end
-
+ class Many < Association
def to_hash(target)
objects = target.public_send(@name)
@resource ||= resource_class
objects.map { |o| @resource.new(o).to_hash }
- end
-
- private
-
- def resource_class
- klass = Class.new
- klass.include(::Alba::Resource)
- klass.class_exec(&@block)
- klass
end
end
end