xml-mapping 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +10 -53
  3. data/README.md +57 -0
  4. data/Rakefile +75 -85
  5. data/TODO.txt +12 -2
  6. data/examples/README +4 -4
  7. data/examples/cleanup.rb +11 -0
  8. data/examples/company_usage.intout +7 -7
  9. data/examples/documents_folders_usage.intout +2 -2
  10. data/examples/order_signature_enhanced_usage.intout +3 -3
  11. data/examples/order_usage.intout +26 -26
  12. data/examples/person.intout +3 -3
  13. data/examples/person_mm.intout +2 -2
  14. data/examples/publication.intout +2 -2
  15. data/examples/reader.intout +1 -1
  16. data/examples/stringarray_usage.intout +1 -1
  17. data/examples/time_augm.intout +6 -6
  18. data/examples/xpath_create_new.intout +13 -13
  19. data/examples/xpath_ensure_created.intout +2 -2
  20. data/examples/xpath_usage.intout +1 -1
  21. data/lib/xml/mapping.rb +0 -2
  22. data/lib/xml/mapping/base.rb +24 -9
  23. data/lib/xml/mapping/version.rb +1 -1
  24. data/test/company.rb +43 -0
  25. data/test/documents_folders.rb +7 -0
  26. data/test/multiple_mappings_test.rb +3 -1
  27. data/test/xml_mapping_adv_test.rb +20 -20
  28. data/test/xml_mapping_test.rb +31 -2
  29. data/{README → user_manual.md} +916 -154
  30. data/user_manual_xxpath.md +677 -0
  31. metadata +100 -112
  32. data/ChangeLog +0 -189
  33. data/README_XPATH +0 -202
  34. data/examples/company_usage.intin.rb +0 -19
  35. data/examples/documents_folders_usage.intin.rb +0 -18
  36. data/examples/order_signature_enhanced_usage.intin.rb +0 -12
  37. data/examples/order_usage.intin.rb +0 -120
  38. data/examples/person.intin.rb +0 -44
  39. data/examples/person_mm.intin.rb +0 -119
  40. data/examples/publication.intin.rb +0 -44
  41. data/examples/reader.intin.rb +0 -33
  42. data/examples/stringarray_usage.intin.rb +0 -11
  43. data/examples/time_augm.intin.rb +0 -19
  44. data/examples/time_augm_loading.intin.rb +0 -44
  45. data/examples/time_node.intin.rb +0 -79
  46. data/examples/time_node_w_marshallers.intin.rb +0 -48
  47. data/examples/xpath_create_new.intin.rb +0 -85
  48. data/examples/xpath_docvsroot.intin.rb +0 -30
  49. data/examples/xpath_ensure_created.intin.rb +0 -62
  50. data/examples/xpath_pathological.intin.rb +0 -42
  51. data/examples/xpath_usage.intin.rb +0 -51
  52. data/install.rb +0 -41
  53. data/test/xxpath_benchmark.result1.txt +0 -17
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9fc1ba6799b750d709b7ee01630bf670f8488854
4
+ data.tar.gz: be07c8311cce21655d28124edfed9d18378d4a71
5
+ SHA512:
6
+ metadata.gz: fdec3b02611b85281ed21da509f57e04f4eb5516947ec6c42879fd7381cc020a960245ab9ab7ae683f07a218d24517488a8169c04af2958e94eaf1d647179b46
7
+ data.tar.gz: c13f9e1ccf415ffd0bc4fa7f0faef0c7e9c37f83f1b2916519212de729087a8abd606dcee5b40712ecad5c18e4b362c10504b532b7786c2c562c6f12f640a324
data/LICENSE CHANGED
@@ -1,56 +1,13 @@
1
- Xml-mapping is copyrighted free software by Olaf Klischat
2
- <klischat@cs.tu-berlin.de>. You can redistribute it and/or modify it
3
- under either the terms of the GPL, or the conditions below:
1
+ Copyright 2014 Olaf Klischat
4
2
 
5
- 1. You may make and give away verbatim copies of the source form of the
6
- software without restriction, provided that you duplicate all of the
7
- original copyright notices and associated disclaimers.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
8
6
 
9
- 2. You may modify your copy of the software in any way, provided that
10
- you do at least ONE of the following:
7
+ http://www.apache.org/licenses/LICENSE-2.0
11
8
 
12
- a) place your modifications in the Public Domain or otherwise
13
- make them Freely Available, such as by posting said
14
- modifications to Usenet or an equivalent medium, or by allowing
15
- the author to include your modifications in the software.
16
-
17
- b) use the modified software only within your corporation or
18
- organization.
19
-
20
- c) give non-standard binaries non-standard names, with
21
- instructions on where to get the original software distribution.
22
-
23
- d) make other distribution arrangements with the author.
24
-
25
- 3. You may distribute the software in object code or binary form,
26
- provided that you do at least ONE of the following:
27
-
28
- a) distribute the binaries and library files of the software,
29
- together with instructions (in the manual page or equivalent)
30
- on where to get the original distribution.
31
-
32
- b) accompany the distribution with the machine-readable source of
33
- the software.
34
-
35
- c) give non-standard binaries non-standard names, with
36
- instructions on where to get the original software distribution.
37
-
38
- d) make other distribution arrangements with the author.
39
-
40
- 4. You may modify and include the part of the software into any other
41
- software (possibly commercial). But some files in the distribution
42
- are not written by the author, so that they are not under these terms.
43
-
44
- For the list of those files and their copying conditions, see the
45
- file LEGAL.
46
-
47
- 5. The scripts and library files supplied as input to or produced as
48
- output from the software do not automatically fall under the
49
- copyright of the software, but belong to whomever generated them,
50
- and may be sold commercially, and may be aggregated with this
51
- software.
52
-
53
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
- PURPOSE.
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,57 @@
1
+ # XML-MAPPING: XML-to-object (and back) Mapper for Ruby, including XPath Interpreter
2
+
3
+ Xml-mapping is an easy to use, extensible library that allows you to
4
+ semi-automatically map Ruby objects to XML trees and vice versa.
5
+
6
+
7
+ ## Trivial Example
8
+
9
+ ### sample document
10
+
11
+ <?xml version="1.0" encoding="ISO-8859-1"?>
12
+
13
+ <item reference="RF-0001">
14
+ <Description>Stuffed Penguin</Description>
15
+ <Quantity>10</Quantity>
16
+ <UnitPrice>8.95</UnitPrice>
17
+ </item>
18
+
19
+ ### mapping class
20
+
21
+ class Item
22
+ include XML::Mapping
23
+
24
+ text_node :ref, "@reference"
25
+ text_node :descr, "Description"
26
+ numeric_node :quantity, "Quantity"
27
+ numeric_node :unit_price, "UnitPrice"
28
+
29
+ def total_price
30
+ quantity*unit_price
31
+ end
32
+ end
33
+
34
+
35
+ ### usage
36
+
37
+ i = Item.load_from_file("item.xml")
38
+ => #<Item:0xb7888c90 @ref="RF-0001" @quantity=10, @descr="Stuffed Penguin", @unit_price=8.95>
39
+
40
+ i.unit_price = 42.23
41
+ xml=i.save_to_xml #convert to REXML node; there's also o.save_to_file(name)
42
+ xml.write($stdout,2)
43
+
44
+ <item reference="RF-0001">
45
+ <Description>Stuffed Penguin</Description>
46
+ <Quantity>10</Quantity>
47
+ <UnitPrice>42.23</UnitPrice>
48
+ </item>
49
+
50
+
51
+
52
+ This is the most trivial example -- the mapper supports arbitrary
53
+ array and hash (map) nodes, object (reference) nodes and arrays/hashes
54
+ of those, polymorphic mappings, multiple mappings per class, fully
55
+ programmable mappings and arbitrary user-defined node types. Read the
56
+ [project documentation](http://multi-io.github.io/xml-mapping/
57
+ "Project Page") for more information.
data/Rakefile CHANGED
@@ -1,67 +1,32 @@
1
1
  # -*- ruby -*-
2
2
  # adapted from active_record's Rakefile
3
3
 
4
- require 'build_lib/rdoc_ext'
4
+ $:.unshift "."
5
5
 
6
6
  require 'rubygems'
7
7
  require 'rake'
8
+ require 'rake/clean'
8
9
  require 'rake/testtask'
9
- require 'build_lib/my_rdoctask'
10
+ require 'rdoc/task'
10
11
  require 'rake/packagetask'
11
- require 'rake/gempackagetask'
12
- #require 'rake/contrib/rubyforgepublisher'
12
+ require 'rubygems/package_task'
13
13
  require 'rake/contrib/sshpublisher'
14
14
 
15
15
  require File.dirname(__FILE__)+"/lib/xml/mapping/version"
16
16
 
17
- # yeah -- it's just stupid that these are private
18
-
19
- class Rake::PackageTask
20
- public :tgz_file, :zip_file
21
- end
22
-
23
- class Rake::GemPackageTask
24
- public :gem_file
25
- end
26
-
27
-
28
- FILES_RDOC_EXTRA=%w{README README_XPATH ChangeLog TODO.txt doc/xpath_impl_notes.txt}
29
- FILES_RDOC_INCLUDES=%w{examples/company.xml
30
- examples/company.rb
31
- examples/company_usage.intout
32
- examples/order.xml
33
- examples/order.rb
34
- examples/order_usage.intout
35
- examples/stringarray_usage.intout
36
- examples/stringarray.xml
37
- examples/documents_folders_usage.intout
38
- examples/documents_folders.xml
39
- examples/time_node_w_marshallers.intout
40
- examples/time_node_w_marshallers.xml
41
- examples/time_augm.intout
42
- examples/time_augm_loading.intout
43
- examples/xpath_usage.intout
44
- examples/xpath_ensure_created.intout
45
- examples/xpath_create_new.intout
46
- examples/xpath_pathological.intout
47
- examples/xpath_docvsroot.intout
48
- examples/order_signature_enhanced_usage.intout
49
- examples/order_signature_enhanced.xml
50
- examples/person.intout
51
- examples/publication.intout
52
- examples/reader.intout
53
- examples/person_mm.intout
54
- }
17
+ FILE_RDOC_MAIN = 'user_manual.md'
18
+ FILES_RDOC_EXTRA = [FILE_RDOC_MAIN] + %w{README.md user_manual_xxpath.md TODO.txt doc/xpath_impl_notes.txt}
19
+ FILES_RDOC_INCLUDES=`git ls-files examples`.split("\n").map{|f| f.gsub(/.intin.rb$/, '.intout')}
55
20
 
56
21
 
57
22
  desc "Default Task"
58
23
  task :default => [ :test ]
59
24
 
60
- Rake::TestTask.new(:test) { |t|
25
+ Rake::TestTask.new :test do |t|
61
26
  t.test_files = ["test/all_tests.rb"]
62
27
  t.verbose = true
63
28
  # t.loader = :testrb
64
- }
29
+ end
65
30
 
66
31
  # runs tests only if sources have changed since last succesful run of
67
32
  # tests
@@ -72,19 +37,51 @@ end
72
37
 
73
38
 
74
39
 
75
- MyRDocTask.new { |rdoc|
40
+ RDoc::Task.new do |rdoc|
76
41
  rdoc.rdoc_dir = 'doc/api'
77
42
  rdoc.title = "XML::Mapping -- Simple, extensible Ruby-to-XML (and back) mapper"
78
- rdoc.options += %w{--line-numbers --inline-source --accessor cattr_accessor=object --include examples}
43
+ rdoc.options += %w{--line-numbers --include examples}
44
+ rdoc.main = FILE_RDOC_MAIN
79
45
  rdoc.rdoc_files.include(*FILES_RDOC_EXTRA)
80
46
  rdoc.rdoc_files.include('lib/**/*.rb')
81
47
 
82
48
  # additional file dependencies for the rdoc task
83
49
  # this somewhat of a black art because RDocTask doesn't document the
84
50
  # prerequisite of its rdoc task (<rdoc_dir>/index.html)
85
- file rdoc.rdoc_target => FILES_RDOC_INCLUDES
86
- file "#{rdoc.rdoc_dir}/index.html" => FileList.new("examples/**/*.rb")
87
- }
51
+ file "#{rdoc.rdoc_dir}/index.html" => (FileList.new("examples/**/*.rb") + FILES_RDOC_INCLUDES)
52
+ end
53
+
54
+
55
+ ## need to process :include: statements manually so we can
56
+ ## have the resulting markdown in the gem
57
+ ### can't use a rule (recursion issues)
58
+ %w{user_manual.md user_manual_xxpath.md}.each do |out_name|
59
+ in_name = "#{File.basename(out_name,'.md')}.in.md"
60
+ CLEAN << out_name
61
+ file out_name => in_name do
62
+ begin
63
+ File.open(out_name, "w") do |fout|
64
+ File.open(in_name, "r") do |fin|
65
+ fin.each_line do |l|
66
+ if m=l.match(/:include: (.*)/)
67
+ File.open("examples/#{m[1]}") do |fincluded|
68
+ fincluded.each_line do |linc|
69
+ fout.puts " #{linc}"
70
+ end
71
+ end
72
+ else
73
+ fout.write l
74
+ end
75
+ end
76
+ end
77
+ end
78
+ rescue Exception
79
+ File.delete out_name
80
+ raise
81
+ end
82
+ end
83
+ end
84
+
88
85
 
89
86
  #rule '.intout' => ['.intin.rb', *FileList.new("lib/**/*.rb")] do |task| # doesn't work -- see below
90
87
  rule '.intout' => ['.intin.rb'] do |task|
@@ -100,8 +97,8 @@ rule '.intout' => ['.intin.rb'] do |task|
100
97
  Dir.chdir File.dirname(task.name)
101
98
  fin.read.split("#<=\n").each do |snippet|
102
99
 
103
- snippet.scan(/^#:(.*?):$/) do |(switch,)|
104
- case switch
100
+ snippet.scan(/^#:(.*?):$/) do |switches|
101
+ case switches[0]
105
102
  when "visible"
106
103
  visible=true
107
104
  when "invisible"
@@ -153,6 +150,7 @@ end
153
150
  # have to add additional prerequisites manually because it appears
154
151
  # that rules can only define a single prerequisite :-\
155
152
  FILES_RDOC_INCLUDES.select{|f|f=~/.intout$/}.each do |f|
153
+ CLEAN << f
156
154
  file f => FileList.new("lib/**/*.rb")
157
155
  file f => FileList.new("examples/**/*.rb")
158
156
  end
@@ -168,58 +166,50 @@ spec = Gem::Specification.new do |s|
168
166
  s.name = 'xml-mapping'
169
167
  s.version = XML::Mapping::VERSION
170
168
  s.platform = Gem::Platform::RUBY
171
- s.summary =
172
- "An easy to use, extensible library for mapping Ruby objects to XML and back. Includes an XPath interpreter."
173
-
174
- # Rubygems' RDoc support is incomplete... Can't seem to find a way
175
- # to set the start page, or a set of files that should be includable
176
- # but not processed by rdoc directly
169
+ s.summary = "XML-Object mapper for Ruby"
170
+ s.description =
171
+ "An easy to use, extensible library for semi-automatically mapping Ruby objects to XML and back. Includes an XPath interpreter."
177
172
  s.files += FILES_RDOC_EXTRA
178
- s.files += Dir.glob("{lib,examples,test}/**/*").delete_if do |item|
179
- item.include?("CVS") || item =~ /~$/
180
- end
181
- s.files += %w{LICENSE Rakefile install.rb}
173
+ s.files += FILES_RDOC_INCLUDES
174
+ s.files += `git ls-files lib test`.split("\n")
175
+ s.files += %w{LICENSE Rakefile}
182
176
  s.extra_rdoc_files = FILES_RDOC_EXTRA
183
177
  s.rdoc_options += %w{--include examples}
184
-
185
178
  s.require_path = 'lib'
186
- # s.autorequire = 'xml/mapping'
187
-
188
- # s.add_dependency 'rexml'
189
-
190
- s.has_rdoc=true
191
-
179
+ s.add_development_dependency 'rake', '~> 0'
192
180
  s.test_file = 'test/all_tests.rb'
193
-
194
181
  s.author = 'Olaf Klischat'
195
- s.email = 'olaf.klischat@sofd.de'
196
- s.homepage = "http://xml-mapping.rubyforge.org"
182
+ s.email = 'olaf.klischat@gmail.com'
183
+ s.homepage = "https://github.com/multi-io/xml-mapping"
197
184
  s.rubyforge_project = "xml-mapping"
185
+ s.licenses = ['Apache-2.0']
198
186
  end
199
187
 
200
188
 
201
189
 
202
- Rake::GemPackageTask.new(spec) do |p|
190
+ Gem::PackageTask.new(spec) do |p|
203
191
  p.gem_spec = spec
204
192
  p.need_tar = true
205
193
  p.need_zip = true
206
-
207
- # (indirectly) add :rdoc, :test as prerequisites to :package task
208
- # created by GemPackageTask
209
- file "#{p.package_dir}/#{p.tgz_file}" => [ "test_run", :rdoc ]
210
- file "#{p.package_dir}/#{p.zip_file}" => [ "test_run", :rdoc ]
211
- file "#{p.package_dir}/#{p.gem_file}" => [ "test_run", :rdoc ]
212
194
  end
213
195
 
214
196
 
215
197
 
216
- # run "rake package" to generate tgz, zip, gem in pkg/
217
-
198
+ require 'tmpdir'
218
199
 
200
+ def system_checked(*args)
201
+ system(*args) or raise "failed to run: #{args.inspect}"
202
+ end
219
203
 
220
- task :rfpub_rdoc => [:rdoc] do
221
- p=Rake::SshDirPublisher.new('rubyforge.org',
222
- '/var/www/gforge-projects/xml-mapping/',
223
- 'doc/api')
224
- p.upload
204
+ desc "updates gh-pages branch in the git with the latest rdoc"
205
+ task :ghpublish => [:rdoc] do
206
+ revision = `git rev-parse HEAD`.chomp
207
+ Dir.mktmpdir do |dir|
208
+ # --no-checkout also deletes all files in the target's index
209
+ system_checked("git clone --branch gh-pages --no-checkout . #{dir}")
210
+ cp_r FileList.new('doc/api/*'), dir
211
+ system_checked("cd #{dir} && git add . && git commit -m 'upgrade to #{revision}'")
212
+ system_checked("git fetch #{dir}")
213
+ system_checked("git branch -f gh-pages FETCH_HEAD")
214
+ end
225
215
  end
data/TODO.txt CHANGED
@@ -31,12 +31,17 @@
31
31
 
32
32
  - documentation:
33
33
 
34
- - README:
34
+ - consider switching to YARD
35
+
36
+ - reasons: parameter/return type metadata, (maybe) plugin for the
37
+ code snippet inclusion stuff
38
+
39
+ - user_manual:
35
40
 
36
41
  - document/show usage of default_when_xpath_err outside node type
37
42
  implementations
38
43
 
39
- - README_XPATH:
44
+ - user_manual_xxpath:
40
45
 
41
46
  - mention new step types, new axes, xml/xpath_methods
42
47
 
@@ -50,6 +55,11 @@
50
55
  implementable for some more complicated XPaths -- raise meaningful
51
56
  exceptions in those cases.
52
57
 
58
+ - would need support in xxpath
59
+
60
+ - should probably be built on top of the Ruby 2.0 lazy enumeration
61
+ stuff
62
+
53
63
  - XML::XXPath/XML::Mapping: add XML text nodes (the sub-node of an
54
64
  element node that contains that element's text) first-class to
55
65
  XML::XXPath. Use it for things like text_node :contents, "text()".
@@ -1,5 +1,5 @@
1
- This directory contains the example code snippets from the main README
1
+ This directory contains the example code snippets from the user manual
2
2
  file (each time the documentation is regenerated, they're included in
3
- the README, executed, and their output is checked for correctness and
4
- included in the README as well). So, if you've read the README, you've
5
- already seen all the examples from this directory.
3
+ the user manual, executed, and their output is checked for correctness
4
+ and included in the manual as well). So, if you've read the user
5
+ manual, you've already seen all the examples from this directory.
@@ -0,0 +1,11 @@
1
+ %w{Address Client Company Customer Document Entry Folder Foo Item Order People Person Publication Signature}.each do |cname|
2
+ begin
3
+ Object.send(:remove_const, cname) # name clash with company_usage...
4
+ rescue
5
+ end
6
+ end
7
+
8
+
9
+ %w{company documents_folders order order_signature_enhanced stringarray time_node}.each do |mod|
10
+ $".delete_if{|f| f =~ %r{/#{mod}.rb$} }
11
+ end
@@ -1,11 +1,11 @@
1
1
  c = Company.load_from_file('company.xml')
2
- => #<Company:0x7f487635b068 @address=#<Address:0x7f487635a1e0 @zip=10113, @city="Berlin">, @name="ACME inc.", @customers=[#<Customer:0x7f48763584d0 @name="James Kirk", @id="jim">, #<Customer:0x7f4876356d88 @name="Ernie", @id="ernie">, #<Customer:0x7f4876355640 @name="Bert", @id="bert">]>
2
+ => #<Company:0x007fb015492e98 @name="ACME inc.", @address=#<Address:0x007fb015492380 @city="Berlin", @zip=10113>, @customers=[#<Customer:0x007fb015490030 @id="jim", @name="James Kirk">, #<Customer:0x007fb01548eeb0 @id="ernie", @name="Ernie">, #<Customer:0x007fb01548da38 @id="bert", @name="Bert">]>
3
3
  c.name
4
4
  => "ACME inc."
5
5
  c.customers.size
6
6
  => 3
7
7
  c.customers[1]
8
- => #<Customer:0x7f4876356d88 @name="Ernie", @id="ernie">
8
+ => #<Customer:0x007fb01548eeb0 @id="ernie", @name="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:0x7f48763584d0 @name="James Tiberius Kirk", @id="jim">, #<Customer:0x7f4876356d88 @name="Ernie", @id="ernie">, #<Customer:0x7f4876355640 @name="Bert", @id="bert">, #<Customer:0x7f4876352b48 @name="Cookie Monster", @id="cm">]
16
+ => [#<Customer:0x007fb015490030 @id="jim", @name="James Tiberius Kirk">, #<Customer:0x007fb01548eeb0 @id="ernie", @name="Ernie">, #<Customer:0x007fb01548da38 @id="bert", @name="Bert">, #<Customer:0x007fb01547f1b8 @id="cm", @name="Cookie Monster">]
17
17
  xml2 = c.save_to_xml
18
18
  => <company name='ACME inc.'> ... </>
19
19
  xml2.write($stdout,2)
@@ -27,22 +27,22 @@ xml2.write($stdout,2)
27
27
  </zip>
28
28
  </address>
29
29
  <customers>
30
- <customer id='69974598795880'>
30
+ <customer id='jim'>
31
31
  <name>
32
32
  James Tiberius Kirk
33
33
  </name>
34
34
  </customer>
35
- <customer id='69974598792900'>
35
+ <customer id='ernie'>
36
36
  <name>
37
37
  Ernie
38
38
  </name>
39
39
  </customer>
40
- <customer id='69974598789920'>
40
+ <customer id='bert'>
41
41
  <name>
42
42
  Bert
43
43
  </name>
44
44
  </customer>
45
- <customer id='69974598784420'>
45
+ <customer id='cm'>
46
46
  <name>
47
47
  Cookie Monster
48
48
  </name>