lib/alba/association.rb in alba-2.0.1 vs lib/alba/association.rb in alba-2.1.0

- old
+ new

@@ -35,12 +35,14 @@ params = params.merge(@params) unless @params.empty? @object = target.__send__(@name) @object = @condition.call(object, params, target) if @condition return if @object.nil? - if @resource.is_a?(Proc) && @object.is_a?(Enumerable) - to_h_with_each_resource(within, params) + if @resource.is_a?(Proc) + return to_h_with_each_resource(within, params) if @object.is_a?(Enumerable) + + @resource.call(@object).new(@object, within: within, params: params).to_h else to_h_with_constantize_resource(within, params) end end @@ -61,13 +63,13 @@ @resource = if block klass = Alba.resource_class klass.transform_keys(key_transformation) klass.class_eval(&block) klass - elsif Alba.inferring + elsif Alba.inflector Alba.infer_resource_class(@name, nesting: nesting) else - raise ArgumentError, 'When Alba.inferring is false, either resource or block is required' + raise ArgumentError, 'When Alba.inflector is nil, either resource or block is required' end end def to_h_with_each_resource(within, params) @object.map do |item|