xml-mapping_extensions 0.4.6 → 0.4.7

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: c4e7ef0d9b37dd1ecc3569d5aeadb75a9da079b1
4
- data.tar.gz: 59a93fa0fa398f3ea4d493c7751f93e3ae34c9de
3
+ metadata.gz: 80244c4ebbcf9f398b53a71edff5b5ec7c884fc5
4
+ data.tar.gz: 55fc77d2fba3a0a5e701e2328d076cd173f854bc
5
5
  SHA512:
6
- metadata.gz: de2478465f7e44829e949505834d290274466d43d643bab3f8cef180fe35e7db1fd3c4ad0a1a07a022b818c5e5d84fb15f108c8a01eb1e58157dc27abaeec8a9
7
- data.tar.gz: 19a67e611dfaf5ae7a8b509598faaa0c84546f0f5a98a3f27058f26cef646c278642b8e39a73a844eaa9a3eaf798698ac95bda6158737816fab92d7a0ba52234
6
+ metadata.gz: 7b1388133c111c18d26a5e4509a12a8ac99e225886164b07e42ab203313c1cae64076b946157252ad0b0ebcd795a84459387c5fa437920d6fa337ce1317c9ca7
7
+ data.tar.gz: a75557813d6716fce717f2a163afce686830b937a0c544dec915e3d6c96b5dee25415ec869c551ea9def763e0158d8b354cc3ef3edae2ecbb20e74c2484cb205
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.7 (21 September 2016)
2
+
3
+ - Fix issue where `ArrayNodes` with `fallback_mapping` wouldn't honor the new mapping.
4
+
1
5
  ## 0.4.6 (15 August 2016)
2
6
 
3
7
  - `TypesafeEnumNode.to_value()` now raises `ArgumentError` if the argument is not a valid value for the node's
@@ -1,6 +1,6 @@
1
1
  module XML
2
2
  module MappingExtensions
3
3
  # The version of this gem
4
- VERSION = '0.4.6'
4
+ VERSION = '0.4.7'
5
5
  end
6
6
  end
@@ -75,6 +75,22 @@ module XML
75
75
  attr_accessor :mapping
76
76
  end
77
77
 
78
+ # Monkey-patch ArrayNode to regenerate marshallers and unmarshallers after cloning
79
+ class ArrayNode
80
+ old_init = instance_method(:initialize)
81
+ define_method(:initialize) do |*args|
82
+ @init_args = args
83
+ old_init.bind(self).call(*args)
84
+ end
85
+
86
+ define_method(:re_initialize) do |args|
87
+ old_init.bind(self).call(*args)
88
+ end
89
+
90
+ attr_reader :init_args
91
+ attr_accessor :options
92
+ end
93
+
78
94
  module ClassMethods
79
95
 
80
96
  # Gets the configured root element names for this object.
@@ -156,6 +172,13 @@ module XML
156
172
  def clone_node(fallback_node, new_mapping)
157
173
  node = fallback_node.clone
158
174
  node.mapping = new_mapping
175
+ if node.is_a?(ArrayNode)
176
+ args = node.init_args.clone
177
+ options = args.pop.clone
178
+ options[:mapping] = new_mapping
179
+ args << options
180
+ node.re_initialize(args)
181
+ end
159
182
  node
160
183
  end
161
184
  end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ module XML
4
+ module Mapping
5
+ class Value
6
+ attr_reader :value
7
+
8
+ def initialize(value:)
9
+ @value = value
10
+ end
11
+ end
12
+
13
+ class ValueNode < SingleAttributeNode
14
+ def initialize(*args)
15
+ path, *args = super(*args)
16
+ @path = ::XML::XXPath.new(path)
17
+ args
18
+ end
19
+
20
+ def set_attr_value(xml, value)
21
+ element = @path.first(xml, ensure_created: true)
22
+ if mapping == :fancy
23
+ element.attributes << REXML::Attribute.new('value', value)
24
+ else
25
+ element.text = value
26
+ end
27
+ end
28
+ end
29
+ XML::Mapping.add_node_class ValueNode
30
+
31
+ class Holder
32
+ include XML::Mapping
33
+
34
+ def initialize(value)
35
+ @value = value
36
+ end
37
+
38
+ value_node :value, 'value', default_value: nil
39
+ use_mapping :fancy
40
+ fallback_mapping :fancy, :_default
41
+ end
42
+
43
+ class HolderHolder
44
+ include XML::Mapping
45
+ array_node :holders, 'holders', 'holder', class: Holder, default_value: []
46
+ use_mapping :fancy
47
+ fallback_mapping :fancy, :_default
48
+ end
49
+
50
+ describe '#fallback_mapping' do
51
+ it 'works with arrays mapped by custom nodes' do
52
+ expected = '<holder-holder>
53
+ <holders>
54
+ <holder><value value="foo"/></holder>
55
+ <holder><value value="bar"/></holder>
56
+ </holders>
57
+ </holder-holder>'
58
+
59
+ hh = HolderHolder.new
60
+ hh.holders = [Holder.new('foo'), Holder.new('bar')]
61
+ xml = hh.write_xml(mapping: :fancy)
62
+ expect(xml).to be_xml(expected)
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -77,7 +77,6 @@ module XML
77
77
  outfile = "#{tmp}/mxspec.xml"
78
78
  @obj.write_to_file(outfile, indent: 4)
79
79
  outxml = File.read(outfile)
80
- puts("'#{outxml}'")
81
80
  expect(outxml).to be_xml(@expected)
82
81
  end
83
82
  end
@@ -87,7 +86,6 @@ module XML
87
86
  outfile = "#{tmp}/mxspec.xml"
88
87
  @obj.write_to_file(outfile, pretty: true)
89
88
  outxml = File.read(outfile)
90
- puts("'#{outxml}'")
91
89
  expect(outxml).to be_xml(@expected)
92
90
  end
93
91
  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.4.6
4
+ version: 0.4.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-08-15 00:00:00.000000000 Z
11
+ date: 2016-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -202,6 +202,7 @@ files:
202
202
  - spec/spec_helper.rb
203
203
  - spec/unit/xml/mapping_extensions/array_node_spec.rb
204
204
  - spec/unit/xml/mapping_extensions/date_node_spec.rb
205
+ - spec/unit/xml/mapping_extensions/fallback_mapping_custom_node_spec.rb
205
206
  - spec/unit/xml/mapping_extensions/fallback_mapping_spec.rb
206
207
  - spec/unit/xml/mapping_extensions/mapping_extensions_spec.rb
207
208
  - spec/unit/xml/mapping_extensions/mime_type_node_spec.rb
@@ -232,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
233
  version: '0'
233
234
  requirements: []
234
235
  rubyforge_project:
235
- rubygems_version: 2.4.5.1
236
+ rubygems_version: 2.6.6
236
237
  signing_key:
237
238
  specification_version: 4
238
239
  summary: Some extensions for for XML::Mapping
@@ -242,6 +243,7 @@ test_files:
242
243
  - spec/spec_helper.rb
243
244
  - spec/unit/xml/mapping_extensions/array_node_spec.rb
244
245
  - spec/unit/xml/mapping_extensions/date_node_spec.rb
246
+ - spec/unit/xml/mapping_extensions/fallback_mapping_custom_node_spec.rb
245
247
  - spec/unit/xml/mapping_extensions/fallback_mapping_spec.rb
246
248
  - spec/unit/xml/mapping_extensions/mapping_extensions_spec.rb
247
249
  - spec/unit/xml/mapping_extensions/mime_type_node_spec.rb