roxml 3.2.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +13 -0
  3. data/Gemfile +9 -6
  4. data/Gemfile.lock +98 -40
  5. data/History.txt +15 -2
  6. data/README.rdoc +3 -2
  7. data/Rakefile +11 -23
  8. data/VERSION +1 -1
  9. data/examples/person.rb +28 -0
  10. data/examples/search_query.rb +17 -0
  11. data/examples/xml/person.xml +14 -0
  12. data/lib/roxml.rb +10 -4
  13. data/lib/roxml/definition.rb +3 -8
  14. data/lib/roxml/xml/parsers/libxml.rb +11 -27
  15. data/lib/roxml/xml/parsers/nokogiri.rb +13 -26
  16. data/lib/roxml/xml/references.rb +35 -20
  17. data/roxml.gemspec +43 -45
  18. data/spec/definition_spec.rb +79 -103
  19. data/spec/examples/active_record_spec.rb +13 -13
  20. data/spec/examples/amazon_spec.rb +13 -13
  21. data/spec/examples/current_weather_spec.rb +6 -6
  22. data/spec/examples/dashed_elements_spec.rb +3 -3
  23. data/spec/examples/library_spec.rb +3 -3
  24. data/spec/examples/library_with_fines_spec.rb +7 -7
  25. data/spec/examples/person_spec.rb +37 -0
  26. data/spec/examples/post_spec.rb +4 -4
  27. data/spec/examples/search_query_spec.rb +26 -0
  28. data/spec/examples/twitter_spec.rb +4 -4
  29. data/spec/reference_spec.rb +2 -2
  30. data/spec/regression_spec.rb +13 -8
  31. data/spec/roxml_spec.rb +56 -61
  32. data/spec/shared_specs.rb +2 -2
  33. data/spec/spec_helper.rb +2 -0
  34. data/spec/xml/array_spec.rb +2 -2
  35. data/spec/xml/attributes_spec.rb +7 -7
  36. data/spec/xml/encoding_spec.rb +9 -9
  37. data/spec/xml/namespace_spec.rb +40 -21
  38. data/spec/xml/namespaces_spec.rb +3 -3
  39. data/spec/xml/object_spec.rb +7 -7
  40. data/spec/xml/parser_spec.rb +2 -8
  41. data/spec/xml/text_spec.rb +6 -6
  42. data/test/fixtures/book_with_octal_pages.xml +2 -3
  43. data/test/test_helper.rb +1 -2
  44. data/test/unit/definition_test.rb +26 -27
  45. data/test/unit/deprecations_test.rb +23 -2
  46. data/test/unit/to_xml_test.rb +9 -9
  47. data/test/unit/xml_attribute_test.rb +3 -2
  48. data/test/unit/xml_block_test.rb +3 -2
  49. data/test/unit/xml_bool_test.rb +7 -8
  50. data/test/unit/xml_convention_test.rb +4 -3
  51. data/test/unit/xml_hash_test.rb +5 -13
  52. data/test/unit/xml_initialize_test.rb +4 -3
  53. data/test/unit/xml_name_test.rb +3 -2
  54. data/test/unit/xml_namespace_test.rb +4 -3
  55. data/test/unit/xml_object_test.rb +8 -7
  56. data/test/unit/xml_required_test.rb +7 -6
  57. data/test/unit/xml_text_test.rb +3 -2
  58. data/website/index.html +11 -11
  59. metadata +117 -61
  60. data/test/load_test.rb +0 -6
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d9a751217585460ca2e749d175117289a4532701abffa52324990844a846261b
4
+ data.tar.gz: 90a4e8a47bf58aaaa0e18087fb852ce713fb32e44415b89f53c464789ae91182
5
+ SHA512:
6
+ metadata.gz: d324b1250fb8ea144973326709e936caddd309d75a03f1801f1e45c8a972c9051982ce127fcf828627d865073e8f10767b76fc9157a564fdf326a98f01b11e98
7
+ data.tar.gz: b8f5ab9bc99c0c772db74fd999b02ae315da623aaaefaf12170d6a294fd38de489e53b51b53a128cd8e204c6a53d73bd9b5544f633bd83fdbe7918386b696bf0
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: ruby
3
+ before_install:
4
+ - bundle update --bundler
5
+ rvm:
6
+ - 2.5.3
7
+ - 2.6.1
8
+ - 2.7.1
9
+ - ruby-head
10
+
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: ruby-head
data/Gemfile CHANGED
@@ -1,12 +1,15 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'activesupport', '>= 2.3.0'
3
+ gem 'activesupport', '>= 4.0'
4
4
  gem 'nokogiri', '>= 1.3.3'
5
5
 
6
6
  group :development, :test do
7
- gem 'rake'
8
- gem 'jeweler'
9
- gem "rspec", '>= 2.0.0'
10
- gem "sqlite3-ruby", '>= 1.2.4'
11
- gem "activerecord", '>= 2.2.2'
7
+ gem 'rake', '~> 0.9'
8
+ gem 'juwelier'
9
+ gem 'minitest'
10
+ gem 'rspec', '~> 3.7.0'
11
+ gem 'sqlite3', '>= 1.2.4'
12
+ gem 'activerecord', '>= 4.0'
13
+ gem 'rack', '< 2.0.0'
14
+ gem 'equivalent-xml', '>= 0.6.0'
12
15
  end
@@ -1,50 +1,108 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.1.3)
5
- activesupport (= 3.1.3)
6
- builder (~> 3.0.0)
7
- i18n (~> 0.6)
8
- activerecord (3.1.3)
9
- activemodel (= 3.1.3)
10
- activesupport (= 3.1.3)
11
- arel (~> 2.2.1)
12
- tzinfo (~> 0.3.29)
13
- activesupport (3.1.3)
14
- multi_json (~> 1.0)
15
- arel (2.2.1)
16
- builder (3.0.0)
17
- diff-lcs (1.1.3)
18
- git (1.2.5)
19
- i18n (0.6.0)
20
- jeweler (1.6.4)
21
- bundler (~> 1.0)
22
- git (>= 1.2.5)
4
+ activemodel (6.0.3.1)
5
+ activesupport (= 6.0.3.1)
6
+ activerecord (6.0.3.1)
7
+ activemodel (= 6.0.3.1)
8
+ activesupport (= 6.0.3.1)
9
+ activesupport (6.0.3.1)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 0.7, < 2)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ zeitwerk (~> 2.2, >= 2.2.2)
15
+ addressable (2.7.0)
16
+ public_suffix (>= 2.0.2, < 5.0)
17
+ builder (3.2.4)
18
+ concurrent-ruby (1.1.6)
19
+ descendants_tracker (0.0.4)
20
+ thread_safe (~> 0.3, >= 0.3.1)
21
+ diff-lcs (1.3)
22
+ equivalent-xml (0.6.0)
23
+ nokogiri (>= 1.4.3)
24
+ faraday (0.17.3)
25
+ multipart-post (>= 1.2, < 3)
26
+ git (1.7.0)
27
+ rchardet (~> 1.8)
28
+ github_api (0.18.2)
29
+ addressable (~> 2.4)
30
+ descendants_tracker (~> 0.0.4)
31
+ faraday (~> 0.8)
32
+ hashie (~> 3.5, >= 3.5.2)
33
+ oauth2 (~> 1.0)
34
+ hashie (3.6.0)
35
+ highline (2.0.3)
36
+ i18n (1.8.3)
37
+ concurrent-ruby (~> 1.0)
38
+ juwelier (2.4.9)
39
+ builder
40
+ bundler
41
+ git
42
+ github_api
43
+ highline
44
+ kamelcase (~> 0)
45
+ nokogiri
46
+ psych
23
47
  rake
24
- multi_json (1.0.4)
25
- nokogiri (1.5.0)
26
- rake (0.9.2.2)
27
- rspec (2.8.0)
28
- rspec-core (~> 2.8.0)
29
- rspec-expectations (~> 2.8.0)
30
- rspec-mocks (~> 2.8.0)
31
- rspec-core (2.8.0)
32
- rspec-expectations (2.8.0)
33
- diff-lcs (~> 1.1.2)
34
- rspec-mocks (2.8.0)
35
- sqlite3 (1.3.5)
36
- sqlite3-ruby (1.3.3)
37
- sqlite3 (>= 1.3.3)
38
- tzinfo (0.3.31)
48
+ rdoc
49
+ semver2
50
+ jwt (2.2.1)
51
+ kamelcase (0.0.2)
52
+ semver2 (~> 3)
53
+ mini_portile2 (2.4.0)
54
+ minitest (5.14.1)
55
+ multi_json (1.14.1)
56
+ multi_xml (0.6.0)
57
+ multipart-post (2.1.1)
58
+ nokogiri (1.10.9)
59
+ mini_portile2 (~> 2.4.0)
60
+ oauth2 (1.4.4)
61
+ faraday (>= 0.8, < 2.0)
62
+ jwt (>= 1.0, < 3.0)
63
+ multi_json (~> 1.3)
64
+ multi_xml (~> 0.5)
65
+ rack (>= 1.2, < 3)
66
+ psych (3.1.0)
67
+ public_suffix (4.0.5)
68
+ rack (1.6.13)
69
+ rake (0.9.6)
70
+ rchardet (1.8.0)
71
+ rdoc (6.2.1)
72
+ rspec (3.7.0)
73
+ rspec-core (~> 3.7.0)
74
+ rspec-expectations (~> 3.7.0)
75
+ rspec-mocks (~> 3.7.0)
76
+ rspec-core (3.7.1)
77
+ rspec-support (~> 3.7.0)
78
+ rspec-expectations (3.7.0)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.7.0)
81
+ rspec-mocks (3.7.0)
82
+ diff-lcs (>= 1.2.0, < 2.0)
83
+ rspec-support (~> 3.7.0)
84
+ rspec-support (3.7.1)
85
+ semver2 (3.4.2)
86
+ sqlite3 (1.4.2)
87
+ thread_safe (0.3.6)
88
+ tzinfo (1.2.7)
89
+ thread_safe (~> 0.1)
90
+ zeitwerk (2.3.0)
39
91
 
40
92
  PLATFORMS
41
93
  ruby
42
94
 
43
95
  DEPENDENCIES
44
- activerecord (>= 2.2.2)
45
- activesupport (>= 2.3.0)
46
- jeweler
96
+ activerecord (>= 4.0)
97
+ activesupport (>= 4.0)
98
+ equivalent-xml (>= 0.6.0)
99
+ juwelier
100
+ minitest
47
101
  nokogiri (>= 1.3.3)
48
- rake
49
- rspec (>= 2.0.0)
50
- sqlite3-ruby (>= 1.2.4)
102
+ rack (< 2.0.0)
103
+ rake (~> 0.9)
104
+ rspec (~> 3.7.0)
105
+ sqlite3 (>= 1.2.4)
106
+
107
+ BUNDLED WITH
108
+ 1.17.3
@@ -1,3 +1,18 @@
1
+ See github releases for versions > 3.3.1
2
+ https://github.com/Empact/roxml/releases
3
+
4
+ == 3.3.1 (February 10, 2012)
5
+
6
+ * bug fix
7
+
8
+ * Fix reading of VERSION file - Jari Bakken (jarib)
9
+
10
+ == 3.3.0 (February 9, 2012)
11
+
12
+ * major enhancement
13
+
14
+ * Don't extend/modify the XML parser
15
+
1
16
  == 3.1.6 (September 9, 2010)
2
17
 
3
18
  * bug fix
@@ -6,8 +21,6 @@
6
21
  (fixes gh issue #27)
7
22
  * change the way we monkey patch Nokogiri to leave the original
8
23
  behaviour of the search() method unchanged (fixes gh issue #16)
9
- * Unofficial release by James Healy, empact has stepped back from maintaining
10
- roxml
11
24
 
12
25
  == 3.1.5 (December 18, 2009)
13
26
 
@@ -1,10 +1,11 @@
1
1
  ROXML Ruby Object to XML mapping library.
2
2
 
3
+ {<img src="https://travis-ci.org/Empact/roxml.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/Empact/roxml]
4
+
3
5
  For more information visit:
4
6
 
5
7
  http://rdoc.info/projects/Empact/roxml
6
8
  http://empact.github.com/roxml/
7
- http://rubyforge.org/projects/roxml/
8
9
 
9
10
  Please submit bugs here:
10
11
 
@@ -171,7 +172,7 @@ explicitly require one or the other, you may do the following:
171
172
  For more information on available annotations, see ROXML::ClassMethods::Declarations
172
173
 
173
174
  == Note on Patches/Pull Requests
174
-
175
+
175
176
  * Fork the project.
176
177
  * Make your feature addition or bug fix.
177
178
  * Add specs for it. This is important so I don't break it in a
data/Rakefile CHANGED
@@ -4,10 +4,9 @@ ENV['RUBY_FLAGS'] = '-W1'
4
4
 
5
5
  # Generate all the Rake tasks
6
6
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
7
+ require 'juwelier'
8
+ Juwelier::Tasks.new do |gem|
9
9
  gem.name = 'roxml'
10
- gem.rubyforge_project = "roxml"
11
10
  gem.summary = "Ruby Object to XML mapping library"
12
11
  gem.description = <<EOF
13
12
  ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML.
@@ -17,28 +16,24 @@ building first-class Ruby classes. As a result, ROXML simplifies the development
17
16
  RESTful applications, Web Services, and XML-RPC.
18
17
  EOF
19
18
  gem.email = "ben.woosley@gmail.com"
20
- gem.homepage = "http://roxml.rubyforge.org"
19
+ gem.homepage = "https://github.com/Empact/roxml"
21
20
  gem.authors = ["Ben Woosley", "Zak Mandhro", "Anders Engstrom", "Russ Olsen"]
22
21
 
23
22
  gem.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
24
23
  end
25
- Jeweler::GemcutterTasks.new
24
+ Juwelier::GemcutterTasks.new
26
25
 
27
26
  Dir['tasks/**/*.rake'].each { |t| load t }
28
27
 
29
- task :default => [:test, :spec, 'test:load']
30
- task :all => [:libxml, :nokogiri, 'test:load']
28
+ task :default => [:test, :spec]
29
+ task :all => [:libxml, :nokogiri]
31
30
  task :libxml => ['test:libxml', 'spec:libxml']
32
31
  task :nokogiri => ['test:nokogiri', 'spec:nokogiri']
33
32
 
34
33
 
35
- require 'rake/rdoctask'
36
- Rake::RDocTask.new do |rdoc|
37
- if File.exist?('VERSION')
38
- version = File.read('VERSION')
39
- else
40
- version = ""
41
- end
34
+ require 'rdoc/task'
35
+ RDoc::Task.new do |rdoc|
36
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
37
 
43
38
  rdoc.rdoc_dir = 'rdoc'
44
39
  rdoc.title = "roxml #{version}"
@@ -72,10 +67,8 @@ end
72
67
 
73
68
  require 'rake/testtask'
74
69
  desc "Test ROXML using the default parser selection behavior"
75
- task :test do
76
- require 'rake/runtest'
77
- $LOAD_PATH << '.'
78
- Rake.run_tests 'test/unit/*_test.rb'
70
+ Rake::TestTask.new do |t|
71
+ t.test_files = FileList['test/**/*_test.rb']
79
72
  end
80
73
 
81
74
  namespace :test do
@@ -93,11 +86,6 @@ namespace :test do
93
86
  Rake::Task["test"].invoke
94
87
  end
95
88
 
96
- task :load do
97
- `ruby test/load_test.rb`
98
- puts "Load Success!" if $?.success?
99
- end
100
-
101
89
  desc "Runs tests under RCOV"
102
90
  task :rcov do
103
91
  system "rcov -T --no-html -x '^/' #{FileList['test/unit/*_test.rb']}"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 4.1.0
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative './../spec/spec_helper'
3
+
4
+ class Person
5
+ include ROXML
6
+
7
+ xml_accessor :name, :from => 'name'
8
+
9
+ xml_accessor :lat, :from => 'latitude', :in => 'location/coordinates'
10
+ xml_accessor :long, :from => 'longitude', :in => 'location/coordinates'
11
+
12
+ xml_accessor :street, :from => 'street', :in => 'location/address'
13
+ xml_accessor :city, :from => 'city', :in => 'location/address'
14
+ xml_accessor :zip, :from => 'zip', :in => 'location/address'
15
+ end
16
+
17
+ unless defined?(RSpec)
18
+ p = Person.new
19
+ p.name = 'John Doe'
20
+
21
+ p.lat = '40.715224'
22
+ p.long = '-74.005966'
23
+ p.street = 'Evergreen Terrace'
24
+ p.city = 'Springfield'
25
+ p.zip = '2342'
26
+
27
+ puts p.to_xml.to_s
28
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative './../spec/spec_helper'
3
+
4
+ class SearchQuery
5
+ include ROXML
6
+ xml_accessor :query
7
+ xml_accessor :max_results, :else => 20, :as => Integer
8
+ xml_accessor :language, :else => 'EN'
9
+ end
10
+
11
+
12
+ unless defined?(RSpec)
13
+ q = SearchQuery.new
14
+ q.query = "Some random query string."
15
+ puts q.to_xml.to_s
16
+ end
17
+
@@ -0,0 +1,14 @@
1
+ <person>
2
+ <name>John Doe</name>
3
+ <location>
4
+ <coordinates>
5
+ <latitude>40.715224</latitude>
6
+ <longitude>-74.005966</longitude>
7
+ </coordinates>
8
+ <address>
9
+ <street>Evergreen Terrace</street>
10
+ <city>Springfield</city>
11
+ <zip>2342</zip>
12
+ </address>
13
+ </location>
14
+ </person>
@@ -1,7 +1,7 @@
1
1
  require 'uri'
2
2
 
3
3
  require 'active_support'
4
- if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('3')
4
+ if Gem.loaded_specs['activesupport'] && Gem.loaded_specs['activesupport'].version >= Gem::Version.new('3')
5
5
  require 'active_support/inflector'
6
6
  require 'active_support/core_ext/object/duplicable'
7
7
  require 'active_support/core_ext/module/delegation'
@@ -14,7 +14,7 @@ require 'roxml/definition'
14
14
  require 'roxml/xml'
15
15
 
16
16
  module ROXML # :nodoc:
17
- VERSION = '3.1.5'
17
+ VERSION = File.read(File.expand_path("../../VERSION", __FILE__))
18
18
 
19
19
  def self.included(base) # :nodoc:
20
20
  base.class_eval do
@@ -42,6 +42,9 @@ module ROXML # :nodoc:
42
42
  ref.update_xml(root, value)
43
43
  end
44
44
  end
45
+ if params[:namespaces]
46
+ params[:namespaces].each { |prefix, url| root.add_namespace_definition(prefix, url) }
47
+ end
45
48
  end
46
49
  end
47
50
  end
@@ -260,7 +263,7 @@ module ROXML # :nodoc:
260
263
  #
261
264
  # xml_reader(:count) {|val| Integer(val) unless val.empty? }
262
265
  #
263
- # Such block shorthands for Integer, Float, Fixnum, BigDecimal, Date, Time, and DateTime
266
+ # Such block shorthands for Integer, Float, BigDecimal, Date, Time, and DateTime
264
267
  # are currently available, but only for non-Hash declarations.
265
268
  #
266
269
  # To reference many elements, put the desired type in a literal array. e.g.:
@@ -434,7 +437,7 @@ module ROXML # :nodoc:
434
437
  # === Other Options
435
438
  # [:in] An optional name of a wrapping tag for this XML accessor.
436
439
  # This can include other xpath values, which will be joined with :from with a '/'
437
- # [:else] Default value for attribute, if missing from the xml on .from_xml
440
+ # [:else] Default value for attribute, if missing from the xml (or it's there but its contents are blank) on .from_xml
438
441
  # [:required] If true, throws RequiredElementMissing when the element isn't present
439
442
  # [:frozen] If true, all results are frozen (using #freeze) at parse-time.
440
443
  # [:cdata] true for values which should be input from or output as cdata elements
@@ -479,6 +482,9 @@ module ROXML # :nodoc:
479
482
  private
480
483
  def add_reader(attr)
481
484
  define_method(attr.accessor) do
485
+ if instance_variable_get(attr.instance_variable_name).nil?
486
+ instance_variable_set(attr.instance_variable_name, attr.default)
487
+ end
482
488
  instance_variable_get(attr.instance_variable_name)
483
489
  end
484
490
  end
@@ -140,12 +140,12 @@ module ROXML
140
140
  default
141
141
  end
142
142
  end
143
-
143
+
144
144
  CORE_BLOCK_SHORTHANDS = {
145
145
  # Core Shorthands
146
146
  Integer => lambda do |val|
147
147
  all(val) do |v|
148
- Integer(v) unless v.blank?
148
+ v.to_i unless v.blank?
149
149
  end
150
150
  end,
151
151
  Float => lambda do |val|
@@ -153,11 +153,6 @@ module ROXML
153
153
  Float(v) unless v.blank?
154
154
  end
155
155
  end,
156
- Fixnum => lambda do |val|
157
- all(val) do |v|
158
- v.to_i unless v.blank?
159
- end
160
- end,
161
156
  Time => lambda do |val|
162
157
  all(val) {|v| Time.parse(v) unless v.blank? }
163
158
  end,
@@ -181,7 +176,7 @@ module ROXML
181
176
  CORE_BLOCK_SHORTHANDS.tap do |blocks|
182
177
  blocks.reverse_merge!(BigDecimal => lambda do |val|
183
178
  all(val) do |v|
184
- BigDecimal.new(v) unless v.blank?
179
+ BigDecimal(v) unless v.blank?
185
180
  end
186
181
  end) if defined?(BigDecimal)
187
182