attribution 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/attribution.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "attribution"
5
- gem.version = "0.5.1"
5
+ gem.version = "0.6.0"
6
6
  gem.authors = ["Paul Barry"]
7
7
  gem.email = ["mail@paulbarry.com"]
8
8
  gem.description = %q{Add attributes to Ruby objects}
@@ -1,3 +1,3 @@
1
1
  module Attribution
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/attribution.rb CHANGED
@@ -21,6 +21,10 @@ module Attribution
21
21
  end
22
22
  alias_method :to_h, :attributes
23
23
 
24
+ def to_json
25
+ to_h.to_json
26
+ end
27
+
24
28
  def attributes=(attributes)
25
29
  if attributes
26
30
  attributes = JSON.parse(attributes) if attributes.is_a?(String)
@@ -28,8 +32,6 @@ module Attribution
28
32
  setter = "#{k}="
29
33
  if respond_to?(setter)
30
34
  send(setter, v)
31
- else
32
- instance_variable_set("@#{k}", v)
33
35
  end
34
36
  end
35
37
  end
@@ -209,4 +209,14 @@ class AttributionTest < Test::Unit::TestCase
209
209
  def test_has_many_setter_with_hash
210
210
  assert_equal(["test"], Book.new("chapters" => { "0" => { "title" => "test" }}).chapters.map(&:title))
211
211
  end
212
+
213
+ def test_non_attribute_values_should_be_ignored_by_the_initializer
214
+ book = Book.new(foo: 'bar')
215
+ assert_equal nil, book.instance_variable_get('@foo')
216
+ end
217
+
218
+ def test_to_json_should_only_include_attibutes
219
+ book = Book.new(id: 1, foo: 'bar')
220
+ assert_equal nil, JSON.parse(book.to_json)['foo']
221
+ end
212
222
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attribution
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: