om 2.0.0 → 2.1.0
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.
- checksums.yaml +4 -4
- data/GETTING_STARTED.textile +2 -2
- data/History.textile +8 -0
- data/README.textile +4 -10
- data/lib/om/version.rb +1 -1
- data/lib/om/xml/term.rb +29 -149
- data/lib/om/xml/term_builder.rb +131 -0
- data/spec/integration/serialization_spec.rb +18 -0
- data/spec/unit/dynamic_node_spec.rb +12 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a6fa4665be8a90aed771767f2a4cdb5d6f76b98
|
4
|
+
data.tar.gz: d723ee94c4ffee487c4351a5d41e5d7146082e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 501f8065eb893cb977490025716bc52b293cfeda24b4bfff788d9120be39aa7e6ecc926e67b5b2f3c802ef014439d2da60e440a5c8466eefca73a15859ad0279
|
7
|
+
data.tar.gz: 9b8a97c71fe6f9ccdaf4debd091c97c77c6608ad747fbcbef91a218ffe10ee6fac902a2ef2966b090a0a008b0713bb5a5c13364163d1b73150b7ff143d06ff4e
|
data/GETTING_STARTED.textile
CHANGED
@@ -4,7 +4,7 @@ OM allows you to define a "terminology" to ease translation between XML and ruby
|
|
4
4
|
|
5
5
|
OM "terms" are ruby symbols you define (in the terminology) that map specific XML content into ruby object attributes.
|
6
6
|
|
7
|
-
The API documentation at "http://
|
7
|
+
The API documentation at "http://rdoc.info/github/projecthydra/om":http://rdoc.info/github/projecthydra/om provides additional, more targeted information. We will provide links to the API as appropriate.
|
8
8
|
|
9
9
|
h4. What you will learn from this document
|
10
10
|
|
@@ -251,4 +251,4 @@ terminology.xpath_for(:organization)
|
|
251
251
|
|
252
252
|
h2. Solrizing Documents
|
253
253
|
|
254
|
-
The solrizer gem provides support for indexing XML documents into Solr based on OM Terminologies. That process is documented in the "solrizer documentation":http://
|
254
|
+
The solrizer gem provides support for indexing XML documents into Solr based on OM Terminologies. That process is documented in the "solrizer documentation":http://rdoc.info/github/projecthydra/solrizer
|
data/History.textile
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
h3. 2.1.0 (unreleased)
|
2
|
+
support for element names with periods in them
|
3
|
+
support for 'type: :time'
|
4
|
+
|
5
|
+
|
6
|
+
h3. 2.0.0
|
7
|
+
Support new solr schema
|
8
|
+
|
1
9
|
h3. 1.8.0
|
2
10
|
Removed unused mods_article_terminology.xml
|
3
11
|
Replacing :data_type with :type; deprecating :data_type
|
data/README.textile
CHANGED
@@ -8,20 +8,14 @@ OM allows you to define a “terminology” to ease translation between XML and
|
|
8
8
|
|
9
9
|
OM “terms” are ruby symbols you define (in the terminology) that map specific XML content into ruby object attributes.
|
10
10
|
|
11
|
-
h2. Tutorials
|
11
|
+
h2. Tutorials & Reference
|
12
12
|
|
13
|
-
* "
|
14
|
-
* "
|
15
|
-
* "Updating Documents":https://github.com/projecthydra/om/blob/master/UPDATING_DOCUMENTS.textile
|
16
|
-
* "Getting Fancy":https://github.com/projecthydra/om/blob/master/GETTING_FANCY.textile
|
17
|
-
|
18
|
-
h2. Common OM Patterns
|
19
|
-
|
20
|
-
"Common OM Patterns":https://github.com/projecthydra/om/blob/master/COMMON_OM_PATTERNS.textile
|
13
|
+
* "Tame Your XML with OM":https://github.com/projecthydra/om/wiki/Tame-your-XML-with-OM
|
14
|
+
* "Common OM Patterns":https://github.com/projecthydra/om/blob/master/COMMON_OM_PATTERNS.textile
|
21
15
|
|
22
16
|
h3. Solrizing Documents
|
23
17
|
|
24
|
-
The solrizer gem provides support for indexing XML documents into Solr based on OM Terminologies. That process is documented in the "solrizer documentation":http://
|
18
|
+
The solrizer gem provides support for indexing XML documents into Solr based on OM Terminologies. That process is documented in the "solrizer documentation":http://rdoc.info/github/projecthydra/solrizer
|
25
19
|
|
26
20
|
h2. OM in the Wild
|
27
21
|
|
data/lib/om/version.rb
CHANGED
data/lib/om/xml/term.rb
CHANGED
@@ -1,147 +1,13 @@
|
|
1
|
+
require 'om/xml/term_builder'
|
2
|
+
|
1
3
|
# Special options:
|
2
4
|
# type, index_as, attributes,
|
3
5
|
# is_root_term, required
|
4
6
|
#
|
5
7
|
class OM::XML::Term
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# Term::Builder Class Definition
|
11
|
-
#
|
12
|
-
# @example
|
13
|
-
# tb2 = OM::XML::Term::Builder.new("my_term_name").path("fooPath").attributes({:lang=>"foo"}).index_as([:searchable, :facetable]).required(true).type(:text)
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# When coding against Builders, remember that they rely on MethodMissing,
|
18
|
-
# so any time you call a method on the Builder that it doesn't explicitly recognize,
|
19
|
-
# the Builder will add your method & arguments to the it's settings and return itself.
|
20
|
-
class Builder
|
21
|
-
|
22
|
-
attr_accessor :name, :settings, :children, :terminology_builder
|
23
|
-
|
24
|
-
def initialize(name, terminology_builder=nil)
|
25
|
-
@name = name.to_sym
|
26
|
-
@terminology_builder = terminology_builder
|
27
|
-
@settings = {:required=>false, :type=>:string}
|
28
|
-
@children = {}
|
29
|
-
end
|
30
|
-
|
31
|
-
def add_child(child)
|
32
|
-
@children[child.name] = child
|
33
|
-
end
|
34
|
-
|
35
|
-
def retrieve_child(child_name)
|
36
|
-
child = @children.fetch(child_name, nil)
|
37
|
-
end
|
38
|
-
|
39
|
-
def lookup_refs(nodes_visited=[])
|
40
|
-
result = []
|
41
|
-
if @settings[:ref]
|
42
|
-
# Fail if we do not have terminology builder
|
43
|
-
if self.terminology_builder.nil?
|
44
|
-
raise "Cannot perform lookup_ref for the #{self.name} builder. It doesn't have a reference to any terminology builder"
|
45
|
-
end
|
46
|
-
target = self.terminology_builder.retrieve_term_builder(*@settings[:ref])
|
47
|
-
|
48
|
-
# Fail on circular references and return an intelligible error message
|
49
|
-
if nodes_visited.include?(target)
|
50
|
-
nodes_visited << self
|
51
|
-
nodes_visited << target
|
52
|
-
trail = ""
|
53
|
-
nodes_visited.each_with_index do |node, z|
|
54
|
-
trail << node.name.inspect
|
55
|
-
unless z == nodes_visited.length-1
|
56
|
-
trail << " => "
|
57
|
-
end
|
58
|
-
end
|
59
|
-
raise OM::XML::Terminology::CircularReferenceError, "Circular reference in Terminology: #{trail}"
|
60
|
-
end
|
61
|
-
result << target
|
62
|
-
result.concat( target.lookup_refs(nodes_visited << self) )
|
63
|
-
end
|
64
|
-
return result
|
65
|
-
end
|
66
|
-
|
67
|
-
# If a :ref value has been set, looks up the target of that ref and merges the target's settings & children with the current builder's settings & children
|
68
|
-
# operates recursively, so it is possible to apply refs that in turn refer to other nodes.
|
69
|
-
def resolve_refs!
|
70
|
-
name_of_last_ref = nil
|
71
|
-
lookup_refs.each_with_index do |ref,z|
|
72
|
-
@settings = two_layer_merge(@settings, ref.settings)
|
73
|
-
@children.merge!(ref.children)
|
74
|
-
name_of_last_ref = ref.name
|
75
|
-
end
|
76
|
-
if @settings[:path].nil? && !name_of_last_ref.nil?
|
77
|
-
@settings[:path] = name_of_last_ref.to_s
|
78
|
-
end
|
79
|
-
@settings.delete :ref
|
80
|
-
return self
|
81
|
-
end
|
82
|
-
|
83
|
-
# Returns a new Hash that merges +downstream_hash+ with +upstream_hash+
|
84
|
-
# similar to calling +upstream_hash+.merge(+downstream_hash+) only it also merges
|
85
|
-
# any internal values that are themselves Hashes.
|
86
|
-
def two_layer_merge(downstream_hash, upstream_hash)
|
87
|
-
up = upstream_hash.dup
|
88
|
-
dn = downstream_hash.dup
|
89
|
-
up.each_pair do |setting_name, value|
|
90
|
-
if value.kind_of?(Hash) && downstream_hash.has_key?(setting_name)
|
91
|
-
dn[setting_name] = value.merge(downstream_hash[setting_name])
|
92
|
-
up.delete(setting_name)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
return up.merge(dn)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Builds a new OM::XML::Term based on the Builder object's current settings
|
99
|
-
# If no path has been provided, uses the Builder object's name as the term's path
|
100
|
-
# Recursively builds any children, appending the results as children of the Term that's being built.
|
101
|
-
# @param [OM::XML::Terminology] terminology that this Term is being built for
|
102
|
-
def build(terminology=nil)
|
103
|
-
self.resolve_refs!
|
104
|
-
if term.self.settings.has_key?(:proxy)
|
105
|
-
term = OM::XML::NamedTermProxy.new(self.name, self.settings[:proxy], terminology, self.settings)
|
106
|
-
else
|
107
|
-
term = OM::XML::Term.new(self.name, {}, terminology)
|
108
|
-
|
109
|
-
self.settings.each do |name, values|
|
110
|
-
if term.respond_to?(name.to_s+"=")
|
111
|
-
term.instance_variable_set("@#{name}", values)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
@children.each_value do |child|
|
115
|
-
term.add_child child.build(terminology)
|
116
|
-
end
|
117
|
-
term.generate_xpath_queries!
|
118
|
-
end
|
119
|
-
|
120
|
-
return term
|
121
|
-
end
|
122
|
-
|
123
|
-
# We have to add this method so it will play nice with ruby 1.8.7
|
124
|
-
def type value
|
125
|
-
@settings[:type] = value
|
126
|
-
return self
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
# Any unknown method calls will add an entry to the settings hash and return the current object
|
131
|
-
def method_missing method, *args, &block
|
132
|
-
if args.length == 1
|
133
|
-
args = args.first
|
134
|
-
end
|
135
|
-
@settings[method] = args
|
136
|
-
return self
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
#
|
141
|
-
# Class Definition for Term
|
142
|
-
#
|
143
|
-
|
144
9
|
include OM::TreeNode
|
10
|
+
include OM::XML::TermBuilder
|
145
11
|
|
146
12
|
attr_accessor :name, :xpath, :xpath_constrained, :xpath_relative, :path, :index_as, :required, :type, :variant_of, :path, :default_content_path, :is_root_term
|
147
13
|
attr_accessor :children, :internal_xml, :terminology
|
@@ -185,7 +51,7 @@ class OM::XML::Term
|
|
185
51
|
# @option opts [String] :path partial xpath that points to the node.
|
186
52
|
# @option opts [Hash] :attributes xml attributes to match in the selector
|
187
53
|
# @option opts [String] :namespace_prefix xml namespace for this node. If not provided, the default namespace set in the terminology will be used.
|
188
|
-
# @option opts [Symbol] :type one of :string, :date, :integer. Defaults to :string
|
54
|
+
# @option opts [Symbol] :type one of :string, :date, :time :integer. Defaults to :string
|
189
55
|
def initialize(name, opts={}, terminology=nil)
|
190
56
|
opts = {:ancestors=>[], :children=>{}}.merge(opts)
|
191
57
|
[:children, :ancestors,:path, :index_as, :required, :variant_of, :path, :attributes, :default_content_path, :namespace_prefix].each do |accessor_name|
|
@@ -228,6 +94,8 @@ class OM::XML::Term
|
|
228
94
|
case type
|
229
95
|
when :date, :integer
|
230
96
|
val.to_s
|
97
|
+
when :time
|
98
|
+
val.to_time.utc.iso8601
|
231
99
|
when :boolean
|
232
100
|
val.to_s
|
233
101
|
else
|
@@ -242,6 +110,9 @@ class OM::XML::Term
|
|
242
110
|
when :date
|
243
111
|
#TODO use present?
|
244
112
|
val.map { |v| !v.empty? ? Date.parse(v) : nil}
|
113
|
+
when :time
|
114
|
+
#TODO use present?
|
115
|
+
val.map { |v| !v.empty? ? DateTime.parse(v) : nil}
|
245
116
|
when :integer
|
246
117
|
#TODO use blank?
|
247
118
|
val.map { |v| v.empty? ? nil : v.to_i}
|
@@ -327,20 +198,29 @@ class OM::XML::Term
|
|
327
198
|
node_options << "\'#{k}\'=>\'#{v}\'" unless v == :none
|
328
199
|
end
|
329
200
|
end
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
builder_ref = "xml['#{self.path[0..path.index(":")-1]}']"
|
334
|
-
builder_method = self.path[path.index(":")+1..-1]
|
201
|
+
|
202
|
+
builder_ref = if self.path.include?(":")
|
203
|
+
"xml['#{self.path[0..path.index(":")-1]}']"
|
335
204
|
elsif !self.namespace_prefix.nil? and self.namespace_prefix != 'oxns'
|
336
|
-
|
337
|
-
|
338
|
-
|
205
|
+
"xml['#{self.namespace_prefix}']"
|
206
|
+
else
|
207
|
+
"xml"
|
339
208
|
end
|
340
|
-
|
341
|
-
|
209
|
+
|
210
|
+
attribute = OM::XML.delimited_list(node_options)
|
211
|
+
|
212
|
+
builder_method = if self.path.include?(":")
|
213
|
+
"#{self.path[path.index(":")+1..-1]}( #{attribute} )"
|
214
|
+
elsif self.path.include?(".")
|
215
|
+
"send(:\\\"#{self.path}\\\", #{attribute} )"
|
216
|
+
elsif self.path.kind_of?(Hash) && self.path[:attribute]
|
217
|
+
"@#{self.path[:attribute]}( #{OM::XML.delimited_list(node_options)} )"
|
218
|
+
elsif Nokogiri::XML::Builder.method_defined? self.path.to_sym
|
219
|
+
"#{self.path}_( #{OM::XML.delimited_list(node_options)} )"
|
220
|
+
else
|
221
|
+
"#{self.path}( #{OM::XML.delimited_list(node_options)} )"
|
342
222
|
end
|
343
|
-
template = "#{builder_ref}.#{builder_method}
|
223
|
+
template = "#{builder_ref}.#{builder_method}#{node_child_template}"
|
344
224
|
return template.gsub( /:::(.*?):::/ ) { '#{'+$1+'}' }
|
345
225
|
end
|
346
226
|
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# Term::Builder Class Definition
|
2
|
+
#
|
3
|
+
# @example
|
4
|
+
# tb2 = OM::XML::Term::Builder.new("my_term_name").path("fooPath").attributes({:lang=>"foo"}).index_as([:searchable, :facetable]).required(true).type(:text)
|
5
|
+
#
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# When coding against Builders, remember that they rely on MethodMissing,
|
9
|
+
# so any time you call a method on the Builder that it doesn't explicitly recognize,
|
10
|
+
# the Builder will add your method & arguments to the it's settings and return itself.
|
11
|
+
#
|
12
|
+
module OM::XML::TermBuilder
|
13
|
+
class Builder
|
14
|
+
attr_accessor :name, :settings, :children, :terminology_builder
|
15
|
+
|
16
|
+
def initialize(name, terminology_builder=nil)
|
17
|
+
@name = name.to_sym
|
18
|
+
@terminology_builder = terminology_builder
|
19
|
+
@settings = {:required=>false, :type=>:string}
|
20
|
+
@children = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_child(child)
|
24
|
+
@children[child.name] = child
|
25
|
+
end
|
26
|
+
|
27
|
+
def retrieve_child(child_name)
|
28
|
+
child = @children.fetch(child_name, nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
def lookup_refs(nodes_visited=[])
|
32
|
+
result = []
|
33
|
+
if @settings[:ref]
|
34
|
+
# Fail if we do not have terminology builder
|
35
|
+
if self.terminology_builder.nil?
|
36
|
+
raise "Cannot perform lookup_ref for the #{self.name} builder. It doesn't have a reference to any terminology builder"
|
37
|
+
end
|
38
|
+
target = self.terminology_builder.retrieve_term_builder(*@settings[:ref])
|
39
|
+
|
40
|
+
# Fail on circular references and return an intelligible error message
|
41
|
+
if nodes_visited.include?(target)
|
42
|
+
nodes_visited << self
|
43
|
+
nodes_visited << target
|
44
|
+
trail = ""
|
45
|
+
nodes_visited.each_with_index do |node, z|
|
46
|
+
trail << node.name.inspect
|
47
|
+
unless z == nodes_visited.length-1
|
48
|
+
trail << " => "
|
49
|
+
end
|
50
|
+
end
|
51
|
+
raise OM::XML::Terminology::CircularReferenceError, "Circular reference in Terminology: #{trail}"
|
52
|
+
end
|
53
|
+
result << target
|
54
|
+
result.concat( target.lookup_refs(nodes_visited << self) )
|
55
|
+
end
|
56
|
+
return result
|
57
|
+
end
|
58
|
+
|
59
|
+
# If a :ref value has been set, looks up the target of that ref and merges the target's settings & children with the current builder's settings & children
|
60
|
+
# operates recursively, so it is possible to apply refs that in turn refer to other nodes.
|
61
|
+
def resolve_refs!
|
62
|
+
name_of_last_ref = nil
|
63
|
+
lookup_refs.each_with_index do |ref,z|
|
64
|
+
@settings = two_layer_merge(@settings, ref.settings)
|
65
|
+
@children.merge!(ref.children)
|
66
|
+
name_of_last_ref = ref.name
|
67
|
+
end
|
68
|
+
if @settings[:path].nil? && !name_of_last_ref.nil?
|
69
|
+
@settings[:path] = name_of_last_ref.to_s
|
70
|
+
end
|
71
|
+
@settings.delete :ref
|
72
|
+
return self
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns a new Hash that merges +downstream_hash+ with +upstream_hash+
|
76
|
+
# similar to calling +upstream_hash+.merge(+downstream_hash+) only it also merges
|
77
|
+
# any internal values that are themselves Hashes.
|
78
|
+
def two_layer_merge(downstream_hash, upstream_hash)
|
79
|
+
up = upstream_hash.dup
|
80
|
+
dn = downstream_hash.dup
|
81
|
+
up.each_pair do |setting_name, value|
|
82
|
+
if value.kind_of?(Hash) && downstream_hash.has_key?(setting_name)
|
83
|
+
dn[setting_name] = value.merge(downstream_hash[setting_name])
|
84
|
+
up.delete(setting_name)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
return up.merge(dn)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Builds a new OM::XML::Term based on the Builder object's current settings
|
91
|
+
# If no path has been provided, uses the Builder object's name as the term's path
|
92
|
+
# Recursively builds any children, appending the results as children of the Term that's being built.
|
93
|
+
# @param [OM::XML::Terminology] terminology that this Term is being built for
|
94
|
+
def build(terminology=nil)
|
95
|
+
self.resolve_refs!
|
96
|
+
if term.self.settings.has_key?(:proxy)
|
97
|
+
term = OM::XML::NamedTermProxy.new(self.name, self.settings[:proxy], terminology, self.settings)
|
98
|
+
else
|
99
|
+
term = OM::XML::Term.new(self.name, {}, terminology)
|
100
|
+
|
101
|
+
self.settings.each do |name, values|
|
102
|
+
if term.respond_to?(name.to_s+"=")
|
103
|
+
term.instance_variable_set("@#{name}", values)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
@children.each_value do |child|
|
107
|
+
term.add_child child.build(terminology)
|
108
|
+
end
|
109
|
+
term.generate_xpath_queries!
|
110
|
+
end
|
111
|
+
|
112
|
+
return term
|
113
|
+
end
|
114
|
+
|
115
|
+
# We have to add this method so it will play nice with ruby 1.8.7
|
116
|
+
def type value
|
117
|
+
@settings[:type] = value
|
118
|
+
return self
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# Any unknown method calls will add an entry to the settings hash and return the current object
|
123
|
+
def method_missing method, *args, &block
|
124
|
+
if args.length == 1
|
125
|
+
args = args.first
|
126
|
+
end
|
127
|
+
@settings[method] = args
|
128
|
+
return self
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -8,6 +8,7 @@ describe "element values" do
|
|
8
8
|
set_terminology do |t|
|
9
9
|
t.root(:path => "outer", :xmlns => nil)
|
10
10
|
t.my_date(:type=>:date)
|
11
|
+
t.my_time(:type=>:time)
|
11
12
|
t.my_int(:type=>:integer)
|
12
13
|
t.active(:type=>:boolean)
|
13
14
|
t.wrapper do
|
@@ -23,6 +24,7 @@ describe "element values" do
|
|
23
24
|
ElementValueTerminology.from_xml <<-EOF
|
24
25
|
<outer outerId="hypatia:outer" type="outer type">
|
25
26
|
<my_date>2012-10-30</my_date>
|
27
|
+
<my_time>2012-10-30T12:22:33Z</my_time>
|
26
28
|
<my_int>7</my_int>
|
27
29
|
<active>true</active>
|
28
30
|
</outer>
|
@@ -32,6 +34,9 @@ EOF
|
|
32
34
|
it "should deserialize date" do
|
33
35
|
subject.my_date.should == [Date.parse('2012-10-30')]
|
34
36
|
end
|
37
|
+
it "should deserialize time" do
|
38
|
+
subject.my_time.should == [DateTime.parse('2012-10-30T12:22:33Z')]
|
39
|
+
end
|
35
40
|
it "should deserialize ints" do
|
36
41
|
subject.my_int.should == [7]
|
37
42
|
end
|
@@ -40,11 +45,22 @@ EOF
|
|
40
45
|
end
|
41
46
|
end
|
42
47
|
describe "Writing to xml" do
|
48
|
+
it "should serialize time" do
|
49
|
+
subject.my_time = [DateTime.parse('2011-01-30T03:45:15Z')]
|
50
|
+
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
51
|
+
<outer outerId="hypatia:outer" type="outer type">
|
52
|
+
<my_date>2012-10-30</my_date>
|
53
|
+
<my_time>2011-01-30T03:45:15Z</my_time>
|
54
|
+
<my_int>7</my_int>
|
55
|
+
<active>true</active>
|
56
|
+
</outer>'
|
57
|
+
end
|
43
58
|
it "should serialize date" do
|
44
59
|
subject.my_date = [Date.parse('2012-09-22')]
|
45
60
|
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
46
61
|
<outer outerId="hypatia:outer" type="outer type">
|
47
62
|
<my_date>2012-09-22</my_date>
|
63
|
+
<my_time>2012-10-30T12:22:33Z</my_time>
|
48
64
|
<my_int>7</my_int>
|
49
65
|
<active>true</active>
|
50
66
|
</outer>'
|
@@ -54,6 +70,7 @@ EOF
|
|
54
70
|
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
55
71
|
<outer outerId="hypatia:outer" type="outer type">
|
56
72
|
<my_date>2012-10-30</my_date>
|
73
|
+
<my_time>2012-10-30T12:22:33Z</my_time>
|
57
74
|
<my_int>9</my_int>
|
58
75
|
<active>true</active>
|
59
76
|
</outer>'
|
@@ -63,6 +80,7 @@ EOF
|
|
63
80
|
subject.to_xml.should be_equivalent_to '<?xml version="1.0"?>
|
64
81
|
<outer outerId="hypatia:outer" type="outer type">
|
65
82
|
<my_date>2012-10-30</my_date>
|
83
|
+
<my_time>2012-10-30T12:22:33Z</my_time>
|
66
84
|
<my_int>7</my_int>
|
67
85
|
<active>false</active>
|
68
86
|
</outer>'
|
@@ -8,7 +8,9 @@ describe "OM::XML::DynamicNode" do
|
|
8
8
|
|
9
9
|
set_terminology do |t|
|
10
10
|
t.root(:path=>"dc", :xmlns=>"http://purl.org/dc/terms/")
|
11
|
-
t.creator(
|
11
|
+
t.creator( :namespace_prefix => "dcterms")
|
12
|
+
t.foo(:namespace_prefix => "dcterms")
|
13
|
+
t.date_created(:path=>'date.created', :namespace_prefix => "dcterms")
|
12
14
|
end
|
13
15
|
|
14
16
|
def self.xml_template
|
@@ -29,6 +31,15 @@ describe "OM::XML::DynamicNode" do
|
|
29
31
|
@sample.creator = ["Foo", "Bar"]
|
30
32
|
@sample.creator.should == ['Foo', 'Bar']
|
31
33
|
end
|
34
|
+
it "should create templates for plain nodes" do
|
35
|
+
@sample.foo = ['in a galaxy far far away']
|
36
|
+
@sample.foo.should == ['in a galaxy far far away']
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should create templates for dynamic nodes with a period in the element name" do
|
40
|
+
@sample.date_created = ['A long time ago']
|
41
|
+
@sample.date_created.should == ['A long time ago']
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
34
45
|
|
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: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Zumwalt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -229,6 +229,7 @@ files:
|
|
229
229
|
- lib/om/xml/node_generator.rb
|
230
230
|
- lib/om/xml/template_registry.rb
|
231
231
|
- lib/om/xml/term.rb
|
232
|
+
- lib/om/xml/term_builder.rb
|
232
233
|
- lib/om/xml/term_value_operators.rb
|
233
234
|
- lib/om/xml/term_xpath_generator.rb
|
234
235
|
- lib/om/xml/terminology.rb
|
@@ -294,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
294
295
|
version: '0'
|
295
296
|
requirements: []
|
296
297
|
rubyforge_project:
|
297
|
-
rubygems_version: 2.0.
|
298
|
+
rubygems_version: 2.0.3
|
298
299
|
signing_key:
|
299
300
|
specification_version: 4
|
300
301
|
summary: 'OM (Opinionated Metadata): A library to help you tame sprawling XML schemas
|