xml-mapping_extensions 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36f81c099c7ffafcad6ffa1af533b3a5f9ced684
4
- data.tar.gz: 09a3a094c1855d14b2e3f89d72ba210bc0a7ede1
3
+ metadata.gz: 91ed4292829e9d05dae2299e8d9f79d6e8e668db
4
+ data.tar.gz: 7980a10f39051df33fe45df96b0541d9242fcc00
5
5
  SHA512:
6
- metadata.gz: b94a791a3a778e2e457e177a04c424011b012a422532aebfc9257a97ec08a3866b991a87b13df49f6ef8d65960e22fee4149426897437c5f74131e5b9ef8a14e
7
- data.tar.gz: 247e5a8e25895cdbad0f3bddf62aafdde2dae6f89e77770e86fa22bd05d89741b0d36b342779851e2812cc55c7247e8d424639ce6c8b028fae5dac92e7e9a3b7
6
+ metadata.gz: 2a79811d0aac935feb3e80dfa218d08f84f8d20726c34616dde559ec18c3422501ca6686affa8c8434470efc20b2319efb8765dceff3a829b7a6ce01ed157456
7
+ data.tar.gz: bbfb24c26fa14bebc99d5a6b84290ca1d3d1e9050828a534fa3616710bf6411f0c98e085ed2ab71e55cdb5971380a5e2f3d1d911b11929c3f606a857f1452e2a
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.4.5 (14 July 2016)
2
+
3
+ - Make `#fallback_mapping` preserve the order of the fallback mapping instead of appending all fallback
4
+ nodes after all explicitly remapped nodes
5
+
1
6
  ## 0.4.4 (12 July 2016)
2
7
 
3
8
  - Add '#fallback_mapping'
@@ -88,8 +88,7 @@ module XML
88
88
  # @param fallback [Symbol] the fallback mapping to be used if the primary
89
89
  # mapping lacks a mapping node or root element name
90
90
  def fallback_mapping(mapping, fallback)
91
- mapping_nodes = nodes_by_attrname(mapping)
92
- add_fallback_nodes(mapping_nodes, mapping, fallback)
91
+ mapping_nodes = add_fallback_nodes(nodes_by_attrname(mapping), mapping, fallback)
93
92
  xml_mapping_nodes_hash[mapping] = mapping_nodes.values
94
93
 
95
94
  return if root_element_names[mapping]
@@ -127,14 +126,16 @@ module XML
127
126
  # @param mapping [Symbol] The primary mapping
128
127
  # @param fallback [Symbol] The fallback mapping
129
128
  def add_fallback_nodes(mapping_nodes, mapping, fallback)
130
- xml_mapping_nodes(mapping: fallback).each do |fallback_node|
131
- attrname = fallback_node.attrname
132
- next if mapping_nodes.key?(attrname)
133
-
134
- node = fallback_node.clone
135
- fallback_node.mapping = mapping
136
- mapping_nodes[attrname] = node
137
- end
129
+ all_nodes = nodes_by_attrname(fallback).map do |attrname, fallback_node|
130
+ [attrname, clone_node(fallback_node, mapping)]
131
+ end.to_h
132
+ all_nodes.merge!(mapping_nodes)
133
+ end
134
+
135
+ def clone_node(fallback_node, new_mapping)
136
+ node = fallback_node.clone
137
+ node.mapping = new_mapping
138
+ node
138
139
  end
139
140
  end
140
141
  end
@@ -1,6 +1,6 @@
1
1
  module XML
2
2
  module MappingExtensions
3
3
  # The version of this gem
4
- VERSION = '0.4.4'
4
+ VERSION = '0.4.5'
5
5
  end
6
6
  end
@@ -10,6 +10,7 @@ module XML
10
10
  numeric_node :attribute, '@attribute'
11
11
  text_node :text, 'text()'
12
12
  array_node :children, 'child', class: String
13
+ numeric_node :stepchild, 'stepchild'
13
14
 
14
15
  use_mapping :alternate
15
16
  text_node :attribute, '@attribute'
@@ -22,6 +23,7 @@ module XML
22
23
  children_text = obj.children.join(',') if obj.children && !obj.children.empty?
23
24
  xml.add_element('children').text = children_text if children_text
24
25
  end)
26
+ text_node :stepchild, 'stepchild'
25
27
 
26
28
  fallback_mapping :alternate, :_default
27
29
  end
@@ -32,8 +34,9 @@ module XML
32
34
  obj.attribute = 123
33
35
  obj.text = 'element text'
34
36
  obj.children = ['child 1', 'child 2']
37
+ obj.stepchild = 456
35
38
  saved_xml = obj.save_to_xml
36
- expected_xml = '<element attribute="123">element text<child>child 1</child><child>child 2</child></element>'
39
+ expected_xml = '<element attribute="123">element text<child>child 1</child><child>child 2</child><stepchild>456</stepchild></element>'
37
40
  expect(saved_xml).to be_xml(expected_xml)
38
41
  end
39
42
 
@@ -42,27 +45,30 @@ module XML
42
45
  obj.attribute = 'elvis'
43
46
  obj.text = 'element text'
44
47
  obj.children = ['child 1', 'child 2']
48
+ obj.stepchild = 456
45
49
  saved_xml = obj.save_to_xml(mapping: :alternate)
46
- expected_xml = '<element attribute="elvis">element text<children>child 1,child 2</children></element>'
50
+ expected_xml = '<element attribute="elvis">element text<children>child 1,child 2</children><stepchild>456</stepchild></element>'
47
51
  expect(saved_xml).to be_xml(expected_xml)
48
52
  end
49
53
  end
50
54
 
51
55
  describe '#parse_xml' do
52
56
  it 'parses a String' do
53
- xml_string = '<element attribute="123">element text<child>child 1</child><child>child 2</child></element>'
57
+ xml_string = '<element attribute="123">element text<child>child 1</child><child>child 2</child><stepchild>456</stepchild></element>'
54
58
  obj = FMSpecObject.parse_xml(xml_string)
55
59
  expect(obj.attribute).to eq(123)
56
60
  expect(obj.text).to eq('element text')
57
61
  expect(obj.children).to eq(['child 1', 'child 2'])
62
+ expect(obj.stepchild).to eq(456)
58
63
  end
59
64
 
60
65
  it 'accepts an alternate mapping' do
61
- xml_string = '<element attribute="elvis">element text<children>child 1,child 2</children></element>'
66
+ xml_string = '<element attribute="elvis">element text<children>child 1,child 2</children><stepchild>456</stepchild></element>'
62
67
  obj = FMSpecObject.parse_xml(xml_string, mapping: :alternate)
63
68
  expect(obj.attribute).to eq('elvis')
64
69
  expect(obj.text).to eq('element text')
65
70
  expect(obj.children).to eq(['child 1', 'child 2'])
71
+ expect(obj.stepchild).to eq('456')
66
72
  end
67
73
  end
68
74
 
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.4.4
4
+ version: 0.4.5
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-07-12 00:00:00.000000000 Z
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types