om 1.6.0.rc2 → 1.6.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/om/version.rb +1 -1
- data/lib/om/xml/document.rb +1 -0
- data/lib/om/xml/dynamic_node.rb +2 -2
- data/lib/om/xml/term_value_operators.rb +7 -6
- data/spec/unit/dynamic_node_spec.rb +116 -78
- metadata +12 -12
data/lib/om/version.rb
CHANGED
data/lib/om/xml/document.rb
CHANGED
@@ -170,6 +170,7 @@ module OM::XML::Document
|
|
170
170
|
if target.is_a?(Array)
|
171
171
|
target = self.find_by_terms(*target)
|
172
172
|
end
|
173
|
+
raise "You must call define_template before calling #{method}" if template_registry.nil?
|
173
174
|
template_registry.send(method, target, *args, &block)
|
174
175
|
end
|
175
176
|
end
|
data/lib/om/xml/dynamic_node.rb
CHANGED
@@ -38,7 +38,7 @@ module OM
|
|
38
38
|
self.parent = parent
|
39
39
|
end
|
40
40
|
|
41
|
-
def method_missing (name, *args)
|
41
|
+
def method_missing (name, *args, &block)
|
42
42
|
if /=$/.match(name.to_s)
|
43
43
|
new_update_node(name, args)
|
44
44
|
elsif args.length > 1
|
@@ -48,7 +48,7 @@ module OM
|
|
48
48
|
if child
|
49
49
|
OM::XML::DynamicNode.new(name, args.first, @document, child, self)
|
50
50
|
else
|
51
|
-
val.send(name, *args)
|
51
|
+
val.send(name, *args, &block)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -103,10 +103,11 @@ module OM::XML::TermValueOperators
|
|
103
103
|
parent_node = node_from_set(parent_nodeset, parent_index)
|
104
104
|
|
105
105
|
if parent_node.nil?
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
106
|
+
if parent_select.empty?
|
107
|
+
parent_node = ng_xml.root
|
108
|
+
else
|
109
|
+
parent_node = build_ancestors(parent_select, parent_index)
|
110
|
+
end
|
110
111
|
end
|
111
112
|
|
112
113
|
insert_from_template(parent_node, new_values, template)
|
@@ -114,7 +115,7 @@ module OM::XML::TermValueOperators
|
|
114
115
|
return parent_node
|
115
116
|
|
116
117
|
end
|
117
|
-
|
118
|
+
|
118
119
|
# Insert xml containing +new_values+ into +parent_node+. Generate the xml based on +template+
|
119
120
|
# @param [Nokogiri::XML::Node] parent_node to insert new xml into
|
120
121
|
# @param [Array] new_values to build the xml around
|
@@ -197,7 +198,7 @@ module OM::XML::TermValueOperators
|
|
197
198
|
if parent_index > starting_point.length
|
198
199
|
parent_index = starting_point.length - 1
|
199
200
|
end
|
200
|
-
return node_from_set(starting_point, parent_index)
|
201
|
+
return node_from_set(starting_point, parent_index)
|
201
202
|
end
|
202
203
|
|
203
204
|
def term_value_update(node_select,node_index,new_value,opts={})
|
@@ -2,106 +2,144 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
require "om"
|
3
3
|
|
4
4
|
describe "OM::XML::DynamicNode" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "dynamically created nodes" do
|
5
|
+
describe do
|
6
|
+
before do
|
7
|
+
class Sample
|
8
|
+
include OM::XML::Document
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
expected_values.each {|v| result.should include(v)}
|
18
|
-
end
|
10
|
+
set_terminology do |t|
|
11
|
+
t.root(:path=>"dc", :xmlns=>"http://purl.org/dc/terms/")
|
12
|
+
t.creator(:xmlns=>"http://www.loc.gov/mods/v3", :namespace_prefix => "dcterms")
|
13
|
+
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
15
|
+
def self.xml_template
|
16
|
+
Nokogiri::XML::Document.parse("<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>")
|
17
|
+
end
|
24
18
|
|
25
|
-
|
26
|
-
@
|
27
|
-
@article.abstract.should == ["My Abstract", 'two']
|
19
|
+
end
|
20
|
+
@sample = Sample.from_xml
|
28
21
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
after do
|
23
|
+
Object.send(:remove_const, :Sample)
|
24
|
+
end
|
25
|
+
it "should create templates for dynamic nodes" do
|
26
|
+
@sample.creator = "Foo"
|
27
|
+
@sample.creator.should == ['Foo']
|
33
28
|
end
|
29
|
+
it "should create templates for dynamic nodes with multiple values" do
|
30
|
+
@sample.creator = ["Foo", "Bar"]
|
31
|
+
@sample.creator.should == ['Foo', 'Bar']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
describe "with a template" do
|
37
|
+
before(:each) do
|
38
|
+
@sample = OM::Samples::ModsArticle.from_xml( fixture( File.join("test_dummy_mods.xml") ) )
|
39
|
+
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "dynamically created nodes" do
|
34
43
|
|
44
|
+
it "should return build an array of values from the nodeset corresponding to the given term" do
|
45
|
+
expected_values = ["Berners-Lee", "Jobs", "Wozniak", "Klimt"]
|
46
|
+
result = @sample.person.last_name
|
47
|
+
result.length.should == expected_values.length
|
48
|
+
expected_values.each {|v| result.should include(v)}
|
49
|
+
end
|
35
50
|
|
36
|
-
|
37
|
-
|
38
|
-
@article.
|
39
|
-
@article.title_info(0).main_title.main_title_lang.should == ["ger"]
|
51
|
+
it "should be able to set first level elements" do
|
52
|
+
@article.abstract = "My Abstract"
|
53
|
+
@article.abstract.should == ["My Abstract"]
|
40
54
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@article.
|
55
|
+
|
56
|
+
it "should be able to set first level elements that are arrays" do
|
57
|
+
@article.abstract = ["My Abstract", "two"]
|
58
|
+
@article.abstract.should == ["My Abstract", 'two']
|
45
59
|
end
|
46
60
|
|
47
|
-
|
61
|
+
it "should delegate all methods (i.e. to_s, first, etc.) to the found array" do
|
62
|
+
@article.person.last_name.to_s.should == ["FAMILY NAME", "Gautama"].to_s
|
63
|
+
@article.person.last_name.first.should == "FAMILY NAME"
|
64
|
+
end
|
48
65
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
66
|
+
it "should delegate with blocks to the found array" do
|
67
|
+
arr = []
|
68
|
+
@article.person.last_name.each{|x| arr << x}
|
69
|
+
arr.should == ["FAMILY NAME", "Gautama"]
|
70
|
+
end
|
55
71
|
|
56
|
-
it "should not find elements that don't exist" do
|
57
|
-
lambda {@article.name.hedgehog}.should raise_exception NoMethodError
|
58
|
-
end
|
59
72
|
|
60
|
-
|
61
|
-
|
62
|
-
|
73
|
+
describe "setting attributes" do
|
74
|
+
it "when they exist" do
|
75
|
+
@article.title_info(0).main_title.main_title_lang = "ger"
|
76
|
+
@article.title_info(0).main_title.main_title_lang.should == ["ger"]
|
77
|
+
end
|
78
|
+
it "when they don't exist" do
|
79
|
+
title = @article.title_info(0)
|
80
|
+
title.language = "rus"
|
81
|
+
@article.title_info(0).language.should == ["rus"]
|
82
|
+
end
|
63
83
|
|
64
|
-
|
65
|
-
@article.title.should == ["ARTICLE TITLE HYDRANGEA ARTICLE 1", "Artikkelin otsikko Hydrangea artiklan 1", "TITLE OF HOST JOURNAL"]
|
66
|
-
@article.title.main_title_lang.should == ['eng']
|
84
|
+
end
|
67
85
|
|
68
|
-
|
86
|
+
it "should find elements two deep" do
|
87
|
+
#TODO reimplement so that method_missing with name is only called once. Create a new method for name.
|
88
|
+
@article.name.name_content.val.should == ["Describes a person"]
|
89
|
+
@article.name.name_content.should == ["Describes a person"]
|
90
|
+
@article.name.name_content(0).should == ["Describes a person"]
|
91
|
+
end
|
69
92
|
|
70
|
-
|
71
|
-
|
72
|
-
|
93
|
+
it "should not find elements that don't exist" do
|
94
|
+
lambda {@article.name.hedgehog}.should raise_exception NoMethodError
|
95
|
+
end
|
73
96
|
|
74
|
-
|
75
|
-
|
97
|
+
it "should allow you to call methods on the return value" do
|
98
|
+
@article.name.name_content.first.should == "Describes a person"
|
99
|
+
end
|
76
100
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
@article.journal(0).issue(1).pages.length.should == 1
|
81
|
-
@article.journal(0).issue(1).pages.start.length.should == 1
|
82
|
-
@article.journal(0).issue(1).pages.start.first.should == "434"
|
101
|
+
it "Should work with proxies" do
|
102
|
+
@article.title.should == ["ARTICLE TITLE HYDRANGEA ARTICLE 1", "Artikkelin otsikko Hydrangea artiklan 1", "TITLE OF HOST JOURNAL"]
|
103
|
+
@article.title.main_title_lang.should == ['eng']
|
83
104
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
105
|
+
@article.title(1).to_pointer.should == [{:title => 1}]
|
106
|
+
|
107
|
+
@article.journal_title.xpath.should == "//oxns:relatedItem[@type=\"host\"]/oxns:titleInfo/oxns:title"
|
108
|
+
@article.journal_title.should == ["TITLE OF HOST JOURNAL"]
|
109
|
+
end
|
110
|
+
|
111
|
+
it "Should be addressable to a specific node" do
|
90
112
|
@article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>{"0"=>"434"} })
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
113
|
+
|
114
|
+
@article.subject.topic(1).to_pointer == [:subject, {:topic => 1}]
|
115
|
+
@article.journal(0).issue.length.should == 2
|
116
|
+
@article.journal(0).issue(1).pages.to_pointer == [{:journal=>0}, {:issue=>1}, :pages]
|
117
|
+
@article.journal(0).issue(1).pages.length.should == 1
|
118
|
+
@article.journal(0).issue(1).pages.start.length.should == 1
|
119
|
+
@article.journal(0).issue(1).pages.start.first.should == "434"
|
120
|
+
|
121
|
+
@article.subject.topic(1).should == ["TOPIC 2"]
|
122
|
+
@article.subject.topic(1).xpath.should == "//oxns:subject/oxns:topic[2]"
|
123
|
+
end
|
124
|
+
|
125
|
+
describe ".nodeset" do
|
126
|
+
it "should return a Nokogiri NodeSet" do
|
127
|
+
@article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>{"0"=>"434"} })
|
128
|
+
nodeset = @article.journal(0).issue(1).pages.start.nodeset
|
129
|
+
nodeset.should be_kind_of Nokogiri::XML::NodeSet
|
130
|
+
nodeset.length.should == @article.journal(0).issue(1).pages.start.length
|
131
|
+
nodeset.first.text.should == @article.journal(0).issue(1).pages.start.first
|
132
|
+
end
|
95
133
|
end
|
96
|
-
end
|
97
134
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
135
|
+
it "should append nodes at the specified index if possible, setting dirty to true if the object responds to dirty" do
|
136
|
+
@article.stubs(:respond_to?).with(:dirty=).returns(true)
|
137
|
+
@article.expects(:dirty=).with(true).twice
|
138
|
+
@article.journal.title_info = ["all", "for", "the"]
|
139
|
+
@article.journal.title_info(3, 'glory')
|
140
|
+
@article.term_values(:journal, :title_info).should == ["all", "for", "the", "glory"]
|
141
|
+
end
|
142
|
+
|
104
143
|
end
|
105
|
-
|
106
144
|
end
|
107
145
|
end
|
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.6.0.
|
4
|
+
version: 1.6.0.rc3
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &70192588062320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.4.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70192588062320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mediashelf-loggable
|
27
|
-
requirement: &
|
27
|
+
requirement: &70192588061880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70192588061880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70192588061300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70192588061300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
|
-
requirement: &
|
49
|
+
requirement: &70192588060780 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.9.8
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70192588060780
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: equivalent-xml
|
60
|
-
requirement: &
|
60
|
+
requirement: &70192588060280 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.2.4
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70192588060280
|
69
69
|
description: ! 'OM (Opinionated Metadata): A library to help you tame sprawling XML
|
70
70
|
schemas like MODS. Wraps Nokogiri documents in objects with miscellaneous helper
|
71
71
|
methods for doing things like retrieve generated xpath queries or look up properties
|