om 1.7.0.rc1 → 1.7.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -2
- data/lib/om/version.rb +1 -1
- data/lib/om/xml/dynamic_node.rb +2 -42
- data/lib/om/xml/term.rb +44 -0
- data/lib/om/xml/term_value_operators.rb +11 -12
- data/spec/integration/serialization_spec.rb +106 -25
- metadata +2 -3
- data/Gemfile.lock +0 -82
data/.gitignore
CHANGED
data/lib/om/version.rb
CHANGED
data/lib/om/xml/dynamic_node.rb
CHANGED
@@ -69,7 +69,7 @@ module OM
|
|
69
69
|
|
70
70
|
def val=(args)
|
71
71
|
@document.ng_xml_will_change!
|
72
|
-
new_values = sanitize_new_values(args.first)
|
72
|
+
new_values = term.sanitize_new_values(args.first)
|
73
73
|
new_values.keys.sort { |a,b| a.to_i <=> b.to_i }.each do |y|
|
74
74
|
z = new_values[y]
|
75
75
|
## If we pass something that already has an index on it, we should be able to add it.
|
@@ -82,20 +82,6 @@ module OM
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
def sanitize_new_values(new_values)
|
86
|
-
# Sanitize new_values to always be a hash with indexes
|
87
|
-
case new_values
|
88
|
-
when Hash
|
89
|
-
new_values.each {|k, v| v = serialize(v) }
|
90
|
-
when Array
|
91
|
-
nv = new_values.dup
|
92
|
-
new_values = {}
|
93
|
-
nv.each {|v| new_values[nv.index(v).to_s] = serialize(v)}
|
94
|
-
else
|
95
|
-
new_values = {"0"=>serialize(new_values)}
|
96
|
-
end
|
97
|
-
new_values
|
98
|
-
end
|
99
85
|
|
100
86
|
def term_child_by_name(term, name)
|
101
87
|
if (term.kind_of? NamedTermProxy)
|
@@ -109,35 +95,9 @@ module OM
|
|
109
95
|
query = xpath
|
110
96
|
trim_text = !query.index("text()").nil?
|
111
97
|
val = @document.find_by_xpath(query).collect {|node| (trim_text ? node.text.strip : node.text) }
|
112
|
-
deserialize(val)
|
113
|
-
end
|
114
|
-
|
115
|
-
# @param string
|
116
|
-
# @return [String,Date,Integer]
|
117
|
-
def deserialize(val)
|
118
|
-
case term.type
|
119
|
-
when :date
|
120
|
-
val.map { |v| Date.parse(v)}
|
121
|
-
when :integer
|
122
|
-
val.map { |v| v.to_i}
|
123
|
-
else
|
124
|
-
val
|
125
|
-
end
|
98
|
+
term.deserialize(val)
|
126
99
|
end
|
127
100
|
|
128
|
-
# @param val [String,Date,Integer]
|
129
|
-
def serialize (val)
|
130
|
-
case term.type
|
131
|
-
when :date
|
132
|
-
val.to_s
|
133
|
-
when :integer
|
134
|
-
val.to_s
|
135
|
-
else
|
136
|
-
val
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
101
|
def nodeset
|
142
102
|
query = xpath
|
143
103
|
trim_text = !query.index("text()").nil?
|
data/lib/om/xml/term.rb
CHANGED
@@ -203,6 +203,50 @@ class OM::XML::Term
|
|
203
203
|
end
|
204
204
|
|
205
205
|
|
206
|
+
def sanitize_new_values(new_values)
|
207
|
+
# Sanitize new_values to always be a hash with indexes
|
208
|
+
case new_values
|
209
|
+
when Hash
|
210
|
+
new_values.each {|k, v| v = serialize(v) }
|
211
|
+
when Array
|
212
|
+
nv = new_values.dup
|
213
|
+
new_values = {}
|
214
|
+
nv.each {|v| new_values[nv.index(v).to_s] = serialize(v)}
|
215
|
+
else
|
216
|
+
new_values = {"0"=>serialize(new_values)}
|
217
|
+
end
|
218
|
+
new_values
|
219
|
+
end
|
220
|
+
|
221
|
+
# @param val [String,Date,Integer]
|
222
|
+
def serialize (val)
|
223
|
+
case type
|
224
|
+
when :date, :integer
|
225
|
+
val.to_s
|
226
|
+
when :boolean
|
227
|
+
val.to_s
|
228
|
+
else
|
229
|
+
val
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
# @param string
|
234
|
+
# @return [String,Date,Integer]
|
235
|
+
def deserialize(val)
|
236
|
+
case type
|
237
|
+
when :date
|
238
|
+
#TODO use present?
|
239
|
+
val.map { |v| !v.empty? ? Date.parse(v) : nil}
|
240
|
+
when :integer
|
241
|
+
#TODO use blank?
|
242
|
+
val.map { |v| v.empty? ? nil : v.to_i}
|
243
|
+
when :boolean
|
244
|
+
val.map { |v| v == 'true' }
|
245
|
+
else
|
246
|
+
val
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
206
250
|
def self.from_node(mapper_xml)
|
207
251
|
name = mapper_xml.attribute("name").text.to_sym
|
208
252
|
attributes = {}
|
@@ -11,8 +11,14 @@ module OM::XML::TermValueOperators
|
|
11
11
|
#if value is on line by itself sometimes does not trim leading and trailing whitespace for a text node so will detect and fix it
|
12
12
|
trim_text = !xpath.nil? && !xpath.index("text()").nil?
|
13
13
|
find_by_terms(*term_pointer).each {|node| result << (trim_text ? node.text.strip : node.text) }
|
14
|
-
|
15
|
-
|
14
|
+
|
15
|
+
if term_pointer.length == 1 && term_pointer.first.kind_of?(String)
|
16
|
+
logger.warn "Passing a xpath to term_values means that OM can not properly find the associated term. Pass a term pointer instead."
|
17
|
+
result
|
18
|
+
else
|
19
|
+
term = self.class.terminology.retrieve_term(*OM.pointers_to_flat_array(OM.destringify(term_pointer), false))
|
20
|
+
term.deserialize(result)
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
# alias for term_values
|
@@ -40,16 +46,10 @@ module OM::XML::TermValueOperators
|
|
40
46
|
template_pointer = OM.pointers_to_flat_array(pointer,false)
|
41
47
|
hn = OM::XML::Terminology.term_hierarchical_name(*pointer)
|
42
48
|
|
49
|
+
term = self.class.terminology.retrieve_term( *OM.pointers_to_flat_array(pointer,false) )
|
50
|
+
|
43
51
|
# Sanitize new_values to always be a hash with indexes
|
44
|
-
|
45
|
-
when Hash
|
46
|
-
when Array
|
47
|
-
nv = new_values.dup
|
48
|
-
new_values = {}
|
49
|
-
nv.each {|v| new_values[nv.index(v).to_s] = v}
|
50
|
-
else
|
51
|
-
new_values = {"0"=>new_values}
|
52
|
-
end
|
52
|
+
new_values = term.sanitize_new_values(new_values)
|
53
53
|
|
54
54
|
# Populate the response hash appropriately, using hierarchical names for terms as keys rather than the given pointers.
|
55
55
|
result.delete(term_pointer)
|
@@ -65,7 +65,6 @@ module OM::XML::TermValueOperators
|
|
65
65
|
end
|
66
66
|
|
67
67
|
# Fill out the pointer completely if the final term is a NamedTermProxy
|
68
|
-
term = self.class.terminology.retrieve_term( *OM.pointers_to_flat_array(pointer,false) )
|
69
68
|
if term.kind_of? OM::XML::NamedTermProxy
|
70
69
|
pointer.pop
|
71
70
|
pointer = pointer.concat(term.proxy_pointer)
|
@@ -9,45 +9,126 @@ describe "element values" do
|
|
9
9
|
t.root(:path => "outer", :xmlns => nil)
|
10
10
|
t.my_date(:type=>:date)
|
11
11
|
t.my_int(:type=>:integer)
|
12
|
+
t.active(:type=>:boolean)
|
13
|
+
t.wrapper do
|
14
|
+
t.inner_date(:type=>:date)
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
16
|
-
|
17
|
-
|
20
|
+
|
21
|
+
describe "when the xml template has existing values" do
|
22
|
+
subject do
|
23
|
+
ElementValueTerminology.from_xml <<-EOF
|
18
24
|
<outer outerId="hypatia:outer" type="outer type">
|
19
25
|
<my_date>2012-10-30</my_date>
|
20
26
|
<my_int>7</my_int>
|
27
|
+
<active>true</active>
|
21
28
|
</outer>
|
22
29
|
EOF
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "Reading from xml" do
|
26
|
-
it "should handle date" do
|
27
|
-
subject.my_date.should == [Date.parse('2012-10-30')]
|
28
30
|
end
|
29
|
-
|
30
|
-
|
31
|
+
describe "reading values" do
|
32
|
+
it "should deserialize date" do
|
33
|
+
subject.my_date.should == [Date.parse('2012-10-30')]
|
34
|
+
end
|
35
|
+
it "should deserialize ints" do
|
36
|
+
subject.my_int.should == [7]
|
37
|
+
end
|
38
|
+
it "should deserialize boolean" do
|
39
|
+
subject.active.should == [true]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
describe "Writing to xml" do
|
43
|
+
it "should serialize date" do
|
44
|
+
subject.my_date = [Date.parse('2012-09-22')]
|
45
|
+
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
46
|
+
<outer outerId="hypatia:outer" type="outer type">
|
47
|
+
<my_date>2012-09-22</my_date>
|
48
|
+
<my_int>7</my_int>
|
49
|
+
<active>true</active>
|
50
|
+
</outer>'
|
51
|
+
end
|
52
|
+
it "should serialize ints" do
|
53
|
+
subject.my_int = [9]
|
54
|
+
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
55
|
+
<outer outerId="hypatia:outer" type="outer type">
|
56
|
+
<my_date>2012-10-30</my_date>
|
57
|
+
<my_int>9</my_int>
|
58
|
+
<active>true</active>
|
59
|
+
</outer>'
|
60
|
+
end
|
61
|
+
it "should serialize boolean" do
|
62
|
+
subject.active = [false]
|
63
|
+
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
64
|
+
<outer outerId="hypatia:outer" type="outer type">
|
65
|
+
<my_date>2012-10-30</my_date>
|
66
|
+
<my_int>7</my_int>
|
67
|
+
<active>false</active>
|
68
|
+
</outer>'
|
69
|
+
end
|
31
70
|
end
|
32
71
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
72
|
+
|
73
|
+
describe "when the xml template is empty" do
|
74
|
+
subject do
|
75
|
+
ElementValueTerminology.from_xml <<-EOF
|
76
|
+
<outer outerId="hypatia:outer" type="outer type">
|
77
|
+
<my_date></my_date>
|
78
|
+
<my_int></my_int>
|
79
|
+
<active></active>
|
80
|
+
</outer>
|
81
|
+
EOF
|
41
82
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
83
|
+
describe "reading values" do
|
84
|
+
it "should deserialize date" do
|
85
|
+
subject.my_date.should == [nil]
|
86
|
+
end
|
87
|
+
it "should deserialize ints" do
|
88
|
+
subject.my_int.should == [nil]
|
89
|
+
end
|
90
|
+
it "should deserialize bools" do
|
91
|
+
subject.active.should == [false]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
describe "Writing to xml" do
|
95
|
+
it "should serialize date" do
|
96
|
+
subject.my_date = [Date.parse('2012-09-22')]
|
97
|
+
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
98
|
+
<outer outerId="hypatia:outer" type="outer type">
|
99
|
+
<my_date>2012-09-22</my_date>
|
100
|
+
<my_int></my_int>
|
101
|
+
<active/>
|
102
|
+
</outer>'
|
103
|
+
end
|
104
|
+
it "should serialize ints" do
|
105
|
+
subject.my_int = [9]
|
106
|
+
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
107
|
+
<outer outerId="hypatia:outer" type="outer type">
|
108
|
+
<my_date></my_date>
|
109
|
+
<my_int>9</my_int>
|
110
|
+
<active/>
|
111
|
+
</outer>'
|
112
|
+
end
|
113
|
+
it "should serialize booleans" do
|
114
|
+
subject.active = [true]
|
115
|
+
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
116
|
+
<outer outerId="hypatia:outer" type="outer type">
|
117
|
+
<my_date></my_date>
|
118
|
+
<my_int></my_int>
|
119
|
+
<active>true</active>
|
120
|
+
</outer>'
|
121
|
+
end
|
122
|
+
it "should serialize nil values" do
|
123
|
+
# I'm not sure that this is the correct behavior for this. Should it remove nodes or just blank them.
|
124
|
+
subject.my_int = [nil]
|
125
|
+
subject.my_date = [nil]
|
126
|
+
subject.active = [nil]
|
127
|
+
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
128
|
+
<outer outerId="hypatia:outer" type="outer type">
|
129
|
+
</outer>'
|
130
|
+
end
|
49
131
|
end
|
50
132
|
end
|
51
|
-
|
52
133
|
end
|
53
134
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: om
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.0.
|
4
|
+
version: 1.7.0.rc2
|
5
5
|
prerelease: 6
|
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: 2012-10-
|
12
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -174,7 +174,6 @@ files:
|
|
174
174
|
- GETTING_FANCY.textile
|
175
175
|
- GETTING_STARTED.textile
|
176
176
|
- Gemfile
|
177
|
-
- Gemfile.lock
|
178
177
|
- History.textile
|
179
178
|
- LICENSE
|
180
179
|
- QUERYING_DOCUMENTS.textile
|
data/Gemfile.lock
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
om (1.6.2)
|
5
|
-
activemodel
|
6
|
-
activesupport
|
7
|
-
mediashelf-loggable
|
8
|
-
nokogiri (>= 1.4.2)
|
9
|
-
|
10
|
-
GEM
|
11
|
-
remote: http://rubygems.org/
|
12
|
-
specs:
|
13
|
-
RedCloth (4.2.9)
|
14
|
-
activemodel (3.2.8)
|
15
|
-
activesupport (= 3.2.8)
|
16
|
-
builder (~> 3.0.0)
|
17
|
-
activesupport (3.2.8)
|
18
|
-
i18n (~> 0.6)
|
19
|
-
multi_json (~> 1.0)
|
20
|
-
awesome_print (1.0.2)
|
21
|
-
builder (3.0.0)
|
22
|
-
columnize (0.3.6)
|
23
|
-
debugger (1.2.0)
|
24
|
-
columnize (>= 0.3.1)
|
25
|
-
debugger-linecache (~> 1.1.1)
|
26
|
-
debugger-ruby_core_source (~> 1.1.3)
|
27
|
-
debugger-linecache (1.1.2)
|
28
|
-
debugger-ruby_core_source (>= 1.1.1)
|
29
|
-
debugger-ruby_core_source (1.1.3)
|
30
|
-
diff-lcs (1.1.3)
|
31
|
-
equivalent-xml (0.2.9)
|
32
|
-
nokogiri (>= 1.4.3)
|
33
|
-
i18n (0.6.0)
|
34
|
-
linecache (0.46)
|
35
|
-
rbx-require-relative (> 0.0.4)
|
36
|
-
mediashelf-loggable (0.4.9)
|
37
|
-
metaclass (0.0.1)
|
38
|
-
mocha (0.12.3)
|
39
|
-
metaclass (~> 0.0.1)
|
40
|
-
multi_json (1.3.6)
|
41
|
-
nokogiri (1.5.5)
|
42
|
-
rake (0.9.2.2)
|
43
|
-
rbx-require-relative (0.0.9)
|
44
|
-
rcov (1.0.0)
|
45
|
-
rspec (2.11.0)
|
46
|
-
rspec-core (~> 2.11.0)
|
47
|
-
rspec-expectations (~> 2.11.0)
|
48
|
-
rspec-mocks (~> 2.11.0)
|
49
|
-
rspec-core (2.11.1)
|
50
|
-
rspec-expectations (2.11.2)
|
51
|
-
diff-lcs (~> 1.1.3)
|
52
|
-
rspec-mocks (2.11.2)
|
53
|
-
ruby-debug (0.10.4)
|
54
|
-
columnize (>= 0.1)
|
55
|
-
ruby-debug-base (~> 0.10.4.0)
|
56
|
-
ruby-debug-base (0.10.4)
|
57
|
-
linecache (>= 0.3)
|
58
|
-
simplecov (0.6.4)
|
59
|
-
multi_json (~> 1.0)
|
60
|
-
simplecov-html (~> 0.5.3)
|
61
|
-
simplecov-html (0.5.3)
|
62
|
-
simplecov-rcov (0.2.3)
|
63
|
-
simplecov (>= 0.4.1)
|
64
|
-
yard (0.8.2.1)
|
65
|
-
|
66
|
-
PLATFORMS
|
67
|
-
ruby
|
68
|
-
|
69
|
-
DEPENDENCIES
|
70
|
-
RedCloth (~> 4.2.9)
|
71
|
-
awesome_print
|
72
|
-
debugger
|
73
|
-
equivalent-xml (>= 0.2.4)
|
74
|
-
mocha (>= 0.9.8)
|
75
|
-
om!
|
76
|
-
rake
|
77
|
-
rcov
|
78
|
-
rspec (~> 2.0)
|
79
|
-
ruby-debug
|
80
|
-
simplecov
|
81
|
-
simplecov-rcov
|
82
|
-
yard
|