om 3.0.7 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/History.textile +14 -0
- data/lib/om.rb +58 -54
- data/lib/om/version.rb +1 -1
- data/lib/om/xml/term_value_operators.rb +1 -2
- data/lib/om/xml/term_xpath_generator.rb +1 -3
- data/om.gemspec +1 -3
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/document_spec.rb +3 -3
- data/spec/unit/term_spec.rb +6 -4
- data/spec/unit/terminology_spec.rb +4 -4
- data/spec/unit/validation_spec.rb +2 -2
- metadata +4 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 774ca56c42282c5d31bef07b86d7f6e5e54d74b7
|
4
|
+
data.tar.gz: bcf4d74285aa0283c8c4a926e988b5444f0706ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c277df99dae62c250a6747bd05f68aa058477ccec12c03861818880e2ce828f20e21a1203bda0204d088830ecf59b9769caba20929fd0643bd3d28362c38091
|
7
|
+
data.tar.gz: d145e98cd6c1387c58b6c98715d502b5bdb30e970050f0ab75c52c1c7fdb00b23ee83f09fdcf1c70565bd5fb6aecd3ab1794bc86b59d83dc0a2aaa1ed7a0d1a4
|
data/.travis.yml
CHANGED
data/History.textile
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
h3. 3.1.0 (17 Jul 2014)
|
2
|
+
2014-07-17: Bump solrizer version to ~> 3.3 [Justin Coyne]
|
3
|
+
|
4
|
+
2014-07-17: Use the system libxml2 on travis [Justin Coyne]
|
5
|
+
|
6
|
+
2014-07-17: Remove dependency on mediashelf-loggable [Justin Coyne]
|
7
|
+
|
8
|
+
2014-06-13: Setting values on a proxy term should build the parent terms if they
|
9
|
+
don't exist [Justin Coyne]
|
10
|
+
|
11
|
+
2014-06-05: Handle invalid time for Rails 3 [Justin Coyne]
|
12
|
+
|
13
|
+
2014-06-02: Updating solrizer, correcting rspec deprecations [Adam Wead]
|
14
|
+
|
1
15
|
h3. 3.0.1 (25 Jun 2013)
|
2
16
|
Fix bug where values that were the same as the existing values were
|
3
17
|
removed from the update list
|
data/lib/om.rb
CHANGED
@@ -1,69 +1,73 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'active_model'
|
3
|
-
require 'deprecation'
|
4
3
|
require 'nokogiri'
|
4
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
5
5
|
|
6
6
|
module OM
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
mattr_accessor :logger
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# Recursively changes any strings beginning with : to symbols and any number strings to integers
|
11
|
+
# @param [String, Array, Hash] params
|
12
|
+
# @example
|
13
|
+
# [{":person"=>"0"}, ":last_name"] #=> [{:person=>0}, :last_name]
|
14
|
+
def destringify(params)
|
15
|
+
case params
|
16
|
+
when String
|
17
|
+
if params == "0" || params.to_i != 0
|
18
|
+
result = params.to_i
|
19
|
+
elsif params[0,1] == ":"
|
20
|
+
result = params.sub(":","").to_sym
|
21
|
+
else
|
22
|
+
result = params.to_sym
|
23
|
+
end
|
24
|
+
return result
|
25
|
+
when Hash
|
26
|
+
result = {}
|
27
|
+
params.each_pair do |k,v|
|
28
|
+
result[ destringify(k) ] = destringify(v)
|
29
|
+
end
|
30
|
+
return result
|
31
|
+
when Array
|
32
|
+
result = []
|
33
|
+
params.each do |x|
|
34
|
+
result << destringify(x)
|
35
|
+
end
|
36
|
+
return result
|
18
37
|
else
|
19
|
-
|
20
|
-
end
|
21
|
-
return result
|
22
|
-
when Hash
|
23
|
-
result = {}
|
24
|
-
params.each_pair do |k,v|
|
25
|
-
result[ destringify(k) ] = destringify(v)
|
38
|
+
return params
|
26
39
|
end
|
27
|
-
return result
|
28
|
-
when Array
|
29
|
-
result = []
|
30
|
-
params.each do |x|
|
31
|
-
result << destringify(x)
|
32
|
-
end
|
33
|
-
return result
|
34
|
-
else
|
35
|
-
return params
|
36
40
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
41
|
+
|
42
|
+
# Convert a Term pointer into a flat array without Hashes.
|
43
|
+
# If include_indices is set to false, node indices will be removed.
|
44
|
+
#
|
45
|
+
# @param [Array] pointers array that you would pass into other Accessor methods
|
46
|
+
# @param [Boolean] include_indices (default: true) if set to false, parent indices will be excluded from the array
|
47
|
+
# @example Turn a pointer into a flat array with node indices preserved
|
48
|
+
# OM.pointers_to_flat_array( [{:conference=>0}, {:role=>1}, :text] )
|
49
|
+
# => [:conference, 0, :role, 1, :text]
|
50
|
+
# @example Remove node indices by setting include_indices to false
|
51
|
+
# OM.pointers_to_flat_array( [{:conference=>0}, {:role=>1}, :text], false )
|
52
|
+
# => [:conference, :role, :text]
|
53
|
+
def pointers_to_flat_array(pointers, include_indices=true)
|
54
|
+
flat_array = []
|
55
|
+
pointers.each do |pointer|
|
56
|
+
if pointer.kind_of?(Hash)
|
57
|
+
flat_array << pointer.keys.first
|
58
|
+
if include_indices
|
59
|
+
flat_array << pointer.values.first
|
60
|
+
end
|
61
|
+
else
|
62
|
+
flat_array << pointer
|
57
63
|
end
|
58
|
-
else
|
59
|
-
flat_array << pointer
|
60
64
|
end
|
65
|
+
return flat_array
|
61
66
|
end
|
62
|
-
return flat_array
|
63
|
-
end
|
64
67
|
|
65
|
-
|
66
|
-
|
68
|
+
def version
|
69
|
+
Om::VERSION
|
70
|
+
end
|
67
71
|
end
|
68
72
|
|
69
73
|
class TypeMismatch < StandardError; end
|
data/lib/om/version.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "open-uri"
|
2
|
-
require "logger"
|
3
2
|
|
4
3
|
class OM::XML::ParentNodeNotFoundError < RuntimeError; end
|
5
4
|
module OM::XML::TermValueOperators
|
@@ -13,7 +12,7 @@ module OM::XML::TermValueOperators
|
|
13
12
|
find_by_terms(*term_pointer).each {|node| result << (trim_text ? node.text.strip : node.text) }
|
14
13
|
|
15
14
|
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."
|
15
|
+
OM.logger.warn "Passing a xpath to term_values means that OM can not properly find the associated term. Pass a term pointer instead." if OM.logger
|
17
16
|
result
|
18
17
|
else
|
19
18
|
term = self.class.terminology.retrieve_term(*OM.pointers_to_flat_array(OM.destringify(term_pointer), false))
|
@@ -1,6 +1,4 @@
|
|
1
|
-
require 'loggable'
|
2
1
|
module OM::XML::TermXpathGenerator
|
3
|
-
include Loggable
|
4
2
|
|
5
3
|
# Generate relative xpath for a term
|
6
4
|
# @param [OM::XML::Term] term that you want to generate relative xpath for
|
@@ -168,7 +166,7 @@ module OM::XML::TermXpathGenerator
|
|
168
166
|
# If we've encountered a NamedTermProxy, insert path sections corresponding to each entry in its proxy_pointer (rather than just the final term that it points to).
|
169
167
|
# TODO Looks like this only works if the last key is a NamedTermProxy, what if we cross proxies on the way there?
|
170
168
|
if term.kind_of? OM::XML::NamedTermProxy
|
171
|
-
logger.warn "You attempted to call an index value of #{index} on the term \"#{k.inspect}\". However \"#{k.inspect}\" is a proxy so we are ignoring the index. See https://jira.duraspace.org/browse/HYDRA-643" if index
|
169
|
+
OM.logger.warn "You attempted to call an index value of #{index} on the term \"#{k.inspect}\". However \"#{k.inspect}\" is a proxy so we are ignoring the index. See https://jira.duraspace.org/browse/HYDRA-643" if index && OM.logger
|
172
170
|
current_location = term.parent.nil? ? term.terminology : term.parent
|
173
171
|
relative_path = ""
|
174
172
|
term.proxy_pointer.each_with_index do |proxy_pointer, proxy_pointer_index|
|
data/om.gemspec
CHANGED
@@ -16,10 +16,8 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_dependency 'activesupport'
|
18
18
|
s.add_dependency 'activemodel'
|
19
|
-
s.add_dependency 'solrizer', '~> 3.
|
19
|
+
s.add_dependency 'solrizer', '~> 3.3'
|
20
20
|
s.add_dependency('nokogiri', ">= 1.4.2")
|
21
|
-
s.add_dependency('mediashelf-loggable')
|
22
|
-
s.add_dependency('deprecation')
|
23
21
|
s.add_development_dependency "rspec", "~> 2.0"
|
24
22
|
s.add_development_dependency "rake"
|
25
23
|
s.add_development_dependency "yard"
|
data/spec/spec_helper.rb
CHANGED
data/spec/unit/document_spec.rb
CHANGED
@@ -149,13 +149,13 @@ describe "OM::XML::Document" do
|
|
149
149
|
|
150
150
|
describe "node_exists?" do
|
151
151
|
it "should return true if any nodes are found" do
|
152
|
-
@mods_article.node_exists?( {:person=>1}, :first_name).should
|
152
|
+
@mods_article.node_exists?( {:person=>1}, :first_name).should be true
|
153
153
|
end
|
154
154
|
it "should return false if no nodes are found" do
|
155
|
-
@mods_article.node_exists?( {:person=>8}, :first_name ).should
|
155
|
+
@mods_article.node_exists?( {:person=>8}, :first_name ).should be false
|
156
156
|
end
|
157
157
|
it "should support xpath queries" do
|
158
|
-
@mods_article.node_exists?('//oxns:name[@type="personal"][1]/oxns:namePart[1]').should
|
158
|
+
@mods_article.node_exists?('//oxns:name[@type="personal"][1]/oxns:namePart[1]').should be true
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
data/spec/unit/term_spec.rb
CHANGED
@@ -2,12 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe OM::XML::Term do
|
4
4
|
describe "without a type" do
|
5
|
-
|
6
|
-
|
5
|
+
it "should default to string" do
|
6
|
+
OM::XML::Term.new(:test_term).type.should == :string
|
7
|
+
end
|
7
8
|
end
|
8
9
|
describe "when type is specified" do
|
9
|
-
|
10
|
-
|
10
|
+
it "should accept date" do
|
11
|
+
OM::XML::Term.new(:test_term, :type=>:date).type.should == :date
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
describe "a big test" do
|
@@ -195,14 +195,14 @@ describe "OM::XML::Terminology" do
|
|
195
195
|
|
196
196
|
describe ".has_term?" do
|
197
197
|
it "should return true if the specified term does exist in the terminology" do
|
198
|
-
@test_full_terminology.has_term?(:journal,:issue,:end_page).should
|
198
|
+
@test_full_terminology.has_term?(:journal,:issue,:end_page).should be true
|
199
199
|
end
|
200
200
|
it "should support term_pointers with array indexes in them (ignoring the indexes)" do
|
201
|
-
@test_full_terminology.has_term?(:title_info, :main_title).should
|
202
|
-
@test_full_terminology.has_term?({:title_info=>"0"}, :main_title).should
|
201
|
+
@test_full_terminology.has_term?(:title_info, :main_title).should be true
|
202
|
+
@test_full_terminology.has_term?({:title_info=>"0"}, :main_title).should be true
|
203
203
|
end
|
204
204
|
it "should return false if the specified term does not exist in the terminology" do
|
205
|
-
@test_full_terminology.has_term?(:name, :date, :nonexistentTerm, :anotherTermName).should
|
205
|
+
@test_full_terminology.has_term?(:name, :date, :nonexistentTerm, :anotherTermName).should be_falsey
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
@@ -69,8 +69,8 @@ describe "OM::XML::Validation" do
|
|
69
69
|
ValidationTest.send(:file_from_url, "http://google.com")
|
70
70
|
end
|
71
71
|
it "should raise an error if the url is invalid" do
|
72
|
-
lambda {ValidationTest.send(:file_from_url, "")}.should raise_error(RuntimeError,
|
73
|
-
lambda {ValidationTest.send(:file_from_url, "foo")}.should raise_error(RuntimeError,
|
72
|
+
lambda {ValidationTest.send(:file_from_url, "")}.should raise_error(RuntimeError, /Could not retrieve file from /)
|
73
|
+
lambda {ValidationTest.send(:file_from_url, "foo")}.should raise_error(RuntimeError, /Could not retrieve file from foo/)
|
74
74
|
end
|
75
75
|
it "should raise an error if file retrieval fails" do
|
76
76
|
skip "no internet connection"
|
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: 3.0
|
4
|
+
version: 3.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: 2014-
|
12
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 3.
|
48
|
+
version: '3.3'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 3.
|
55
|
+
version: '3.3'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: nokogiri
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,34 +67,6 @@ dependencies:
|
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 1.4.2
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: mediashelf-loggable
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
77
|
-
type: :runtime
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '0'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: deprecation
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '0'
|
91
|
-
type: :runtime
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - ">="
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
98
70
|
- !ruby/object:Gem::Dependency
|
99
71
|
name: rspec
|
100
72
|
requirement: !ruby/object:Gem::Requirement
|