roxml 3.3.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +14 -0
- data/Gemfile +10 -6
- data/Gemfile.lock +102 -40
- data/History.txt +9 -0
- data/README.rdoc +3 -2
- data/Rakefile +6 -9
- data/VERSION +1 -1
- data/examples/search_query.rb +17 -0
- data/lib/roxml/definition.rb +4 -9
- data/lib/roxml/xml/references.rb +24 -9
- data/lib/roxml.rb +28 -13
- data/roxml.gemspec +42 -39
- data/spec/definition_spec.rb +85 -104
- data/spec/examples/active_record_spec.rb +13 -13
- data/spec/examples/amazon_spec.rb +13 -13
- data/spec/examples/current_weather_spec.rb +6 -6
- data/spec/examples/dashed_elements_spec.rb +3 -3
- data/spec/examples/library_spec.rb +3 -3
- data/spec/examples/library_with_fines_spec.rb +7 -7
- data/spec/examples/person_spec.rb +3 -3
- data/spec/examples/post_spec.rb +4 -4
- data/spec/examples/search_query_spec.rb +26 -0
- data/spec/examples/twitter_spec.rb +4 -4
- data/spec/reference_spec.rb +2 -2
- data/spec/regression_spec.rb +13 -8
- data/spec/roxml_spec.rb +30 -43
- data/spec/shared_specs.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/xml/array_spec.rb +2 -2
- data/spec/xml/attributes_spec.rb +7 -7
- data/spec/xml/encoding_spec.rb +9 -9
- data/spec/xml/namespace_spec.rb +40 -21
- data/spec/xml/namespaces_spec.rb +3 -3
- data/spec/xml/object_spec.rb +7 -7
- data/spec/xml/parser_spec.rb +2 -2
- data/spec/xml/text_spec.rb +6 -6
- data/test/fixtures/book_with_octal_pages.xml +2 -3
- data/test/test_helper.rb +1 -2
- data/test/unit/definition_test.rb +26 -27
- data/test/unit/deprecations_test.rb +23 -2
- data/test/unit/to_xml_test.rb +7 -7
- data/test/unit/xml_attribute_test.rb +3 -2
- data/test/unit/xml_block_test.rb +3 -2
- data/test/unit/xml_bool_test.rb +7 -8
- data/test/unit/xml_convention_test.rb +4 -3
- data/test/unit/xml_hash_test.rb +5 -13
- data/test/unit/xml_initialize_test.rb +4 -3
- data/test/unit/xml_name_test.rb +3 -2
- data/test/unit/xml_namespace_test.rb +4 -3
- data/test/unit/xml_object_test.rb +8 -7
- data/test/unit/xml_required_test.rb +7 -6
- data/test/unit/xml_text_test.rb +3 -2
- data/website/index.html +11 -11
- metadata +128 -60
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0af38afb86b97b74c552f4ebd660722c4037154016838e4df2eb64626e2ab3fd
|
|
4
|
+
data.tar.gz: c95d035410a533947c04a41a772fdcbf778e0777bff5fbdf6a9515c97184afec
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c48cd9e91df3ced0445098e6c191d5475ec61baa44f61ecc8023d9b6e812079e96d877e4398418e991217165563d2dd3091f2449060483edad558e958c854f93
|
|
7
|
+
data.tar.gz: c45ca74b5168bf80e1d2133d8cc7a9036cb6c2b60fedbbda23df96b920cc89c47a5e5f84728dc3412aba5a2892447d3797e2472f718b12ebec22ae510d4b2760
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
source "http://rubygems.org"
|
|
2
2
|
|
|
3
|
-
gem 'activesupport', '>=
|
|
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 '
|
|
9
|
-
gem
|
|
10
|
-
gem
|
|
11
|
-
gem
|
|
7
|
+
gem 'rake', '~> 0.9'
|
|
8
|
+
gem 'juwelier'
|
|
9
|
+
gem 'minitest'
|
|
10
|
+
gem 'rexml'
|
|
11
|
+
gem 'rspec', '~> 3.7.0'
|
|
12
|
+
gem 'sqlite3', '>= 1.2.4'
|
|
13
|
+
gem 'activerecord', '>= 4.0'
|
|
14
|
+
gem 'rack', '< 2.0.0'
|
|
15
|
+
gem 'equivalent-xml', '>= 0.6.0'
|
|
12
16
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,50 +1,112 @@
|
|
|
1
1
|
GEM
|
|
2
2
|
remote: http://rubygems.org/
|
|
3
3
|
specs:
|
|
4
|
-
activemodel (3.1
|
|
5
|
-
activesupport (= 3.1
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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.8.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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
rdoc
|
|
49
|
+
semver2
|
|
50
|
+
jwt (2.2.1)
|
|
51
|
+
kamelcase (0.0.2)
|
|
52
|
+
semver2 (~> 3)
|
|
53
|
+
mini_portile2 (2.5.1)
|
|
54
|
+
minitest (5.14.4)
|
|
55
|
+
multi_json (1.14.1)
|
|
56
|
+
multi_xml (0.6.0)
|
|
57
|
+
multipart-post (2.1.1)
|
|
58
|
+
nokogiri (1.11.4)
|
|
59
|
+
mini_portile2 (~> 2.5.0)
|
|
60
|
+
racc (~> 1.4)
|
|
61
|
+
oauth2 (1.4.4)
|
|
62
|
+
faraday (>= 0.8, < 2.0)
|
|
63
|
+
jwt (>= 1.0, < 3.0)
|
|
64
|
+
multi_json (~> 1.3)
|
|
65
|
+
multi_xml (~> 0.5)
|
|
66
|
+
rack (>= 1.2, < 3)
|
|
67
|
+
psych (3.1.0)
|
|
68
|
+
public_suffix (4.0.6)
|
|
69
|
+
racc (1.5.2)
|
|
70
|
+
rack (1.6.13)
|
|
71
|
+
rake (0.9.6)
|
|
72
|
+
rchardet (1.8.0)
|
|
73
|
+
rdoc (6.3.2)
|
|
74
|
+
rexml (3.2.5)
|
|
75
|
+
rspec (3.7.0)
|
|
76
|
+
rspec-core (~> 3.7.0)
|
|
77
|
+
rspec-expectations (~> 3.7.0)
|
|
78
|
+
rspec-mocks (~> 3.7.0)
|
|
79
|
+
rspec-core (3.7.1)
|
|
80
|
+
rspec-support (~> 3.7.0)
|
|
81
|
+
rspec-expectations (3.7.0)
|
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
83
|
+
rspec-support (~> 3.7.0)
|
|
84
|
+
rspec-mocks (3.7.0)
|
|
85
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
86
|
+
rspec-support (~> 3.7.0)
|
|
87
|
+
rspec-support (3.7.1)
|
|
88
|
+
semver2 (3.4.2)
|
|
89
|
+
sqlite3 (1.4.2)
|
|
90
|
+
thread_safe (0.3.6)
|
|
91
|
+
tzinfo (1.2.7)
|
|
92
|
+
thread_safe (~> 0.1)
|
|
93
|
+
zeitwerk (2.3.0)
|
|
39
94
|
|
|
40
95
|
PLATFORMS
|
|
41
96
|
ruby
|
|
42
97
|
|
|
43
98
|
DEPENDENCIES
|
|
44
|
-
activerecord (>=
|
|
45
|
-
activesupport (>=
|
|
46
|
-
|
|
99
|
+
activerecord (>= 4.0)
|
|
100
|
+
activesupport (>= 4.0)
|
|
101
|
+
equivalent-xml (>= 0.6.0)
|
|
102
|
+
juwelier
|
|
103
|
+
minitest
|
|
47
104
|
nokogiri (>= 1.3.3)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
105
|
+
rack (< 2.0.0)
|
|
106
|
+
rake (~> 0.9)
|
|
107
|
+
rexml
|
|
108
|
+
rspec (~> 3.7.0)
|
|
109
|
+
sqlite3 (>= 1.2.4)
|
|
110
|
+
|
|
111
|
+
BUNDLED WITH
|
|
112
|
+
2.2.22
|
data/History.txt
CHANGED
data/README.rdoc
CHANGED
|
@@ -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 '
|
|
8
|
-
|
|
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,12 +16,12 @@ 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 = "
|
|
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
|
-
|
|
24
|
+
Juwelier::GemcutterTasks.new
|
|
26
25
|
|
|
27
26
|
Dir['tasks/**/*.rake'].each { |t| load t }
|
|
28
27
|
|
|
@@ -68,10 +67,8 @@ end
|
|
|
68
67
|
|
|
69
68
|
require 'rake/testtask'
|
|
70
69
|
desc "Test ROXML using the default parser selection behavior"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
$LOAD_PATH << '.'
|
|
74
|
-
Rake.run_tests 'test/unit/*_test.rb'
|
|
70
|
+
Rake::TestTask.new do |t|
|
|
71
|
+
t.test_files = FileList['test/**/*_test.rb']
|
|
75
72
|
end
|
|
76
73
|
|
|
77
74
|
namespace :test do
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4.2.0
|
|
@@ -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
|
+
|
data/lib/roxml/definition.rb
CHANGED
|
@@ -60,7 +60,7 @@ module ROXML
|
|
|
60
60
|
@sought_type = :namespace
|
|
61
61
|
elsif opts[:from].to_s.starts_with?('@')
|
|
62
62
|
@sought_type = :attr
|
|
63
|
-
opts[:from].sub
|
|
63
|
+
opts[:from] = opts[:from].sub('@', '')
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
@name = @attr_name = accessor.to_s.chomp('?')
|
|
@@ -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
|
-
|
|
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
|
|
179
|
+
BigDecimal(v) unless v.blank?
|
|
185
180
|
end
|
|
186
181
|
end) if defined?(BigDecimal)
|
|
187
182
|
|
data/lib/roxml/xml/references.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module ROXML
|
|
2
|
-
class RequiredElementMissing <
|
|
2
|
+
class RequiredElementMissing < ArgumentError # :nodoc:
|
|
3
3
|
end
|
|
4
4
|
|
|
5
5
|
#
|
|
@@ -32,8 +32,9 @@ module ROXML
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def value_in(xml)
|
|
35
|
-
|
|
36
|
-
value =
|
|
35
|
+
xml = XML::Node.from(xml)
|
|
36
|
+
value = fetch_value(xml)
|
|
37
|
+
value = default if default && (value.nil? || value.to_s.empty?)
|
|
37
38
|
|
|
38
39
|
value = apply_blocks(value)
|
|
39
40
|
value = freeze(value) if value && opts.frozen?
|
|
@@ -44,19 +45,33 @@ module ROXML
|
|
|
44
45
|
def conventionize(what)
|
|
45
46
|
convention ||= @instance.class.respond_to?(:roxml_naming_convention) && @instance.class.roxml_naming_convention
|
|
46
47
|
if !what.blank? && convention.respond_to?(:call)
|
|
47
|
-
URI.
|
|
48
|
+
URI.decode_www_form_component(convention.call(URI.encode_www_form_component(what)))
|
|
48
49
|
else
|
|
49
50
|
what
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
def namespacify(what)
|
|
54
|
-
if what.to_s.present? &&
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
if what.to_s.present? && opts.namespace != false && ns = [opts.namespace, @instance.class.roxml_namespace, @default_namespace].compact.map(&:to_s).first
|
|
56
|
+
require "rexml/xpath_parser"
|
|
57
|
+
|
|
58
|
+
parser = REXML::Parsers::XPathParser.new
|
|
59
|
+
parsed = parser.parse what
|
|
60
|
+
|
|
61
|
+
parsed.each_cons(4).with_index.each do |a,i|
|
|
62
|
+
if a[0..2] == [:child, :qname, ""]
|
|
63
|
+
if ns == "*"
|
|
64
|
+
parsed[i+1,3] = [:any, :predicate, [:eq, [:function, "local-name", []], [:literal, a[3]]]] if a[3] != "*"
|
|
65
|
+
else
|
|
66
|
+
a[2].replace ns
|
|
67
|
+
end
|
|
68
|
+
end
|
|
57
69
|
end
|
|
70
|
+
|
|
71
|
+
parser.abbreviate parsed
|
|
72
|
+
else
|
|
73
|
+
what
|
|
58
74
|
end
|
|
59
|
-
what
|
|
60
75
|
end
|
|
61
76
|
|
|
62
77
|
def apply_blocks(val)
|
|
@@ -87,7 +102,7 @@ module ROXML
|
|
|
87
102
|
end
|
|
88
103
|
|
|
89
104
|
def wrap(xml, opts = {:always_create => false})
|
|
90
|
-
wrap_with = @auto_vals ? auto_wrapper : wrapper
|
|
105
|
+
wrap_with = defined?(@auto_vals) && @auto_vals ? auto_wrapper : wrapper
|
|
91
106
|
|
|
92
107
|
return xml if !wrap_with || xml.name == wrap_with
|
|
93
108
|
|
data/lib/roxml.rb
CHANGED
|
@@ -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
|
|
@@ -89,7 +92,7 @@ module ROXML # :nodoc:
|
|
|
89
92
|
def xml_namespace(namespace)
|
|
90
93
|
@roxml_namespace = namespace.to_s
|
|
91
94
|
end
|
|
92
|
-
|
|
95
|
+
|
|
93
96
|
# Sets up a mapping of namespace prefixes to hrefs, to be used by this class.
|
|
94
97
|
# These namespace prefixes are independent of what appears in the xml, only
|
|
95
98
|
# the namespace hrefs themselves need to match
|
|
@@ -125,7 +128,11 @@ module ROXML # :nodoc:
|
|
|
125
128
|
end
|
|
126
129
|
|
|
127
130
|
def roxml_namespaces # :nodoc:
|
|
128
|
-
@roxml_namespaces
|
|
131
|
+
if defined? @roxml_namespaces
|
|
132
|
+
@roxml_namespaces
|
|
133
|
+
else
|
|
134
|
+
{}
|
|
135
|
+
end
|
|
129
136
|
end
|
|
130
137
|
|
|
131
138
|
# Most xml documents have a consistent naming convention, for example, the node and
|
|
@@ -160,7 +167,7 @@ module ROXML # :nodoc:
|
|
|
160
167
|
# Note that the xml_convention is also applied to the default root-level tag_name,
|
|
161
168
|
# but in this case an underscored version of the name is applied, for convenience.
|
|
162
169
|
def xml_convention(to_proc_able = nil, &block)
|
|
163
|
-
raise ArgumentError, "conventions are already set" if @roxml_naming_convention
|
|
170
|
+
raise ArgumentError, "conventions are already set" if defined?(@roxml_naming_convention)
|
|
164
171
|
@roxml_naming_convention =
|
|
165
172
|
if to_proc_able
|
|
166
173
|
raise ArgumentError, "only one conventions can be set" if block_given?
|
|
@@ -171,8 +178,10 @@ module ROXML # :nodoc:
|
|
|
171
178
|
end
|
|
172
179
|
|
|
173
180
|
def roxml_naming_convention # :nodoc:
|
|
174
|
-
@roxml_naming_convention
|
|
175
|
-
|
|
181
|
+
if defined? @roxml_naming_convention
|
|
182
|
+
@roxml_naming_convention
|
|
183
|
+
elsif superclass.respond_to?(:roxml_naming_convention)
|
|
184
|
+
superclass.roxml_naming_convention
|
|
176
185
|
end
|
|
177
186
|
end
|
|
178
187
|
|
|
@@ -260,7 +269,7 @@ module ROXML # :nodoc:
|
|
|
260
269
|
#
|
|
261
270
|
# xml_reader(:count) {|val| Integer(val) unless val.empty? }
|
|
262
271
|
#
|
|
263
|
-
# Such block shorthands for Integer, Float,
|
|
272
|
+
# Such block shorthands for Integer, Float, BigDecimal, Date, Time, and DateTime
|
|
264
273
|
# are currently available, but only for non-Hash declarations.
|
|
265
274
|
#
|
|
266
275
|
# To reference many elements, put the desired type in a literal array. e.g.:
|
|
@@ -434,7 +443,7 @@ module ROXML # :nodoc:
|
|
|
434
443
|
# === Other Options
|
|
435
444
|
# [:in] An optional name of a wrapping tag for this XML accessor.
|
|
436
445
|
# 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
|
|
446
|
+
# [:else] Default value for attribute, if missing from the xml (or it's there but its contents are blank) on .from_xml
|
|
438
447
|
# [:required] If true, throws RequiredElementMissing when the element isn't present
|
|
439
448
|
# [:frozen] If true, all results are frozen (using #freeze) at parse-time.
|
|
440
449
|
# [:cdata] true for values which should be input from or output as cdata elements
|
|
@@ -479,6 +488,9 @@ module ROXML # :nodoc:
|
|
|
479
488
|
private
|
|
480
489
|
def add_reader(attr)
|
|
481
490
|
define_method(attr.accessor) do
|
|
491
|
+
unless instance_variable_defined?(attr.instance_variable_name)
|
|
492
|
+
instance_variable_set(attr.instance_variable_name, attr.default)
|
|
493
|
+
end
|
|
482
494
|
instance_variable_get(attr.instance_variable_name)
|
|
483
495
|
end
|
|
484
496
|
end
|
|
@@ -495,21 +507,25 @@ module ROXML # :nodoc:
|
|
|
495
507
|
# do not work without one.
|
|
496
508
|
def tag_name
|
|
497
509
|
return roxml_tag_name if roxml_tag_name
|
|
498
|
-
|
|
510
|
+
|
|
499
511
|
if tag_name = name.split('::').last
|
|
500
512
|
roxml_naming_convention ? roxml_naming_convention.call(tag_name.underscore) : tag_name.downcase
|
|
501
513
|
end
|
|
502
514
|
end
|
|
503
515
|
|
|
504
516
|
def roxml_tag_name # :nodoc:
|
|
505
|
-
@roxml_tag_name
|
|
506
|
-
|
|
517
|
+
if defined? @roxml_tag_name
|
|
518
|
+
@roxml_tag_name
|
|
519
|
+
elsif superclass.respond_to?(:roxml_tag_name)
|
|
520
|
+
superclass.roxml_tag_name
|
|
507
521
|
end
|
|
508
522
|
end
|
|
509
523
|
|
|
510
524
|
def roxml_namespace # :nodoc:
|
|
511
|
-
@roxml_namespace
|
|
512
|
-
|
|
525
|
+
if defined? @roxml_namespace
|
|
526
|
+
@roxml_namespace
|
|
527
|
+
elsif superclass.respond_to?(:roxml_namespace)
|
|
528
|
+
superclass.roxml_namespace
|
|
513
529
|
end
|
|
514
530
|
end
|
|
515
531
|
|
|
@@ -561,4 +577,3 @@ module ROXML # :nodoc:
|
|
|
561
577
|
end
|
|
562
578
|
end
|
|
563
579
|
end
|
|
564
|
-
|