Skip to content
Browse files

don't aggregate if not asked to

  • Loading branch information...
1 parent f37dd5f commit 8b81ba8e92a95dfb282c690258edc8ac4234daca @davidhq davidhq committed Jul 26, 2009
Showing with 13 additions and 7 deletions.
  1. +7 −7 lib/asbestos.rb
  2. +6 −0 spec/asbestos_spec.rb
View
14 lib/asbestos.rb
@@ -80,8 +80,7 @@ def method_missing(method, *args)
end
else
raise ArgumentError, "don't know what to do with attributes" if attrs
- method = method.pluralize if _aggregates.include?(method)
- _write_pair(method, value)
+ _write_pair(method, value, _aggregates.include?(method))
end
end
end
@@ -96,13 +95,14 @@ def _aggregates
@options[:aggregate] ||= []
end
- def _write_pair(key, value)
+ def _write_pair(key, value, aggregate = false)
key = key.to_s.gsub('-', '_')
- if @target[key].nil?
- @target[key] = value
- else
- @target[key] = [@target[key]] unless @target[key].is_a?(Array)
+ if aggregate
+ key = key.pluralize
+ @target[key] ||= []
@target[key] << value
+ else
+ @target[key] = value
end
end
View
6 spec/asbestos_spec.rb
@@ -84,4 +84,10 @@ def to_json
@json.tag!(:foo, 'bar')
to_json.should == '{"foos": ["bar", "bar"]}'
end
+
+ it "should not aggregate when not asked" do
+ @json.tag!(:foo, 'bar')
+ @json.tag!(:foo, 'bar')
+ to_json.should == '{"foo": "bar"}'
+ end
end

0 comments on commit 8b81ba8

Please sign in to comment.
Something went wrong with that request. Please try again.