xml-mapping_extensions 0.3.6 → 0.3.7
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/.yardopts +3 -1
- data/CHANGES.md +6 -0
- data/lib/xml/mapping_extensions/namespace.rb +25 -5
- data/lib/xml/mapping_extensions/version.rb +1 -1
- data/spec/unit/xml/mapping_extensions/mapping_extensions_spec.rb +0 -2
- data/spec/unit/xml/mapping_extensions/namespace_spec.rb +77 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50ceab85aed6813c2835984fc59ece8806dcbd31
|
4
|
+
data.tar.gz: aa7f145312c0a7c7fb97ba40f5620c1ad58b267c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9c052d3e34068555752d3a52a811d9710a4927611df2b7b3102eb29a406fc612f390c038e21510dcc470d1f9b4461749db57968a2585f024a82b9534f49fead
|
7
|
+
data.tar.gz: 43c32627ebebed41055496cc0807a536549a7acc5553afc8848cde3baf1f0b800e6e1480ea956c2c9e649212091da7d37bb6168cf14e0aa2a7a3d33782e0f343
|
data/.yardopts
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.3.7 (13 May 2016)
|
2
|
+
|
3
|
+
- Made `Namespace#schema_location` optional.
|
4
|
+
- Added `Namespace#to_s` to improve log and debug output.
|
5
|
+
- Added hashing and equality to `Namespace`.
|
6
|
+
|
1
7
|
## 0.3.6 (2 May 2016)
|
2
8
|
|
3
9
|
- Added `XML::MappingExtensions::Namespace`, with corresponding extension module
|
@@ -12,17 +12,17 @@ module XML
|
|
12
12
|
# @return [String, nil] the namespace prefix
|
13
13
|
attr_reader :prefix
|
14
14
|
|
15
|
-
# @return [String] the schema location URI(s), as a space-separated string list
|
15
|
+
# @return [String, nil] the schema location URI(s), as a space-separated string list
|
16
16
|
attr_reader :schema_location
|
17
17
|
|
18
18
|
# Creates a new {Namespace}
|
19
19
|
# @param uri [URI, String] the namespace URI
|
20
20
|
# @param prefix [String, nil] the namespace prefix
|
21
|
-
# @param schema_location [String] the schema location(s)
|
22
|
-
def initialize(uri:, prefix: nil, schema_location:)
|
21
|
+
# @param schema_location [String, nil] the schema location(s)
|
22
|
+
def initialize(uri:, prefix: nil, schema_location: nil)
|
23
23
|
@uri = uri.to_s
|
24
24
|
@prefix = prefix
|
25
|
-
@schema_location = schema_location
|
25
|
+
@schema_location = schema_location
|
26
26
|
end
|
27
27
|
|
28
28
|
# Sets `uri` as the default (no-prefix) namespace on `elem`, with
|
@@ -30,6 +30,8 @@ module XML
|
|
30
30
|
# @param elem [REXML::Element] The element to set the namespace on
|
31
31
|
def set_default_namespace(elem) # rubocop:disable Style/AccessorMethodName
|
32
32
|
elem.add_namespace(uri)
|
33
|
+
return unless schema_location
|
34
|
+
# TODO: Figure out xsi:noNamespaceSchemaLocation
|
33
35
|
elem.add_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance')
|
34
36
|
elem.add_attribute('xsi:schemaLocation', schema_location)
|
35
37
|
end
|
@@ -44,7 +46,24 @@ module XML
|
|
44
46
|
root.add_namespace(prefix, uri)
|
45
47
|
end
|
46
48
|
|
47
|
-
|
49
|
+
def to_s
|
50
|
+
"Namespace(uri: #{uri}, prefix: #{prefix || 'nil'}, schema_location: #{schema_location || 'nil'}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def ==(other)
|
54
|
+
other.class == self.class && other.state == state
|
55
|
+
end
|
56
|
+
|
57
|
+
alias_method :eql?, :==
|
58
|
+
|
59
|
+
def hash
|
60
|
+
state.hash
|
61
|
+
end
|
62
|
+
|
63
|
+
def state
|
64
|
+
[uri, prefix, schema_location]
|
65
|
+
end
|
66
|
+
protected :state
|
48
67
|
|
49
68
|
def set_prefix_recursive(elem) # rubocop:disable Style/AccessorMethodName
|
50
69
|
return unless elem.namespace == uri
|
@@ -52,6 +71,7 @@ module XML
|
|
52
71
|
elem.name = "#{prefix}:#{elem.name}"
|
53
72
|
elem.each_element { |e| set_prefix_recursive(e) }
|
54
73
|
end
|
74
|
+
private :set_prefix_recursive
|
55
75
|
end
|
56
76
|
end
|
57
77
|
|
@@ -56,7 +56,6 @@ module XML
|
|
56
56
|
expected = "<px:element #{namespace_attribs} attribute='123'>element text<px:child>child 1</px:child><px:child>child 2</px:child></px:element>"
|
57
57
|
|
58
58
|
expect(obj.save_to_xml).to be_xml(expected)
|
59
|
-
puts(obj.write_xml)
|
60
59
|
end
|
61
60
|
|
62
61
|
it 'works without prefixes' do
|
@@ -74,7 +73,6 @@ module XML
|
|
74
73
|
expected = "<element #{namespace_attribs} attribute='123'>element text<child>child 1</child><child>child 2</child></element>"
|
75
74
|
|
76
75
|
expect(obj.save_to_xml).to be_xml(expected)
|
77
|
-
puts(obj.write_xml)
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
@@ -6,6 +6,9 @@ module XML
|
|
6
6
|
describe '#set_default_namespace' do
|
7
7
|
it 'sets the default namespace'
|
8
8
|
it 'sets the schema location'
|
9
|
+
it 'allows a nil schema location'
|
10
|
+
it 'sets the no-namespace schema location'
|
11
|
+
it 'allows a nil no-namespace schema location'
|
9
12
|
end
|
10
13
|
|
11
14
|
describe '#set_prefix' do
|
@@ -13,6 +16,80 @@ module XML
|
|
13
16
|
it 'clears the no-prefix namespace, if previously present'
|
14
17
|
it 'leaves an unrelated no-prefix namespace intact'
|
15
18
|
end
|
19
|
+
|
20
|
+
describe '#to_s' do
|
21
|
+
it 'includes the prefix, namespace, and schema location' do
|
22
|
+
uri = 'http://example.org/px/'
|
23
|
+
prefix = 'px'
|
24
|
+
schema_location = 'http://example.org/px.xsd'
|
25
|
+
namespace = Namespace.new(uri: uri, prefix: prefix, schema_location: schema_location)
|
26
|
+
expect(namespace.to_s).to match(/Namespace.*#{uri}.*#{prefix}.*#{schema_location}/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'accepts a nil prefix' do
|
30
|
+
uri = 'http://example.org/px/'
|
31
|
+
schema_location = 'http://example.org/px.xsd'
|
32
|
+
namespace = Namespace.new(uri: uri, schema_location: schema_location)
|
33
|
+
expect(namespace.to_s).to match(/Namespace.*#{uri}.*nil.*#{schema_location}/)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'accepts a nil schema_location' do
|
37
|
+
uri = 'http://example.org/px/'
|
38
|
+
prefix = 'px'
|
39
|
+
namespace = Namespace.new(uri: uri, prefix: prefix)
|
40
|
+
expect(namespace.to_s).to match(/Namespace.*#{uri}.*#{prefix}.*nil/)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'equality' do
|
45
|
+
describe 'equal objects' do
|
46
|
+
before(:each) do
|
47
|
+
@ns1 = Namespace.new(uri: 'http://example.org/px/', prefix: 'px', schema_location: 'http://example.org/px.xsd')
|
48
|
+
@ns2 = Namespace.new(uri: 'http://example.org/px/', prefix: 'px', schema_location: 'http://example.org/px.xsd')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'are equal' do
|
52
|
+
expect(@ns1).to eq(@ns2)
|
53
|
+
expect(@ns2).to eq(@ns1)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'have the same hash code' do
|
57
|
+
expect(@ns1.hash).to eq(@ns2.hash)
|
58
|
+
expect(@ns2.hash).to eq(@ns1.hash)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'unequal objects' do
|
63
|
+
before(:each) do
|
64
|
+
@nss = [
|
65
|
+
Namespace.new(uri: 'http://example.org/px/', prefix: 'px', schema_location: 'http://example.org/px.xsd'),
|
66
|
+
Namespace.new(uri: 'http://example.com/px/', prefix: 'px', schema_location: 'http://example.org/px.xsd'),
|
67
|
+
Namespace.new(uri: 'http://example.org/px/', prefix: 'px', schema_location: 'http://example.com/px.xsd'),
|
68
|
+
Namespace.new(uri: 'http://example.org/px/', prefix: 'px2', schema_location: 'http://example.org/px.xsd'),
|
69
|
+
Namespace.new(uri: 'http://example.org/px/', schema_location: 'http://example.org/px.xsd'),
|
70
|
+
Namespace.new(uri: 'http://example.org/px/', prefix: 'px')
|
71
|
+
]
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'are unequal' do
|
75
|
+
@nss.each do |ns1|
|
76
|
+
@nss.each do |ns2|
|
77
|
+
next if ns1.equal?(ns2)
|
78
|
+
expect(ns1).not_to eq(ns2)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'have different hash codes' do
|
84
|
+
@nss.each do |ns1|
|
85
|
+
@nss.each do |ns2|
|
86
|
+
next if ns1.equal?(ns2)
|
87
|
+
expect(ns1.hash).not_to eq(ns2.hash)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
16
93
|
end
|
17
94
|
end
|
18
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml-mapping_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|