xml-mapping 0.8 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,128 @@
1
+ 2005-12-07 Olaf Klischat
2
+
3
+ * release 0.8.1
4
+
5
+ 2005-12-07 Olaf Klischat
6
+
7
+ * ChangeLog file
8
+
9
+ 2005/11/30 Olaf Klischat
10
+
11
+ * bugfix: clone default values to avoid external modifications
12
+
13
+ 2005/07/07 Olaf Klischat
14
+
15
+ * release 0.8
16
+
17
+ 2005/07/04 Olaf Klischat
18
+
19
+ * xml/xpath / XML::XPath -> xml/xxpath / XML::XXPath, license ->
20
+ Ruby's
21
+
22
+ 2005/06/29 Olaf Klischat
23
+
24
+ * when creating elt[@attr='value'] path elements, add a new
25
+ element if one with @attr='value' already existed
26
+
27
+ 2005/03/30 Olaf Klischat
28
+
29
+ * add_accessor: check for existing accessors.
30
+
31
+ 2005/03/05 Olaf Klischat
32
+
33
+ * better support for inheritance among mapping
34
+ classes
35
+
36
+ 2005/03/03 Olaf Klischat
37
+
38
+ * "polymorphic" nodes via root element
39
+ name. SubObjectBaseNode-based nodes es use node polymorphy when
40
+ no explicit node marshaller/unmarshaller has been sp ecified.
41
+
42
+ 2005/02/28 Olaf Klischat
43
+
44
+ * mapping root elt name => mapping class;
45
+ XML::Mapping::load_object_from_* implemented
46
+
47
+ 2005/02/13 Olaf Klischat
48
+
49
+ * IntNode renamed & generalized to NumericNode
50
+
51
+ 2005/02/12 Olaf Klischat
52
+
53
+ * renaming *_rexml => *_xml
54
+
55
+ 2005/01/27 Olaf Klischat
56
+
57
+ * special exception NoAttrValueSet for indicating absence of a
58
+ specific attribute in an XML source
59
+
60
+ 2005/01/23 Olaf Klischat
61
+
62
+ * some more documentation, Node.obj_initializing, setting node
63
+ values to defaults on initialization
64
+
65
+ 2005/01/10 Olaf Klischat
66
+
67
+ * root_element_name
68
+
69
+ 2005/01/07 Olaf Klischat
70
+
71
+ * refactoring:
72
+
73
+ Made node types (classes) dynamically addable via
74
+ XML::Mapping.add_node_class, xml/mapping.rb moved to
75
+ xml/mapping/base.rb, node types moved to
76
+ xml/mapping/standard_nodes.rb, xml/mapping.rb now requires base
77
+ and standard_nodes and adds all standard node types to
78
+ XML::Mapping.
79
+
80
+ * additional node class SingleAttributeNode < Node for nodes that
81
+ map to a single attribute in their class (that's true for all
82
+ nodes we have so far). Call to add_attribute moved from "core"
83
+ to SingleAttributeNode.initialize.
84
+
85
+ * XML::Mapping: @nodes renamed to @xml_mapping_nodes to minimize
86
+ chance of name clashes.
87
+
88
+ 2004/12/30 Olaf Klischat
89
+
90
+ * array node writing, hash node writing
91
+
92
+
93
+ 2004/12/30 Olaf Klischat
94
+
95
+ * xpath: create_new flag, + convenience method
96
+
97
+ 2004/12/21 Olaf Klischat
98
+
99
+ * node classes
100
+
101
+ 2004/12/20 Olaf Klischat
102
+
103
+ * hash_node
104
+
105
+ 2004/12/08 Olaf Klischat
106
+
107
+ * xpath: attribute nodes
108
+
109
+ * xml_mapping: retargeted from REXML::XPath to XML::XPath
110
+
111
+ 2004/12/02 Olaf Klischat
112
+
113
+ * xpath: write accessors
114
+
115
+ 2004/11/27 Olaf Klischat
116
+
117
+ * xpath: read access seems to work
118
+
119
+ 2004/11/25 Olaf Klischat
120
+
121
+ * array_node
122
+
123
+ stone age Olaf Klischat
124
+
125
+ * see http://rubygarden.org/ruby?XmlMapping
126
+
127
+
128
+
data/Rakefile CHANGED
@@ -168,7 +168,7 @@ spec = Gem::Specification.new do |s|
168
168
  s.files += Dir.glob("{lib,examples,test}/**/*").delete_if do |item|
169
169
  item.include?("CVS") || item =~ /~$/
170
170
  end
171
- s.files += %w{LICENSE Rakefile install.rb}
171
+ s.files += %w{LICENSE Rakefile ChangeLog install.rb}
172
172
  s.extra_rdoc_files = FILES_RDOC_EXTRA
173
173
  s.rdoc_options += %w{--include examples}
174
174
 
@@ -1,11 +1,11 @@
1
1
  c = Company.load_from_file('company.xml')
2
- => #<Company:0x40471c18 @address=#<Address:0x40471344 @zip=10113, @city="Berlin">, @name="ACME inc.", @customers=[#<Customer:0x4046fe90 @name="James Kirk", @id="jim">, #<Customer:0x4046f51c @name="Ernie", @id="ernie">, #<Customer:0x4046eba8 @name="Bert", @id="bert">]>
2
+ => #<Company:0x312dc8 @customers=[#<Customer:0x310bd8 @name="James Kirk", @id="jim">, #<Customer:0x310200 @name="Ernie", @id="ernie">, #<Customer:0x30f7f8 @name="Bert", @id="bert">], @address=#<Address:0x3123d8 @zip=10113, @city="Berlin">, @name="ACME inc.">
3
3
  c.name
4
4
  => "ACME inc."
5
5
  c.customers.size
6
6
  => 3
7
7
  c.customers[1]
8
- => #<Customer:0x4046f51c @name="Ernie", @id="ernie">
8
+ => #<Customer:0x310200 @name="Ernie", @id="ernie">
9
9
  c.customers[1].name
10
10
  => "Ernie"
11
11
  c.customers[0].name
@@ -13,7 +13,7 @@ c.customers[0].name
13
13
  c.customers[0].name = 'James Tiberius Kirk'
14
14
  => "James Tiberius Kirk"
15
15
  c.customers << Customer.new('cm','Cookie Monster')
16
- => [#<Customer:0x4046fe90 @name="James Tiberius Kirk", @id="jim">, #<Customer:0x4046f51c @name="Ernie", @id="ernie">, #<Customer:0x4046eba8 @name="Bert", @id="bert">, #<Customer:0x4046d7a8 @name="Cookie Monster", @id="cm">]
16
+ => [#<Customer:0x310bd8 @name="James Tiberius Kirk", @id="jim">, #<Customer:0x310200 @name="Ernie", @id="ernie">, #<Customer:0x30f7f8 @name="Bert", @id="bert">, #<Customer:0x30e118 @name="Cookie Monster", @id="cm">]
17
17
  xml2 = c.save_to_xml
18
18
  => <company name='ACME inc.'> ... </>
19
19
  xml2.write($stdout,2)
@@ -23,16 +23,16 @@ xml2.write($stdout,2)
23
23
  <zip>10113</zip>
24
24
  </address>
25
25
  <customers>
26
- <customer id='539197256'>
26
+ <customer id='1607148'>
27
27
  <name>James Tiberius Kirk</name>
28
28
  </customer>
29
- <customer id='539196046'>
29
+ <customer id='1605888'>
30
30
  <name>Ernie</name>
31
31
  </customer>
32
- <customer id='539194836'>
32
+ <customer id='1604604'>
33
33
  <name>Bert</name>
34
34
  </customer>
35
- <customer id='539192276'>
35
+ <customer id='1601676'>
36
36
  <name>Cookie Monster</name>
37
37
  </customer>
38
38
  </customers>
@@ -1,9 +1,9 @@
1
1
  s=Signature.load_from_file("order_signature_enhanced.xml")
2
- => #<Signature:0x40476344 @name="John Doe", @signed_on=Sun Feb 13 00:00:00 CET 2005, @position="product manager">
2
+ => #<Signature:0x1aed60 @signed_on=Sun Feb 13 00:00:00 MET 2005, @name="John Doe", @position="product manager">
3
3
  s.signed_on
4
- => Sun Feb 13 00:00:00 CET 2005
4
+ => Sun Feb 13 00:00:00 MET 2005
5
5
  s.signed_on=Time.local(1976,12,18)
6
- => Sat Dec 18 00:00:00 CET 1976
6
+ => Sat Dec 18 00:00:00 MET 1976
7
7
  s.save_to_xml.write($stdout,2)
8
8
  <signature>
9
9
  <Name>John Doe</Name>
@@ -1,10 +1,10 @@
1
1
  ####read access
2
2
  o=Order.load_from_file("order.xml")
3
- => #<Order:0x40441590 @signatures=[#<Signature:0x40436fc8 @name="John Doe", @position="product manager">, #<Signature:0x404363ac @name="Jill Smith", @position="clerk">, #<Signature:0x40435790 @name="Miles O'Brien", @position="Some Employee">], @items={"RF-3341"=>#<Item:0x40438f58 @unit_price=0.85, @quantity=30, @descr="Cookie">, "RF-0034"=>#<Item:0x4043a7a4 @unit_price=28.5, @quantity=5, @descr="Chocolate">, "RF-0001"=>#<Item:0x4043bff0 @unit_price=8.95, @quantity=10, @descr="Stuffed Penguin">}, @client=#<Client:0x40440be0 @name="Jean Smith", @work_address=#<Address:0x4043e05c @street="98765, Fulton Street", @zip=94102, @state="CA", @city="San Francisco">, @home_address=#<Address:0x4043ff10 @street="2000, Alameda de las Pulgas", @zip=94403, @state="CA", @city="San Mateo">>, @reference="12343-AHSHE-314159">
3
+ => #<Order:0x404730 @items={"RF-3341"=>#<Item:0x3f7fb0 @unit_price=0.85, @quantity=30, @descr="Cookie">, "RF-0034"=>#<Item:0x3faa70 @unit_price=28.5, @quantity=5, @descr="Chocolate">, "RF-0001"=>#<Item:0x3fcfa8 @unit_price=8.95, @quantity=10, @descr="Stuffed Penguin">}, @signatures=[#<Signature:0x3f4878 @name="John Doe", @position="product manager">, #<Signature:0x3f38d0 @name="Jill Smith", @position="clerk">, #<Signature:0x3f23a0 @name="Miles O'Brien", @position="Some Employee">], @client=#<Client:0x403a70 @work_address=#<Address:0x3ffbb8 @street="98765, Fulton Street", @state="CA", @zip=94102, @city="San Francisco">, @name="Jean Smith", @home_address=#<Address:0x402450 @street="2000, Alameda de las Pulgas", @state="CA", @zip=94403, @city="San Mateo">>, @reference="12343-AHSHE-314159">
4
4
  o.reference
5
5
  => "12343-AHSHE-314159"
6
6
  o.client
7
- => #<Client:0x40440be0 @name="Jean Smith", @work_address=#<Address:0x4043e05c @street="98765, Fulton Street", @zip=94102, @state="CA", @city="San Francisco">, @home_address=#<Address:0x4043ff10 @street="2000, Alameda de las Pulgas", @zip=94403, @state="CA", @city="San Mateo">>
7
+ => #<Client:0x403a70 @work_address=#<Address:0x3ffbb8 @street="98765, Fulton Street", @state="CA", @zip=94102, @city="San Francisco">, @name="Jean Smith", @home_address=#<Address:0x402450 @street="2000, Alameda de las Pulgas", @state="CA", @zip=94403, @city="San Mateo">>
8
8
  o.items.keys
9
9
  => ["RF-3341", "RF-0034", "RF-0001"]
10
10
  o.items["RF-0034"].descr
@@ -12,7 +12,7 @@ o.items["RF-0034"].descr
12
12
  o.items["RF-0034"].total_price
13
13
  => 142.5
14
14
  o.signatures
15
- => [#<Signature:0x40436fc8 @name="John Doe", @position="product manager">, #<Signature:0x404363ac @name="Jill Smith", @position="clerk">, #<Signature:0x40435790 @name="Miles O'Brien", @position="Some Employee">]
15
+ => [#<Signature:0x3f4878 @name="John Doe", @position="product manager">, #<Signature:0x3f38d0 @name="Jill Smith", @position="clerk">, #<Signature:0x3f23a0 @name="Miles O'Brien", @position="Some Employee">]
16
16
  o.signatures[2].name
17
17
  => "Miles O'Brien"
18
18
  o.signatures[2].position
@@ -92,13 +92,13 @@ xml.write($stdout,2)
92
92
  </order>
93
93
  ####Starting a new order from scratch
94
94
  o = Order.new
95
- => #<Order:0x4053a014 @signatures=[]>
95
+ => #<Order:0x3b5500 @signatures=[]>
96
96
  ## attributes with default values (here: signatures) are set
97
97
  ## automatically
98
98
 
99
99
  xml=o.save_to_xml
100
100
  XML::MappingError: no value, and no default value, for attribute: reference
101
- from ../lib/xml/../xml/mapping/base.rb:377:in `obj_to_xml'
101
+ from ../lib/xml/../xml/mapping/base.rb:381:in `obj_to_xml'
102
102
  from ../lib/xml/../xml/mapping/base.rb:157:in `fill_into_xml'
103
103
  from ../lib/xml/../xml/mapping/base.rb:156:in `each'
104
104
  from ../lib/xml/../xml/mapping/base.rb:156:in `fill_into_xml'
@@ -15,9 +15,9 @@ nowxml=Time.now.save_to_xml
15
15
  nowxml.write($stdout,2)
16
16
  <time>
17
17
  <year>2005</year>
18
- <month>7</month>
18
+ <month>12</month>
19
19
  <mday>7</mday>
20
- <hours>6</hours>
21
- <minutes>10</minutes>
22
- <seconds>49</seconds>
20
+ <hours>20</hours>
21
+ <minutes>52</minutes>
22
+ <seconds>4</seconds>
23
23
  </time>
@@ -58,7 +58,7 @@ firstbazelt=XML::XXPath.new("/bar/baz").first(rootelt)
58
58
  path2=XML::XXPath.new("@key2")
59
59
 
60
60
  path2.create_new(firstbazelt)
61
- => #<XML::XXPath::Accessors::Attribute:0x404b0c4c @name="key2", @parent=<baz key2='[unset]' key='work'> ... </>>
61
+ => #<XML::XXPath::Accessors::Attribute:0x314bf8 @parent=<baz key2='[unset]' key='work'> ... </>, @name="key2">
62
62
  d.write($stdout,2)
63
63
  <foo>
64
64
  <bar>
@@ -81,7 +81,7 @@ d.write($stdout,2)
81
81
  ### no change
82
82
 
83
83
  XML::XXPath.new("/bar/baz[6]/@haha").first(rootelt,:ensure_created=>true)
84
- => #<XML::XXPath::Accessors::Attribute:0x404d5ce0 @name="haha", @parent=<baz haha='[unset]'/>>
84
+ => #<XML::XXPath::Accessors::Attribute:0x3223b0 @parent=<baz haha='[unset]'/>, @name="haha">
85
85
  d.write($stdout,2)
86
86
  <foo>
87
87
  <bar>
@@ -97,7 +97,7 @@ d.write($stdout,2)
97
97
  ### for there to be a 6th "baz" element, there must be 1st..5th "baz" elements
98
98
 
99
99
  XML::XXPath.new("/bar/baz[6]/@haha").first(rootelt,:ensure_created=>true)
100
- => #<XML::XXPath::Accessors::Attribute:0x404d086c @name="haha", @parent=<baz haha='[unset]'/>>
100
+ => #<XML::XXPath::Accessors::Attribute:0x31f830 @parent=<baz haha='[unset]'/>, @name="haha">
101
101
  d.write($stdout,2)
102
102
  <foo>
103
103
  <bar>
@@ -350,7 +350,11 @@ module XML
350
350
  unless @options.has_key? :default_value
351
351
  raise XML::MappingError, "no value, and no default value: #{err}"
352
352
  end
353
- obj.send :"#{@attrname}=", @options[:default_value]
353
+ begin
354
+ obj.send :"#{@attrname}=", @options[:default_value].clone
355
+ rescue
356
+ obj.send :"#{@attrname}=", @options[:default_value]
357
+ end
354
358
  end
355
359
  end
356
360
 
@@ -386,7 +390,11 @@ module XML
386
390
  end
387
391
  def obj_initializing(obj) # :nodoc:
388
392
  if @options.has_key? :default_value
389
- obj.send :"#{@attrname}=", @options[:default_value]
393
+ begin
394
+ obj.send :"#{@attrname}=", @options[:default_value].clone
395
+ rescue
396
+ obj.send :"#{@attrname}=", @options[:default_value]
397
+ end
390
398
  end
391
399
  end
392
400
  # utility method to be used by implementations of
@@ -3,6 +3,6 @@
3
3
 
4
4
  module XML
5
5
  module Mapping
6
- VERSION = '0.8'
6
+ VERSION = '0.8.1'
7
7
  end
8
8
  end
@@ -21,6 +21,8 @@ class Company
21
21
  text_node :ent3, "arrtest/entry[3]"
22
22
 
23
23
  array_node :stuff, "stuff", "*"
24
+
25
+ object_node :test_default_value_identity, "dummy", :default_value => ["default"]
24
26
  end
25
27
 
26
28
 
@@ -165,6 +165,25 @@ class XmlMappingTest < Test::Unit::TestCase
165
165
  end
166
166
 
167
167
 
168
+ def test_default_value_identity_on_initialize
169
+ c = Company.new
170
+ assert_equal ["default"], c.test_default_value_identity
171
+ c.test_default_value_identity << "foo"
172
+
173
+ c2 = Company.new
174
+ assert_equal ["default"], c2.test_default_value_identity
175
+ end
176
+
177
+
178
+ def test_default_value_identity_on_load
179
+ assert_equal ["default"], @c.test_default_value_identity
180
+ @c.test_default_value_identity << "bar"
181
+
182
+ c2 = Company.load_from_file(File.dirname(__FILE__) + "/fixtures/company1.xml")
183
+ assert_equal ["default"], c2.test_default_value_identity
184
+ end
185
+
186
+
168
187
  def test_polymorphic_node
169
188
  assert_equal 3, @c.stuff.size
170
189
  assert_equal 'Saddam Hussein', @c.stuff[0].name
metadata CHANGED
@@ -1,12 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.4
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: xml-mapping
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.8"
7
- date: 2005-07-07
8
- summary: "An easy to use, extensible library for mapping Ruby objects to XML and back.
9
- Includes an XPath interpreter."
6
+ version: 0.8.1
7
+ date: 2005-12-07 00:00:00 +01:00
8
+ summary: "An easy to use, extensible library for mapping Ruby objects to XML and back. Includes an XPath interpreter."
10
9
  require_paths:
11
10
  - lib
12
11
  email: klischat@cs.tu-berlin.de
@@ -25,6 +24,8 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
24
  version: 0.0.0
26
25
  version:
27
26
  platform: ruby
27
+ signing_key:
28
+ cert_chain:
28
29
  authors:
29
30
  - Olaf Klischat
30
31
  files:
@@ -36,40 +37,41 @@ files:
36
37
  - lib/xml/mapping
37
38
  - lib/xml/mapping.rb
38
39
  - lib/xml/xxpath.rb
39
- - lib/xml/mapping/version.rb
40
+ - lib/xml/xxpath
40
41
  - lib/xml/mapping/base.rb
42
+ - lib/xml/mapping/version.rb
41
43
  - lib/xml/mapping/standard_nodes.rb
42
- - examples/time_augm.intout
43
- - examples/company.rb
44
44
  - examples/company.xml
45
+ - examples/company.rb
46
+ - examples/order_signature_enhanced.rb
45
47
  - examples/company_usage.intin.rb
46
48
  - examples/order.rb
47
49
  - examples/order.xml
48
- - examples/order_signature_enhanced.rb
50
+ - examples/company_usage.intout
49
51
  - examples/order_signature_enhanced.xml
50
- - examples/order_signature_enhanced_usage.intin.rb
51
52
  - examples/order_usage.intin.rb
52
- - examples/time_augm.intin.rb
53
53
  - examples/time_node.rb
54
+ - examples/order_signature_enhanced_usage.intin.rb
55
+ - examples/time_augm.intin.rb
54
56
  - examples/xpath_create_new.intin.rb
55
57
  - examples/xpath_docvsroot.intin.rb
56
58
  - examples/xpath_ensure_created.intin.rb
57
59
  - examples/xpath_pathological.intin.rb
58
60
  - examples/xpath_usage.intin.rb
59
- - examples/company_usage.intout
61
+ - examples/order_usage.intout
62
+ - examples/time_augm.intout
60
63
  - examples/xpath_usage.intout
61
64
  - examples/xpath_ensure_created.intout
62
65
  - examples/xpath_create_new.intout
63
66
  - examples/xpath_pathological.intout
64
67
  - examples/xpath_docvsroot.intout
65
68
  - examples/order_signature_enhanced_usage.intout
66
- - examples/order_usage.intout
67
- - test/fixtures
68
69
  - test/all_tests.rb
69
70
  - test/company.rb
71
+ - test/tests_init.rb
72
+ - test/fixtures
70
73
  - test/documents_folders.rb
71
74
  - test/multiple_mappings.rb
72
- - test/tests_init.rb
73
75
  - test/xml_mapping_adv_test.rb
74
76
  - test/xml_mapping_test.rb
75
77
  - test/xpath_test.rb
@@ -79,6 +81,7 @@ files:
79
81
  - test/fixtures/documents_folders2.xml
80
82
  - LICENSE
81
83
  - Rakefile
84
+ - ChangeLog
82
85
  - install.rb
83
86
  test_files:
84
87
  - test/all_tests.rb