attribution 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/attribution.gemspec +1 -1
- data/lib/attribution/version.rb +1 -1
- data/lib/attribution.rb +13 -11
- data/test/attribution_test.rb +1 -0
- metadata +2 -2
data/attribution.gemspec
CHANGED
data/lib/attribution/version.rb
CHANGED
data/lib/attribution.rb
CHANGED
@@ -10,6 +10,9 @@ module Attribution
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(attributes={})
|
13
|
+
self.class.attribute_names.each do |attr|
|
14
|
+
instance_variable_set("@#{attr}", nil)
|
15
|
+
end
|
13
16
|
self.attributes = attributes
|
14
17
|
end
|
15
18
|
|
@@ -21,18 +24,17 @@ module Attribution
|
|
21
24
|
end
|
22
25
|
alias_method :to_h, :attributes
|
23
26
|
|
24
|
-
def to_json
|
25
|
-
to_h.to_json
|
26
|
-
end
|
27
|
-
|
28
27
|
def attributes=(attributes)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
attributes = case attributes
|
29
|
+
when String then JSON.parse(attributes)
|
30
|
+
when Hash then attributes
|
31
|
+
else {}
|
32
|
+
end.with_indifferent_access
|
33
|
+
|
34
|
+
attributes.each do |k,v|
|
35
|
+
setter = "#{k}="
|
36
|
+
if respond_to?(setter)
|
37
|
+
send(setter, v)
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
data/test/attribution_test.rb
CHANGED
@@ -218,5 +218,6 @@ class AttributionTest < Test::Unit::TestCase
|
|
218
218
|
def test_to_json_should_only_include_attibutes
|
219
219
|
book = Book.new(id: 1, foo: 'bar')
|
220
220
|
assert_equal nil, JSON.parse(book.to_json)['foo']
|
221
|
+
assert JSON.parse(book.to_json).key?('title'), 'to_json sohuld include attributes that have no value assigned to them'
|
221
222
|
end
|
222
223
|
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.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|