json_record 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGE_LOG +4 -0
- data/VERSION +1 -1
- data/json_record.gemspec +2 -2
- data/lib/json_record/embedded_document.rb +13 -8
- data/lib/json_record/json_field.rb +9 -4
- metadata +2 -2
data/CHANGE_LOG
CHANGED
@@ -22,3 +22,7 @@
|
|
22
22
|
1.0.6
|
23
23
|
- Allow EmbeddedDocument.new to call all accessors and not just those defined in the JSON schema.
|
24
24
|
- Allow getting and setting json attributes with [] and []=
|
25
|
+
|
26
|
+
1.0.7
|
27
|
+
- Added attributes= to EmbeddedDocument for mass attribute assignment
|
28
|
+
- Changed deserialized Json values to go through setter methods instead of being directly set
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.7
|
data/json_record.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{json_record}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Durand"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-26}
|
13
13
|
s.email = %q{brian@embellishedvisions.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.rdoc"
|
@@ -82,22 +82,27 @@ module JsonRecord
|
|
82
82
|
def initialize (attrs = {})
|
83
83
|
@attributes = {}
|
84
84
|
@json_attributes = {}
|
85
|
+
self.attributes = attrs
|
86
|
+
end
|
87
|
+
|
88
|
+
# Get the attributes of the document.
|
89
|
+
def attributes
|
90
|
+
@json_attributes.reject{|k,v| !schema.fields.include?(k)}
|
91
|
+
end
|
92
|
+
|
93
|
+
# Set all the attributes at once.
|
94
|
+
def attributes= (attrs)
|
85
95
|
attrs.each_pair do |name, value|
|
86
96
|
field = schema.fields[name.to_s] || FieldDefinition.new(name, :type => value.class)
|
87
|
-
|
88
|
-
if respond_to?(
|
89
|
-
send(
|
97
|
+
setter = "#{name}=".to_sym
|
98
|
+
if respond_to?(setter)
|
99
|
+
send(setter, value)
|
90
100
|
else
|
91
101
|
write_attribute(field, value, self)
|
92
102
|
end
|
93
103
|
end
|
94
104
|
end
|
95
105
|
|
96
|
-
# Get the attributes of the document.
|
97
|
-
def attributes
|
98
|
-
@json_attributes.reject{|k,v| !schema.fields.include?(k)}
|
99
|
-
end
|
100
|
-
|
101
106
|
# Get the attribute values of the document before they were type cast.
|
102
107
|
def attributes_before_type_cast
|
103
108
|
@attributes
|
@@ -37,10 +37,15 @@ module JsonRecord
|
|
37
37
|
Thread.current[:do_not_track_json_field_changes] = true
|
38
38
|
begin
|
39
39
|
ActiveSupport::JSON.decode(json).each_pair do |attr_name, attr_value|
|
40
|
-
|
41
|
-
@
|
42
|
-
|
43
|
-
|
40
|
+
setter = "#{attr_name}=".to_sym
|
41
|
+
if @record.respond_to?(setter)
|
42
|
+
@record.send(setter, attr_value)
|
43
|
+
else
|
44
|
+
field = nil
|
45
|
+
@schemas.each{|schema| field = schema.fields[attr_name]; break if field}
|
46
|
+
field = FieldDefinition.new(attr_name, :type => attr_value.class) unless field
|
47
|
+
write_attribute(field, attr_value, @record)
|
48
|
+
end
|
44
49
|
end
|
45
50
|
ensure
|
46
51
|
Thread.current[:do_not_track_json_field_changes] = do_not_track_changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Durand
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-26 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|