xml-object 0.9.93 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c18066558a35627d1903eff9a58c61e133429c0
4
+ data.tar.gz: 52e89eaf04ae675b033091bafe97fba86847aaaa
5
+ SHA512:
6
+ metadata.gz: 7f9c6fe37eea43a4f073f7db584c29617334607f6b20b1fc1e2e18814a11e70a4f63ead949a9e227ecd58055d381affde99d0bd4776f1081bf94e9896ac72535
7
+ data.tar.gz: 3de060a2a3537d4008d518ba25ad6d4f178d4bb144f9e6c5b011cc5d9b217bbf719e66fde17bc22aa3aba797cd6622470388931a8c9679d216341c888d2324a5
@@ -12,17 +12,7 @@ speedups. See more below.
12
12
 
13
13
  == Compatibility
14
14
 
15
- I've tested this release under:
16
-
17
- Rubinius: 1.0.1 (REXML only, libxml-ruby might work if you can build it)
18
- MRI: 1.9.2, 1.8.7, 1.8.6
19
- REE: 1.8.7
20
- JRuby: 1.5.2, 1.4.0 (both in 1.8.7 mode)
21
-
22
- And with the following optionals:
23
-
24
- version 1.1.4 of libxml-ruby (for faster execution)
25
- version 2.3.8 of activesupport (for inflected plurals)
15
+ See https://travis-ci.org/notlaforge/xml-object/
26
16
 
27
17
  == Installation instructions
28
18
 
@@ -180,4 +170,4 @@ The LibXML adapter will not return the 'xmlns' attribute.
180
170
 
181
171
  == Legal
182
172
 
183
- Copyright (c) 2008, 2009 Jordi Bunster, released under the MIT license
173
+ Copyright (c) Jordi Bunster, released under the MIT license
data/WHATSNEW CHANGED
@@ -1,4 +1,12 @@
1
- * 0.9.93 (?):
1
+ * 1.0.0 (2016-04-07):
2
+ - Verified safe after http://blog.rubygems.org/2016/04/06/gem-replacement-vulnerability-and-mitigation.html
3
+ - Dropped ruby 1.8 (and JRuby in 1.8 mode)
4
+ - Moved tests to https://travis-ci.org/notlaforge/xml-object/
5
+ - Activesupport now required, but we only load the inflector
6
+ and none of the core extensions, so it won't infect your
7
+ code.
8
+
9
+ * 0.9.93 (2010-08-26):
2
10
  - Rubinius support (tested with REXML only)
3
11
  - 1.9.2 support
4
12
 
@@ -6,63 +6,63 @@ require 'xml-object/collection_proxy'
6
6
  require 'xml-object/element'
7
7
 
8
8
  module XMLObject
9
- # Returns a String or Array object representing the given XML, decorated
10
- # with methods to access attributes and/or child elements.
11
- def self.new(duck) # :nodoc:
12
- case duck
13
- when @adapter::Element then new_decorated_obj duck
14
- when Array then duck.map! { |d| new_decorated_obj d }
15
- else new @adapter.new(duck)
16
- end
17
- end
9
+ # Returns a String or Array object representing the given XML, decorated
10
+ # with methods to access attributes and/or child elements.
11
+ def self.new(duck) # :nodoc:
12
+ case duck
13
+ when @adapter::Element then new_decorated_obj duck
14
+ when Array then duck.map! { |d| new_decorated_obj d }
15
+ else new @adapter.new(duck)
16
+ end
17
+ end
18
18
 
19
- private ##################################################################
19
+ private ##################################################################
20
20
 
21
- # Takes any adapter Element object, and converts it recursively into
22
- # the corresponding tree of decorated objects.
23
- def self.new_decorated_obj(xml) # :nodoc:
24
- # More than one child, empty value, and all children with the same name?
25
- obj = if xml.children.size > 1 && xml.value !~ /\S/ &&
21
+ # Takes any adapter Element object, and converts it recursively into
22
+ # the corresponding tree of decorated objects.
23
+ def self.new_decorated_obj(xml) # :nodoc:
24
+ # More than one child, empty value, and all children with the same name?
25
+ obj = if xml.children.size > 1 && xml.value !~ /\S/ &&
26
26
  xml.children.map { |c| c.name }.uniq.size == 1
27
27
 
28
- CollectionProxy.new xml # This is an empty array wrap
29
- else
30
- Element.new xml # This one is an actual element
31
- end
28
+ CollectionProxy.new xml # This is an empty array wrap
29
+ else
30
+ Element.new xml # This one is an actual element
31
+ end
32
32
 
33
- xml.children.each { |child| add_child obj, child.name, new(child) }
34
- xml.attributes.each { |name, value| add_attribute obj, name, value }
33
+ xml.children.each { |child| add_child obj, child.name, new(child) }
34
+ xml.attributes.each { |name, value| add_attribute obj, name, value }
35
35
 
36
- # Let's teach our object how to access its XML elements and attributes
37
- obj.extend Properties
38
- end
36
+ # Let's teach our object how to access its XML elements and attributes
37
+ obj.extend Properties
38
+ end
39
39
 
40
- # Decorates the given object 'obj' with a method 'name' that returns the
41
- # given 'element'. If 'name' is already taken, takes care of the array
42
- # folding behaviour.
43
- def self.add_child(obj, name, element) # :nodoc:
44
- key = name.to_sym
45
- children = obj.instance_variable_get :@__children
40
+ # Decorates the given object 'obj' with a method 'name' that returns the
41
+ # given 'element'. If 'name' is already taken, takes care of the array
42
+ # folding behaviour.
43
+ def self.add_child(obj, name, element) # :nodoc:
44
+ key = name.to_sym
45
+ children = obj.instance_variable_get :@__children
46
46
 
47
- children[key] = if children[key]
47
+ children[key] = if children[key]
48
48
 
49
- children[key] = [ children[key] ] unless children[key].is_a? Array
50
- children[key] << element
51
- else
52
- element
53
- end
49
+ children[key] = [ children[key] ] unless children[key].is_a? Array
50
+ children[key] << element
51
+ else
52
+ element
53
+ end
54
54
 
55
- obj.instance_variable_set :@__children, children
56
- element
57
- end
55
+ obj.instance_variable_set :@__children, children
56
+ element
57
+ end
58
58
 
59
- # Decorates the given object 'obj' with a method 'name' that returns the
60
- # given 'attr_value'.
61
- def self.add_attribute(obj, name, value) # :nodoc:
62
- attributes = obj.instance_variable_get :@__attributes
63
- attributes[key = name.to_sym] = value.strip.gsub /\s+/, ' '
59
+ # Decorates the given object 'obj' with a method 'name' that returns the
60
+ # given 'attr_value'.
61
+ def self.add_attribute(obj, name, value) # :nodoc:
62
+ attributes = obj.instance_variable_get :@__attributes
63
+ attributes[key = name.to_sym] = value.strip.gsub /\s+/, ' '
64
64
 
65
- obj.instance_variable_set :@__attributes, attributes
66
- value
67
- end
65
+ obj.instance_variable_set :@__attributes, attributes
66
+ value
67
+ end
68
68
  end
@@ -1,29 +1,29 @@
1
1
  module XMLObject # :nodoc:
2
- class << self # :nodoc:
3
- attr_accessor :adapter # :nodoc:
4
- end
2
+ class << self # :nodoc:
3
+ attr_accessor :adapter # :nodoc:
4
+ end
5
5
 
6
- module Adapters # :nodoc:
7
- module Base # :nodoc:
8
- class Element # :nodoc:
9
- attr_accessor :raw, :name, :value, :attributes, :children # :nodoc:
6
+ module Adapters # :nodoc:
7
+ module Base # :nodoc:
8
+ class Element # :nodoc:
9
+ attr_accessor :raw, :name, :value, :attributes, :children # :nodoc:
10
10
 
11
- def initialize(*args)
11
+ def initialize(*args)
12
12
 
13
- @children = @element_nodes.map { |node| self.class.new(node) }
14
- @value = (not (text_value !~ /\S/)) ? text_value : cdata_value
15
- end
13
+ @children = @element_nodes.map { |node| self.class.new(node) }
14
+ @value = (not (text_value !~ /\S/)) ? text_value : cdata_value
15
+ end
16
16
 
17
- private ###########################################################
17
+ private ###########################################################
18
18
 
19
- def text_value
20
- @text_value_memo ||= @text_nodes.reject { |n| n !~ /\S/ }.join
21
- end
19
+ def text_value
20
+ @text_value_memo ||= @text_nodes.reject { |n| n !~ /\S/ }.join
21
+ end
22
22
 
23
- def cdata_value
24
- @cdata_nodes.join
25
- end
26
- end
27
- end
28
- end
23
+ def cdata_value
24
+ @cdata_nodes.join
25
+ end
26
+ end
27
+ end
28
+ end
29
29
  end
@@ -1,34 +1,34 @@
1
1
  require 'libxml' unless defined?(JRUBY_VERSION) # JRuby already has it...
2
2
 
3
3
  module XMLObject::Adapters::LibXML
4
- # Can take a String of XML data, or anything that responds to
5
- # either +read+ or +to_s+.
6
- def self.new(duck)
7
- case
8
- when duck.respond_to?(:read)
9
- then Element.new(::LibXML::XML::Parser.string(duck.read).parse.root)
10
- when duck.respond_to?(:to_s)
11
- then Element.new(::LibXML::XML::Parser.string(duck.to_s).parse.root)
12
- else raise "Don't know how to deal with '#{duck.class}' object"
13
- end
14
- end
4
+ # Can take a String of XML data, or anything that responds to
5
+ # either +read+ or +to_s+.
6
+ def self.new(duck)
7
+ case
8
+ when duck.respond_to?(:read)
9
+ then Element.new(::LibXML::XML::Parser.string(duck.read).parse.root)
10
+ when duck.respond_to?(:to_s)
11
+ then Element.new(::LibXML::XML::Parser.string(duck.to_s).parse.root)
12
+ else raise "Don't know how to deal with '#{duck.class}' object"
13
+ end
14
+ end
15
15
 
16
- private ##################################################################
16
+ private ##################################################################
17
17
 
18
- class Element < XMLObject::Adapters::Base::Element # :nodoc:
19
- def initialize(xml)
20
- @raw, @name, @attributes = xml, xml.name, xml.attributes.to_h
18
+ class Element < XMLObject::Adapters::Base::Element # :nodoc:
19
+ def initialize(xml)
20
+ @raw, @name, @attributes = xml, xml.name, xml.attributes.to_h
21
21
 
22
- @element_nodes = xml.children.select { |c| c.element? }
22
+ @element_nodes = xml.children.select { |c| c.element? }
23
23
 
24
- @text_nodes = xml.children.select { |c| c.text? }.map! { |c| c.to_s }
25
- @cdata_nodes = xml.children.select { |c| c.cdata? }.map! do |c|
26
- c.to_s.chomp(']]>').sub('<![CDATA[', '')
27
- end
24
+ @text_nodes = xml.children.select { |c| c.text? }.map! { |c| c.to_s }
25
+ @cdata_nodes = xml.children.select { |c| c.cdata? }.map! do |c|
26
+ c.to_s.chomp(']]>').sub('<![CDATA[', '')
27
+ end
28
28
 
29
- super
30
- end
31
- end
29
+ super
30
+ end
31
+ end
32
32
  end
33
33
 
34
34
  ::XMLObject.adapter = ::XMLObject::Adapters::LibXML
@@ -1,37 +1,37 @@
1
1
  require 'rexml/document'
2
2
 
3
3
  module XMLObject::Adapters::REXML
4
- # Can take a String of XML data, or anything that responds to
5
- # either +read+ or +to_s+.
6
- def self.new(duck)
7
- case
8
- when duck.respond_to?(:read)
9
- then Element.new(::REXML::Document.new(duck.read).root)
10
- when duck.respond_to?(:to_s)
11
- then Element.new(::REXML::Document.new(duck.to_s).root)
12
- else raise "Don't know how to deal with '#{duck.class}' object"
13
- end
14
- end
15
-
16
- private ##################################################################
17
-
18
- class Element < XMLObject::Adapters::Base::Element # :nodoc:
19
- def initialize(xml)
20
- @raw, @name, @attributes = xml, xml.name, xml.attributes
21
-
22
- @element_nodes = xml.elements
23
-
24
- @text_nodes = xml.children.select do |child|
25
- child.class == ::REXML::Text
26
- end.map! { |child| child.to_s }
27
-
28
- @cdata_nodes = xml.children.select do |child|
29
- child.class == ::REXML::CData
30
- end.map! { |child| child.to_s }
31
-
32
- super
33
- end
34
- end
4
+ # Can take a String of XML data, or anything that responds to
5
+ # either +read+ or +to_s+.
6
+ def self.new(duck)
7
+ case
8
+ when duck.respond_to?(:read)
9
+ then Element.new(::REXML::Document.new(duck.read).root)
10
+ when duck.respond_to?(:to_s)
11
+ then Element.new(::REXML::Document.new(duck.to_s).root)
12
+ else raise "Don't know how to deal with '#{duck.class}' object"
13
+ end
14
+ end
15
+
16
+ private ##################################################################
17
+
18
+ class Element < XMLObject::Adapters::Base::Element # :nodoc:
19
+ def initialize(xml)
20
+ @raw, @name, @attributes = xml, xml.name, xml.attributes
21
+
22
+ @element_nodes = xml.elements
23
+
24
+ @text_nodes = xml.children.select do |child|
25
+ child.class == ::REXML::Text
26
+ end.map! { |child| child.to_s }
27
+
28
+ @cdata_nodes = xml.children.select do |child|
29
+ child.class == ::REXML::CData
30
+ end.map! { |child| child.to_s }
31
+
32
+ super
33
+ end
34
+ end
35
35
  end
36
36
 
37
37
  ::XMLObject.adapter = ::XMLObject::Adapters::REXML
@@ -1,37 +1,37 @@
1
1
  class XMLObject::CollectionProxy # :nodoc:
2
- instance_methods.each do |m|
3
- meth_str, meth_sym = m.to_s, m.to_sym # Ruby 1.8 and 1.9 differ, so...
2
+ instance_methods.each do |m|
3
+ meth_str, meth_sym = m.to_s, m.to_sym # Ruby 1.8 and 1.9 differ, so...
4
4
 
5
- undef_method meth_sym unless meth_str =~ /^__/ ||
5
+ undef_method meth_sym unless meth_str =~ /^__/ ||
6
6
  meth_str =~ /^instance_/ ||
7
7
  meth_sym == :is_a? ||
8
8
  meth_sym == :kind_of? ||
9
9
  meth_sym == :extend ||
10
10
  meth_sym == :nil? ||
11
11
  meth_sym == :object_id
12
- end
12
+ end
13
13
 
14
- def initialize(xml) # :nodoc:
15
- @__children, @__attributes = {}, {}
16
- @__target_kid = xml.children[0].name.to_sym
17
- end
14
+ def initialize(xml) # :nodoc:
15
+ @__children, @__attributes = {}, {}
16
+ @__target_kid = xml.children[0].name.to_sym
17
+ end
18
18
 
19
- private ##################################################################
19
+ private ##################################################################
20
20
 
21
- def method_missing(m, *a, &b) # :nodoc:
22
- dispatched = __question_dispatch(m, *a, &b)
23
- dispatched = __dot_notation_dispatch(m, *a, &b) if dispatched.nil?
21
+ def method_missing(m, *a, &b) # :nodoc:
22
+ dispatched = __question_dispatch(m, *a, &b)
23
+ dispatched = __dot_notation_dispatch(m, *a, &b) if dispatched.nil?
24
24
 
25
- if dispatched.nil? && @__children[@__target_kid].respond_to?(m)
26
- dispatched = @__children[@__target_kid].__send__(m, *a, &b)
25
+ if dispatched.nil? && @__children[@__target_kid].respond_to?(m)
26
+ dispatched = @__children[@__target_kid].__send__(m, *a, &b)
27
27
 
28
- unless nil == dispatched
29
- # All is fair in Love and War. And 100% coverage.
30
- instance_eval \
31
- %{ def #{m}(*a, &b); @__children[@__target_kid].#{m}(*a, &b); end }
32
- end
33
- end
28
+ unless nil == dispatched
29
+ # All is fair in Love and War. And 100% coverage.
30
+ instance_eval \
31
+ %{ def #{m}(*a, &b); @__children[@__target_kid].#{m}(*a, &b); end }
32
+ end
33
+ end
34
34
 
35
- (nil == dispatched) ? raise(NameError.new(m.to_s)) : dispatched
36
- end
35
+ (nil == dispatched) ? raise(NameError.new(m.to_s)) : dispatched
36
+ end
37
37
  end
@@ -1,24 +1,24 @@
1
1
  module XMLObject::Element
2
- def self.new(xml) # :nodoc:
3
- element = xml.value
4
- element.instance_variable_set :@__raw_xml, xml.raw
5
- element.instance_variable_set :@__children, {}
6
- element.instance_variable_set :@__attributes, {}
7
- element.extend self
8
- end
2
+ def self.new(xml) # :nodoc:
3
+ element = xml.value
4
+ element.instance_variable_set :@__raw_xml, xml.raw
5
+ element.instance_variable_set :@__children, {}
6
+ element.instance_variable_set :@__attributes, {}
7
+ element.extend self
8
+ end
9
9
 
10
- # The raw, unadapted XML object. Whatever this is, it really depends on
11
- # the currently chosen adapter.
12
- def raw_xml
13
- @__raw_xml
14
- end
10
+ # The raw, unadapted XML object. Whatever this is, it really depends on
11
+ # the currently chosen adapter.
12
+ def raw_xml
13
+ @__raw_xml
14
+ end
15
15
 
16
- private ##################################################################
16
+ private ##################################################################
17
17
 
18
- def method_missing(m, *a, &b) # :nodoc:
19
- dispatched = __question_dispatch(m, *a, &b)
20
- dispatched = __dot_notation_dispatch(m, *a, &b) if dispatched.nil?
18
+ def method_missing(m, *a, &b) # :nodoc:
19
+ dispatched = __question_dispatch(m, *a, &b)
20
+ dispatched = __dot_notation_dispatch(m, *a, &b) if dispatched.nil?
21
21
 
22
- dispatched.nil? ? raise(NameError.new(m.to_s)) : dispatched
23
- end
22
+ dispatched.nil? ? raise(NameError.new(m.to_s)) : dispatched
23
+ end
24
24
  end
@@ -1,95 +1,97 @@
1
+ require 'active_support/inflector'
2
+
1
3
  module XMLObject::Properties
2
- # Array-bracket (+[]+) notation access to elements and attributes. Use
3
- # when the element or attribute you need to reach is not reachable via dot
4
- # notation (because it's not a valid method name, or because the method
5
- # exists, such as +id+ or +class+).
6
- #
7
- # It also supports a hash key, which is used to reach attributes named
8
- # the same as elements in the same depth level (which otherwise go first)
9
- #
10
- # All of this is a lot easier to explain by example:
11
- #
12
- # <article id="main_article" author="j-random">
13
- # <author>J. Random Hacker</author>
14
- # </article>
15
- #
16
- # article.id => 9314390 # Object#id
17
- # article[:id] => "main_article" # id attribute
18
- # article[:author] => "J. Random Hacker" # <author> element
19
- # article[:attr => 'author'] => "j-random" # author attribute
20
- #
21
- # Valid keys for the hash notation are +:attr+ and +:elem+.
22
- def [](duck)
23
- if @__target_kid && duck.is_a?(Numeric)
24
- @__children[@__target_kid][duck]
25
- elsif duck.is_a?(Hash)
26
- raise NameError.new('only one key allowed') if duck.keys.size != 1
27
- key, name = duck.keys[0].to_sym, duck.values[0].to_sym
28
-
29
- unless ( (key == :elem) || (:attr == key) )
30
- raise NameError.new("Invalid key :#{key.to_s}. Use :elem or :attr")
31
- end
32
-
33
- value = (key == :elem) ? @__children[name] : @__attributes[name]
34
- value.nil? ? raise(NameError.new(name.to_s)) : value
35
- else
36
- key = duck.to_s.to_sym
37
-
38
- case
39
- when (not @__children[key].nil?) then @__children[key]
40
- when (not @__attributes[key].nil?) then @__attributes[key]
41
- else raise NameError.new(key.to_s)
42
- end
43
- end
44
- end
45
-
46
- private ##################################################################
47
-
48
- def __question_dispatch(meth, *args, &block)
49
- return nil unless meth.to_s.match(/\?$/) && args.empty? && block.nil?
50
-
51
- method_sans_question = meth.to_s.chomp('?').to_sym
52
-
53
- if boolish = __send__(method_sans_question)
54
- bool = case
55
- when %w[ true yes t y ].include?(boolish.downcase) then true
56
- when %w[ false no f n ].include?(boolish.downcase) then false
57
- else nil
58
- end
59
-
60
- unless bool.nil?
61
- instance_eval %{ def #{meth}; #{bool ? 'true' : 'false'}; end }
62
- end
63
-
64
- bool
65
- end
66
- end
67
-
68
- def __dot_notation_dispatch(meth, *args, &block)
69
- return nil unless args.empty? && block.nil?
70
-
71
- if @__children.has_key?(meth)
72
- instance_eval %{ def #{meth}; @__children[%s|#{meth}|]; end }
73
- @__children[meth]
74
-
75
- elsif @__attributes.has_key?(meth)
76
- instance_eval %{ def #{meth}; @__attributes[%s|#{meth}|]; end }
77
- @__attributes[meth]
78
-
79
- elsif @__children.has_key?(naive_sing = meth.to_s.chomp('s').to_sym) &&
80
- @__children[naive_sing].is_a?(Array)
81
-
82
- instance_eval %{ def #{meth}; @__children[%s|#{naive_sing}|]; end }
83
- @__children[naive_sing]
84
-
85
- elsif defined?(ActiveSupport::Inflector) &&
86
- @__children.has_key?(singular = meth.to_s.singularize.to_sym) &&
87
- @__children[singular].is_a?(Array)
88
-
89
- instance_eval %{ def #{meth}; @__children[%s|#{singular}|]; end }
90
- @__children[singular]
91
- else
92
- nil
93
- end
94
- end
95
- end
4
+ # Array-bracket (+[]+) notation access to elements and attributes. Use
5
+ # when the element or attribute you need to reach is not reachable via dot
6
+ # notation (because it's not a valid method name, or because the method
7
+ # exists, such as +id+ or +class+).
8
+ #
9
+ # It also supports a hash key, which is used to reach attributes named
10
+ # the same as elements in the same depth level (which otherwise go first)
11
+ #
12
+ # All of this is a lot easier to explain by example:
13
+ #
14
+ # <article id="main_article" author="j-random">
15
+ # <author>J. Random Hacker</author>
16
+ # </article>
17
+ #
18
+ # article.id => 9314390 # Object#id
19
+ # article[:id] => "main_article" # id attribute
20
+ # article[:author] => "J. Random Hacker" # <author> element
21
+ # article[:attr => 'author'] => "j-random" # author attribute
22
+ #
23
+ # Valid keys for the hash notation are +:attr+ and +:elem+.
24
+ def [](duck)
25
+ if @__target_kid && duck.is_a?(Numeric)
26
+ @__children[@__target_kid][duck]
27
+ elsif duck.is_a?(Hash)
28
+ raise NameError.new('only one key allowed') if duck.keys.size != 1
29
+ key, name = duck.keys[0].to_sym, duck.values[0].to_sym
30
+
31
+ unless ( (key == :elem) || (:attr == key) )
32
+ raise NameError.new("Invalid key :#{key.to_s}. Use :elem or :attr")
33
+ end
34
+
35
+ value = (key == :elem) ? @__children[name] : @__attributes[name]
36
+ value.nil? ? raise(NameError.new(name.to_s)) : value
37
+ else
38
+ key = duck.to_s.to_sym
39
+
40
+ case
41
+ when (not @__children[key].nil?) then @__children[key]
42
+ when (not @__attributes[key].nil?) then @__attributes[key]
43
+ else raise NameError.new(key.to_s)
44
+ end
45
+ end
46
+ end
47
+
48
+ private ##################################################################
49
+
50
+ def __question_dispatch(meth, *args, &block)
51
+ return nil unless meth.to_s.match(/\?$/) && args.empty? && block.nil?
52
+
53
+ method_sans_question = meth.to_s.chomp('?').to_sym
54
+
55
+ if boolish = __send__(method_sans_question)
56
+ bool = case
57
+ when %w[ true yes t y ].include?(boolish.downcase) then true
58
+ when %w[ false no f n ].include?(boolish.downcase) then false
59
+ else nil
60
+ end
61
+
62
+ unless bool.nil?
63
+ instance_eval %{ def #{meth}; #{bool ? 'true' : 'false'}; end }
64
+ end
65
+
66
+ bool
67
+ end
68
+ end
69
+
70
+ def __dot_notation_dispatch(meth, *args, &block)
71
+ return nil unless args.empty? && block.nil?
72
+
73
+ if @__children.has_key?(meth)
74
+ instance_eval %{ def #{meth}; @__children[%s|#{meth}|]; end }
75
+ @__children[meth]
76
+
77
+ elsif @__attributes.has_key?(meth)
78
+ instance_eval %{ def #{meth}; @__attributes[%s|#{meth}|]; end }
79
+ @__attributes[meth]
80
+
81
+ elsif @__children.has_key?(naive_sing = meth.to_s.chomp('s').to_sym) &&
82
+ @__children[naive_sing].is_a?(Array)
83
+
84
+ instance_eval %{ def #{meth}; @__children[%s|#{naive_sing}|]; end }
85
+ @__children[naive_sing]
86
+
87
+ elsif (singular = ActiveSupport::Inflector.singularize(meth.to_s)) &&
88
+ @__children.has_key?(singular.to_sym) &&
89
+ @__children[singular.to_sym].is_a?(Array)
90
+
91
+ instance_eval %{ def #{meth}; @__children[%s|#{singular}|]; end }
92
+ @__children[singular.to_sym]
93
+ else
94
+ nil
95
+ end
96
+ end
97
+ end
@@ -1,4 +1,4 @@
1
1
  module XMLObject
2
- VERSION = '0.9.93'
3
- LOCATION = File.dirname __FILE__ # :nodoc:
4
- end
2
+ VERSION = '1.0.0'
3
+ LOCATION = File.dirname __FILE__ # :nodoc:
4
+ end
@@ -1,4 +1,4 @@
1
- require 'lib/xml-object/version'
1
+ require './lib/xml-object/version'
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'xml-object'
@@ -12,7 +12,11 @@ Gem::Specification.new do |gem|
12
12
  documents of a known structure. While not devoid of caveats, it does
13
13
  have a very pleasant, idiomatic Ruby syntax. }.strip!.gsub! /\s+/, ' '
14
14
 
15
- gem.required_ruby_version = '>= 1.8.6'
15
+ gem.required_ruby_version = '>= 1.9.3'
16
+
17
+ gem.add_dependency 'activesupport'
18
+ gem.add_development_dependency 'minitest'
19
+ gem.add_development_dependency 'rake'
16
20
 
17
21
  gem.has_rdoc = true
18
22
  gem.extra_rdoc_files = %w[ README.rdoc MIT-LICENSE WHATSNEW ]
@@ -37,4 +41,4 @@ Gem::Specification.new do |gem|
37
41
  lib/xml-object.rb
38
42
  xml-object.gemspec
39
43
  ]
40
- end
44
+ end
metadata CHANGED
@@ -1,35 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: xml-object
3
- version: !ruby/object:Gem::Version
4
- hash: 129
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 9
9
- - 93
10
- version: 0.9.93
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Jordi Bunster
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2010-08-26 00:00:00 -07:00
19
- default_executable:
20
- dependencies: []
21
-
22
- description: XMLObject is a library for reading (not writing) XML. It is particularly suited for cases where one is dealing with small documents of a known structure. While not devoid of caveats, it does have a very pleasant, idiomatic Ruby syntax.
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: XMLObject is a library for reading (not writing) XML. It is particularly
56
+ suited for cases where one is dealing with small documents of a known structure.
57
+ While not devoid of caveats, it does have a very pleasant, idiomatic Ruby syntax.
23
58
  email: jordi@bunster.org
24
59
  executables: []
25
-
26
60
  extensions: []
27
-
28
- extra_rdoc_files:
61
+ extra_rdoc_files:
29
62
  - README.rdoc
30
63
  - MIT-LICENSE
31
64
  - WHATSNEW
32
- files:
65
+ files:
33
66
  - MIT-LICENSE
34
67
  - README.rdoc
35
68
  - TODO
@@ -43,45 +76,32 @@ files:
43
76
  - lib/xml-object/properties.rb
44
77
  - lib/xml-object.rb
45
78
  - xml-object.gemspec
46
- has_rdoc: true
47
79
  homepage:
48
80
  licenses: []
49
-
81
+ metadata: {}
50
82
  post_install_message:
51
- rdoc_options:
83
+ rdoc_options:
52
84
  - --title
53
85
  - XMLObject
54
86
  - --main
55
87
  - README.rdoc
56
88
  - --inline-source
57
- require_paths:
89
+ require_paths:
58
90
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 59
65
- segments:
66
- - 1
67
- - 8
68
- - 6
69
- version: 1.8.6
70
- required_rubygems_version: !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: 1.9.3
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
79
101
  requirements: []
80
-
81
102
  rubyforge_project:
82
- rubygems_version: 1.3.7
103
+ rubygems_version: 2.0.14
83
104
  signing_key:
84
- specification_version: 3
105
+ specification_version: 4
85
106
  summary: The Rubyista's way to do quick XML sit-ups
86
107
  test_files: []
87
-