jordi-xml_struct 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/WHATSNEW +3 -0
- data/lib/xml_struct.rb +18 -6
- data/test/samples/weird_characters.xml +2 -0
- data/test/test_helper.rb +1 -0
- data/test/xml_struct_test.rb +14 -0
- metadata +2 -1
data/WHATSNEW
CHANGED
data/lib/xml_struct.rb
CHANGED
@@ -58,16 +58,24 @@ module XMLStruct
|
|
58
58
|
children[key] = if children[key]
|
59
59
|
|
60
60
|
unless obj.respond_to?((plural_key = key.to_s.pluralize).to_sym)
|
61
|
-
|
62
|
-
|
61
|
+
begin
|
62
|
+
obj.instance_eval %{
|
63
|
+
def #{plural_key}; @__children[%s|#{key.to_s}|]; end }
|
64
|
+
rescue SyntaxError
|
65
|
+
nil
|
66
|
+
end
|
63
67
|
end
|
64
68
|
|
65
69
|
children[key] = [ children[key] ] unless children[key].is_a? Array
|
66
70
|
children[key] << element
|
67
71
|
else
|
68
72
|
unless obj.respond_to? key
|
69
|
-
|
70
|
-
|
73
|
+
begin
|
74
|
+
obj.instance_eval %{
|
75
|
+
def #{key.to_s}; @__children[%s|#{key.to_s}|]; end }
|
76
|
+
rescue SyntaxError
|
77
|
+
nil
|
78
|
+
end
|
71
79
|
end
|
72
80
|
|
73
81
|
element
|
@@ -85,8 +93,12 @@ module XMLStruct
|
|
85
93
|
attributes[(key = name.to_sym)] = attr_value.squish.extend String
|
86
94
|
|
87
95
|
unless obj.respond_to? key
|
88
|
-
|
89
|
-
|
96
|
+
begin
|
97
|
+
obj.instance_eval %{
|
98
|
+
def #{key.to_s}; @__attributes[%s|#{key.to_s}|]; end }
|
99
|
+
rescue SyntaxError
|
100
|
+
nil
|
101
|
+
end
|
90
102
|
end
|
91
103
|
|
92
104
|
obj.instance_variable_set :@__attributes, attributes
|
data/test/test_helper.rb
CHANGED
@@ -24,6 +24,7 @@ end
|
|
24
24
|
|
25
25
|
require 'digest/md5'
|
26
26
|
{ :lorem => '9062c0f294383435d5b04ce6d67b6d61',
|
27
|
+
:weird_characters => 'cdcbd9b89b261487fa98c11d856f50fe',
|
27
28
|
:recipe => '6087ab42049273d123d473093b04ab12' }.each do |file_key, md5|
|
28
29
|
|
29
30
|
unless Digest::MD5.hexdigest(xml_file(file_key).read) == md5
|
data/test/xml_struct_test.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
+
describe 'An XML file with weird characters' do
|
4
|
+
|
5
|
+
it 'should not raise exceptions' do
|
6
|
+
should.not.raise(Exception) do
|
7
|
+
@xml = XMLStruct.new xml_file(:weird_characters)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should allow access to attributes with dashes in the name' do
|
12
|
+
XMLStruct.new(
|
13
|
+
xml_file(:weird_characters))['attr-with-dashes'].should == 'lame'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
3
17
|
describe 'The XML Struct module' do
|
4
18
|
|
5
19
|
def setup
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jordi-xml_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordi Bunster
|
@@ -75,6 +75,7 @@ test_files:
|
|
75
75
|
- test/samples
|
76
76
|
- test/samples/lorem.xml
|
77
77
|
- test/samples/recipe.xml
|
78
|
+
- test/samples/weird_characters.xml
|
78
79
|
- test/test_helper.rb
|
79
80
|
- test/vendor
|
80
81
|
- test/vendor/test-spec
|