activesupport 2.3.5 → 2.3.6.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- data/CHANGELOG +23 -0
- data/lib/active_support.rb +1 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +14 -3
- data/lib/active_support/core_ext/enumerable.rb +6 -0
- data/lib/active_support/core_ext/file/atomic.rb +2 -1
- data/lib/active_support/core_ext/numeric/conversions.rb +2 -2
- data/lib/active_support/core_ext/object.rb +1 -0
- data/lib/active_support/core_ext/object/metaclass.rb +6 -5
- data/lib/active_support/core_ext/object/singleton_class.rb +13 -0
- data/lib/active_support/core_ext/string.rb +0 -1
- data/lib/active_support/core_ext/string/output_safety.rb +148 -44
- data/lib/active_support/core_ext/time/calculations.rb +1 -1
- data/lib/active_support/inflector.rb +1 -1
- data/lib/active_support/json/backends/yajl.rb +40 -0
- data/lib/active_support/json/decoding.rb +16 -1
- data/lib/active_support/json/encoding.rb +11 -2
- data/lib/active_support/ordered_hash.rb +24 -1
- data/lib/active_support/vendor.rb +10 -2
- data/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile +76 -0
- data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/MIT-LICENSE +0 -0
- data/lib/active_support/vendor/i18n-0.3.3/README.textile +81 -0
- data/lib/active_support/vendor/i18n-0.3.3/Rakefile +24 -0
- data/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml +144 -0
- data/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb +71 -0
- data/lib/active_support/vendor/i18n-0.3.3/contributors.txt +17 -0
- data/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec +165 -0
- data/lib/active_support/vendor/i18n-0.3.3/init.rb +1 -0
- data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n.rb +99 -21
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend.rb +17 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record.rb +70 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/missing.rb +67 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/store_procs.rb +38 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/translation.rb +83 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/base.rb +259 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cache.rb +75 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cascade.rb +44 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/chain.rb +74 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fallbacks.rb +52 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fast.rb +68 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/gettext.rb +75 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/helpers.rb +80 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/interpolation_compiler.rb +119 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/metadata.rb +73 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/pluralization.rb +57 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/simple.rb +22 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/object/meta_class.rb +5 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/string/interpolate.rb +99 -0
- data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n/exceptions.rb +14 -6
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/gettext.rb +25 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers.rb +5 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers/gettext.rb +64 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale.rb +6 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/fallbacks.rb +98 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag.rb +28 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/parents.rb +24 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/rfc4646.rb +76 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/simple.rb +41 -0
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb +3 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/all.rb +8 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb +15 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb +40 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb +92 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/link.rb +55 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb +91 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb +90 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb +54 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb +84 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb +45 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb +35 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb +40 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb +29 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb +40 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb +31 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb +26 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb +33 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb +31 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb +33 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb +21 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb +60 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb +52 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb +72 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb +66 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb +64 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb +57 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb +50 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb +26 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb +107 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb +67 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb +43 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb +77 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb +94 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb +201 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb +91 -0
- data/lib/active_support/vendor/{i18n-0.1.3/test → i18n-0.3.3/test/cases}/i18n_exceptions_test.rb +8 -10
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb +23 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb +172 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb +126 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb +143 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb +33 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po +72 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb +3 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml +3 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb +113 -0
- data/lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb +100 -0
- data/lib/active_support/vendor/i18n-0.3.3/vendor/po_parser.rb +329 -0
- data/lib/active_support/version.rb +1 -1
- data/lib/active_support/whiny_nil.rb +1 -1
- data/lib/active_support/xml_mini/libxml.rb +23 -83
- data/lib/active_support/xml_mini/libxmlsax.rb +74 -0
- data/lib/active_support/xml_mini/nokogiri.rb +25 -22
- data/lib/active_support/xml_mini/nokogirisax.rb +73 -0
- metadata +108 -20
- data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
- data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
- data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
- data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -214
- data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
- data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
- data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
@@ -45,7 +45,7 @@ class NilClass
|
|
45
45
|
def method_missing(method, *args, &block)
|
46
46
|
# Ruby 1.9.2: disallow explicit coercion via method_missing.
|
47
47
|
if method == :to_ary || method == :to_str
|
48
|
-
|
48
|
+
raise NoMethodError, "undefined method `#{method}' for nil:NilClass"
|
49
49
|
elsif klass = METHOD_CLASS_MAP[method]
|
50
50
|
raise_nil_warning_for klass, method, caller
|
51
51
|
else
|
@@ -9,15 +9,12 @@ module ActiveSupport
|
|
9
9
|
# string::
|
10
10
|
# XML Document string to parse
|
11
11
|
def parse(string)
|
12
|
-
LibXML::XML.default_keep_blanks = false
|
13
|
-
|
14
12
|
if string.blank?
|
15
13
|
{}
|
16
14
|
else
|
17
15
|
LibXML::XML::Parser.string(string.strip).parse.to_hash
|
18
16
|
end
|
19
17
|
end
|
20
|
-
|
21
18
|
end
|
22
19
|
end
|
23
20
|
|
@@ -30,101 +27,44 @@ module LibXML
|
|
30
27
|
end
|
31
28
|
|
32
29
|
module Node
|
33
|
-
CONTENT_ROOT = '__content__'
|
34
|
-
LIB_XML_LIMIT = 30000000 # Hardcoded LibXML limit
|
30
|
+
CONTENT_ROOT = '__content__'.freeze
|
35
31
|
|
36
32
|
# Convert XML document to hash
|
37
33
|
#
|
38
34
|
# hash::
|
39
35
|
# Hash to merge the converted element into.
|
40
36
|
def to_hash(hash={})
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
elsif yaml?
|
50
|
-
children_yaml_to_hash(sub_hash)
|
51
|
-
else
|
52
|
-
children_to_hash(sub_hash)
|
53
|
-
end
|
37
|
+
node_hash = {}
|
38
|
+
|
39
|
+
# Insert node hash into parent hash correctly.
|
40
|
+
case hash[name]
|
41
|
+
when Array then hash[name] << node_hash
|
42
|
+
when Hash then hash[name] = [hash[name], node_hash]
|
43
|
+
when nil then hash[name] = node_hash
|
44
|
+
else raise "Unexpected error during hash insertion!"
|
54
45
|
end
|
55
|
-
hash
|
56
|
-
end
|
57
46
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
# name to to merge into hash
|
66
|
-
def insert_name_into_hash(hash, name)
|
67
|
-
sub_hash = {}
|
68
|
-
if hash[name]
|
69
|
-
if !hash[name].kind_of? Array
|
70
|
-
hash[name] = [hash[name]]
|
71
|
-
end
|
72
|
-
hash[name] << sub_hash
|
73
|
-
else
|
74
|
-
hash[name] = sub_hash
|
47
|
+
# Handle child elements
|
48
|
+
each_child do |c|
|
49
|
+
if c.element?
|
50
|
+
c.to_hash(node_hash)
|
51
|
+
elsif c.text? || c.cdata?
|
52
|
+
node_hash[CONTENT_ROOT] ||= ''
|
53
|
+
node_hash[CONTENT_ROOT] << c.content
|
75
54
|
end
|
76
|
-
sub_hash
|
77
55
|
end
|
78
56
|
|
79
|
-
# Insert children into hash
|
80
|
-
#
|
81
|
-
# hash::
|
82
|
-
# Hash to merge the children into.
|
83
|
-
def children_to_hash(hash={})
|
84
|
-
each { |child| child.to_hash(hash) }
|
85
|
-
attributes_to_hash(hash)
|
86
|
-
hash
|
87
|
-
end
|
88
57
|
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
# Hash to merge the attributes into
|
93
|
-
def attributes_to_hash(hash={})
|
94
|
-
each_attr { |attr| hash[attr.name] = attr.value }
|
95
|
-
hash
|
58
|
+
# Remove content node if it is blank
|
59
|
+
if node_hash.length > 1 && node_hash[CONTENT_ROOT].blank?
|
60
|
+
node_hash.delete(CONTENT_ROOT)
|
96
61
|
end
|
97
62
|
|
98
|
-
#
|
99
|
-
|
100
|
-
# hash::
|
101
|
-
# Hash to merge the array into
|
102
|
-
def children_array_to_hash(hash={})
|
103
|
-
hash[child.name] = map do |child|
|
104
|
-
returning({}) { |sub_hash| child.children_to_hash(sub_hash) }
|
105
|
-
end
|
106
|
-
hash
|
107
|
-
end
|
108
|
-
|
109
|
-
# Convert yaml into hash
|
110
|
-
#
|
111
|
-
# hash::
|
112
|
-
# Hash to merge the yaml into
|
113
|
-
def children_yaml_to_hash(hash = {})
|
114
|
-
hash[CONTENT_ROOT] = content unless content.blank?
|
115
|
-
hash
|
116
|
-
end
|
117
|
-
|
118
|
-
# Check if child is of type array
|
119
|
-
def array?
|
120
|
-
child? && child.next? && child.name == child.next.name
|
121
|
-
end
|
122
|
-
|
123
|
-
# Check if child is of type yaml
|
124
|
-
def yaml?
|
125
|
-
attributes.collect{|x| x.value}.include?('yaml')
|
126
|
-
end
|
63
|
+
# Handle attributes
|
64
|
+
each_attr { |a| node_hash[a.name] = a.value }
|
127
65
|
|
66
|
+
hash
|
67
|
+
end
|
128
68
|
end
|
129
69
|
end
|
130
70
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'libxml'
|
2
|
+
|
3
|
+
# = XmlMini LibXML implementation using a SAX-based parser
|
4
|
+
module ActiveSupport
|
5
|
+
module XmlMini_LibXMLSAX
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# Class that will build the hash while the XML document
|
9
|
+
# is being parsed using SAX events.
|
10
|
+
class HashBuilder
|
11
|
+
|
12
|
+
include LibXML::XML::SaxParser::Callbacks
|
13
|
+
|
14
|
+
CONTENT_KEY = '__content__'.freeze
|
15
|
+
HASH_SIZE_KEY = '__hash_size__'.freeze
|
16
|
+
|
17
|
+
attr_reader :hash
|
18
|
+
|
19
|
+
def current_hash
|
20
|
+
@hash_stack.last
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_start_document
|
24
|
+
@hash = { CONTENT_KEY => '' }
|
25
|
+
@hash_stack = [@hash]
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_end_document
|
29
|
+
@hash = @hash_stack.pop
|
30
|
+
@hash.delete(CONTENT_KEY)
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_start_element(name, attrs = {})
|
34
|
+
new_hash = { CONTENT_KEY => '' }.merge(attrs)
|
35
|
+
new_hash[HASH_SIZE_KEY] = new_hash.size + 1
|
36
|
+
|
37
|
+
case current_hash[name]
|
38
|
+
when Array then current_hash[name] << new_hash
|
39
|
+
when Hash then current_hash[name] = [current_hash[name], new_hash]
|
40
|
+
when nil then current_hash[name] = new_hash
|
41
|
+
end
|
42
|
+
|
43
|
+
@hash_stack.push(new_hash)
|
44
|
+
end
|
45
|
+
|
46
|
+
def on_end_element(name)
|
47
|
+
if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ''
|
48
|
+
current_hash.delete(CONTENT_KEY)
|
49
|
+
end
|
50
|
+
@hash_stack.pop
|
51
|
+
end
|
52
|
+
|
53
|
+
def on_characters(string)
|
54
|
+
current_hash[CONTENT_KEY] << string
|
55
|
+
end
|
56
|
+
|
57
|
+
alias_method :on_cdata_block, :on_characters
|
58
|
+
end
|
59
|
+
|
60
|
+
attr_accessor :document_class
|
61
|
+
self.document_class = HashBuilder
|
62
|
+
|
63
|
+
def parse(string)
|
64
|
+
return {} if string.blank?
|
65
|
+
LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
|
66
|
+
parser = LibXML::XML::SaxParser.string(string)
|
67
|
+
document = self.document_class.new
|
68
|
+
|
69
|
+
parser.callbacks = document
|
70
|
+
parser.parse
|
71
|
+
document.hash
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -12,7 +12,7 @@ module ActiveSupport
|
|
12
12
|
if string.blank?
|
13
13
|
{}
|
14
14
|
else
|
15
|
-
doc = Nokogiri::XML(string)
|
15
|
+
doc = Nokogiri::XML(string)
|
16
16
|
raise doc.errors.first if doc.errors.length > 0
|
17
17
|
doc.to_hash
|
18
18
|
end
|
@@ -26,40 +26,43 @@ module ActiveSupport
|
|
26
26
|
end
|
27
27
|
|
28
28
|
module Node
|
29
|
-
CONTENT_ROOT = '__content__'
|
29
|
+
CONTENT_ROOT = '__content__'.freeze
|
30
30
|
|
31
31
|
# Convert XML document to hash
|
32
32
|
#
|
33
33
|
# hash::
|
34
34
|
# Hash to merge the converted element into.
|
35
35
|
def to_hash(hash = {})
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
hash[name]
|
36
|
+
node_hash = {}
|
37
|
+
|
38
|
+
# Insert node hash into parent hash correctly.
|
39
|
+
case hash[name]
|
40
|
+
when Array then hash[name] << node_hash
|
41
|
+
when Hash then hash[name] = [hash[name], node_hash]
|
42
|
+
when nil then hash[name] = node_hash
|
43
|
+
else raise "Unexpected error during hash insertion!"
|
42
44
|
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
+
# Handle child elements
|
47
|
+
children.each do |c|
|
48
|
+
if c.element?
|
49
|
+
c.to_hash(node_hash)
|
50
|
+
elsif c.text? || c.cdata?
|
51
|
+
node_hash[CONTENT_ROOT] ||= ''
|
52
|
+
node_hash[CONTENT_ROOT] << c.content
|
53
|
+
end
|
54
|
+
end
|
46
55
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
56
|
+
# Remove content node if it is blank and there are child tags
|
57
|
+
if node_hash.length > 1 && node_hash[CONTENT_ROOT].blank?
|
58
|
+
node_hash.delete(CONTENT_ROOT)
|
59
|
+
end
|
51
60
|
|
52
|
-
|
53
|
-
}
|
61
|
+
# Handle attributes
|
62
|
+
attribute_nodes.each { |a| node_hash[a.node_name] = a.value }
|
54
63
|
|
55
64
|
hash
|
56
65
|
end
|
57
|
-
|
58
|
-
def attributes_as_hash
|
59
|
-
Hash[*(attribute_nodes.map { |node|
|
60
|
-
[node.node_name, node.value]
|
61
|
-
}.flatten)]
|
62
|
-
end
|
63
66
|
end
|
64
67
|
end
|
65
68
|
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
# = XmlMini Nokogiri implementation using a SAX-based parser
|
4
|
+
module ActiveSupport
|
5
|
+
module XmlMini_NokogiriSAX
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# Class that will build the hash while the XML document
|
9
|
+
# is being parsed using SAX events.
|
10
|
+
class HashBuilder < Nokogiri::XML::SAX::Document
|
11
|
+
|
12
|
+
CONTENT_KEY = '__content__'.freeze
|
13
|
+
HASH_SIZE_KEY = '__hash_size__'.freeze
|
14
|
+
|
15
|
+
attr_reader :hash
|
16
|
+
|
17
|
+
def current_hash
|
18
|
+
@hash_stack.last
|
19
|
+
end
|
20
|
+
|
21
|
+
def start_document
|
22
|
+
@hash = {}
|
23
|
+
@hash_stack = [@hash]
|
24
|
+
end
|
25
|
+
|
26
|
+
def end_document
|
27
|
+
raise "Parse stack not empty!" if @hash_stack.size > 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def error(error_message)
|
31
|
+
raise error_message
|
32
|
+
end
|
33
|
+
|
34
|
+
def start_element(name, attrs = [])
|
35
|
+
new_hash = { CONTENT_KEY => '' }
|
36
|
+
new_hash[attrs.shift] = attrs.shift while attrs.length > 0
|
37
|
+
new_hash[HASH_SIZE_KEY] = new_hash.size + 1
|
38
|
+
|
39
|
+
case current_hash[name]
|
40
|
+
when Array then current_hash[name] << new_hash
|
41
|
+
when Hash then current_hash[name] = [current_hash[name], new_hash]
|
42
|
+
when nil then current_hash[name] = new_hash
|
43
|
+
end
|
44
|
+
|
45
|
+
@hash_stack.push(new_hash)
|
46
|
+
end
|
47
|
+
|
48
|
+
def end_element(name)
|
49
|
+
if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ''
|
50
|
+
current_hash.delete(CONTENT_KEY)
|
51
|
+
end
|
52
|
+
@hash_stack.pop
|
53
|
+
end
|
54
|
+
|
55
|
+
def characters(string)
|
56
|
+
current_hash[CONTENT_KEY] << string
|
57
|
+
end
|
58
|
+
|
59
|
+
alias_method :cdata_block, :characters
|
60
|
+
end
|
61
|
+
|
62
|
+
attr_accessor :document_class
|
63
|
+
self.document_class = HashBuilder
|
64
|
+
|
65
|
+
def parse(string)
|
66
|
+
return {} if string.blank?
|
67
|
+
document = self.document_class.new
|
68
|
+
parser = Nokogiri::XML::SAX::Parser.new(document)
|
69
|
+
parser.parse(string)
|
70
|
+
document.hash
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: true
|
5
|
+
segments:
|
6
|
+
- 2
|
7
|
+
- 3
|
8
|
+
- 6
|
9
|
+
- pre
|
10
|
+
version: 2.3.6.pre
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- David Heinemeier Hansson
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-03-07 00:00:00 -08:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -116,6 +122,7 @@ files:
|
|
116
122
|
- lib/active_support/core_ext/object/instance_variables.rb
|
117
123
|
- lib/active_support/core_ext/object/metaclass.rb
|
118
124
|
- lib/active_support/core_ext/object/misc.rb
|
125
|
+
- lib/active_support/core_ext/object/singleton_class.rb
|
119
126
|
- lib/active_support/core_ext/object.rb
|
120
127
|
- lib/active_support/core_ext/pathname/clean_within.rb
|
121
128
|
- lib/active_support/core_ext/pathname.rb
|
@@ -156,6 +163,7 @@ files:
|
|
156
163
|
- lib/active_support/inflections.rb
|
157
164
|
- lib/active_support/inflector.rb
|
158
165
|
- lib/active_support/json/backends/jsongem.rb
|
166
|
+
- lib/active_support/json/backends/yajl.rb
|
159
167
|
- lib/active_support/json/backends/yaml.rb
|
160
168
|
- lib/active_support/json/decoding.rb
|
161
169
|
- lib/active_support/json/encoders/date.rb
|
@@ -207,19 +215,93 @@ files:
|
|
207
215
|
- lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb
|
208
216
|
- lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb
|
209
217
|
- lib/active_support/vendor/builder-2.1.2/builder.rb
|
210
|
-
- lib/active_support/vendor/i18n-0.
|
211
|
-
- lib/active_support/vendor/i18n-0.
|
212
|
-
- lib/active_support/vendor/i18n-0.
|
213
|
-
- lib/active_support/vendor/i18n-0.
|
214
|
-
- lib/active_support/vendor/i18n-0.
|
215
|
-
- lib/active_support/vendor/i18n-0.
|
216
|
-
- lib/active_support/vendor/i18n-0.
|
217
|
-
- lib/active_support/vendor/i18n-0.
|
218
|
-
- lib/active_support/vendor/i18n-0.
|
219
|
-
- lib/active_support/vendor/i18n-0.
|
220
|
-
- lib/active_support/vendor/i18n-0.
|
221
|
-
- lib/active_support/vendor/i18n-0.
|
222
|
-
- lib/active_support/vendor/i18n-0.
|
218
|
+
- lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml
|
219
|
+
- lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb
|
220
|
+
- lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile
|
221
|
+
- lib/active_support/vendor/i18n-0.3.3/contributors.txt
|
222
|
+
- lib/active_support/vendor/i18n-0.3.3/i18n.gemspec
|
223
|
+
- lib/active_support/vendor/i18n-0.3.3/init.rb
|
224
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/missing.rb
|
225
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/store_procs.rb
|
226
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/translation.rb
|
227
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record.rb
|
228
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/base.rb
|
229
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cache.rb
|
230
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cascade.rb
|
231
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/chain.rb
|
232
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fallbacks.rb
|
233
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fast.rb
|
234
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/gettext.rb
|
235
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/helpers.rb
|
236
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/interpolation_compiler.rb
|
237
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/metadata.rb
|
238
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/pluralization.rb
|
239
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/simple.rb
|
240
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend.rb
|
241
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/object/meta_class.rb
|
242
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/string/interpolate.rb
|
243
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/exceptions.rb
|
244
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/gettext.rb
|
245
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers/gettext.rb
|
246
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers.rb
|
247
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/fallbacks.rb
|
248
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/parents.rb
|
249
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/rfc4646.rb
|
250
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/simple.rb
|
251
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag.rb
|
252
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale.rb
|
253
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb
|
254
|
+
- lib/active_support/vendor/i18n-0.3.3/lib/i18n.rb
|
255
|
+
- lib/active_support/vendor/i18n-0.3.3/MIT-LICENSE
|
256
|
+
- lib/active_support/vendor/i18n-0.3.3/Rakefile
|
257
|
+
- lib/active_support/vendor/i18n-0.3.3/README.textile
|
258
|
+
- lib/active_support/vendor/i18n-0.3.3/test/all.rb
|
259
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb
|
260
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb
|
261
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb
|
262
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/link.rb
|
263
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb
|
264
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb
|
265
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb
|
266
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb
|
267
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb
|
268
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb
|
269
|
+
- lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb
|
270
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb
|
271
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb
|
272
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb
|
273
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb
|
274
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb
|
275
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb
|
276
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb
|
277
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb
|
278
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb
|
279
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb
|
280
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb
|
281
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb
|
282
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb
|
283
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb
|
284
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb
|
285
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb
|
286
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb
|
287
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb
|
288
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb
|
289
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb
|
290
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb
|
291
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb
|
292
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb
|
293
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_exceptions_test.rb
|
294
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb
|
295
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb
|
296
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb
|
297
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb
|
298
|
+
- lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb
|
299
|
+
- lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po
|
300
|
+
- lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb
|
301
|
+
- lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml
|
302
|
+
- lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb
|
303
|
+
- lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb
|
304
|
+
- lib/active_support/vendor/i18n-0.3.3/vendor/po_parser.rb
|
223
305
|
- lib/active_support/vendor/memcache-client-1.7.4/memcache.rb
|
224
306
|
- lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb
|
225
307
|
- lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb
|
@@ -364,7 +446,9 @@ files:
|
|
364
446
|
- lib/active_support/whiny_nil.rb
|
365
447
|
- lib/active_support/xml_mini/jdom.rb
|
366
448
|
- lib/active_support/xml_mini/libxml.rb
|
449
|
+
- lib/active_support/xml_mini/libxmlsax.rb
|
367
450
|
- lib/active_support/xml_mini/nokogiri.rb
|
451
|
+
- lib/active_support/xml_mini/nokogirisax.rb
|
368
452
|
- lib/active_support/xml_mini/rexml.rb
|
369
453
|
- lib/active_support/xml_mini.rb
|
370
454
|
- lib/active_support.rb
|
@@ -382,18 +466,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
382
466
|
requirements:
|
383
467
|
- - ">="
|
384
468
|
- !ruby/object:Gem::Version
|
469
|
+
segments:
|
470
|
+
- 0
|
385
471
|
version: "0"
|
386
|
-
version:
|
387
472
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
388
473
|
requirements:
|
389
|
-
- - "
|
474
|
+
- - ">"
|
390
475
|
- !ruby/object:Gem::Version
|
391
|
-
|
392
|
-
|
476
|
+
segments:
|
477
|
+
- 1
|
478
|
+
- 3
|
479
|
+
- 1
|
480
|
+
version: 1.3.1
|
393
481
|
requirements: []
|
394
482
|
|
395
483
|
rubyforge_project: activesupport
|
396
|
-
rubygems_version: 1.3.
|
484
|
+
rubygems_version: 1.3.6
|
397
485
|
signing_key:
|
398
486
|
specification_version: 3
|
399
487
|
summary: Support and utility classes used by the Rails framework.
|