activesupport 2.3.2 → 2.3.3

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.

Files changed (43) hide show
  1. data/CHANGELOG +7 -0
  2. data/lib/active_support/cache.rb +14 -1
  3. data/lib/active_support/cache/mem_cache_store.rb +16 -10
  4. data/lib/active_support/cache/strategy/local_cache.rb +1 -1
  5. data/lib/active_support/core_ext/date/calculations.rb +1 -1
  6. data/lib/active_support/core_ext/hash/conversions.rb +13 -4
  7. data/lib/active_support/core_ext/kernel/debugger.rb +4 -2
  8. data/lib/active_support/core_ext/module/attribute_accessors.rb +2 -0
  9. data/lib/active_support/core_ext/module/delegation.rb +12 -3
  10. data/lib/active_support/core_ext/module/model_naming.rb +8 -6
  11. data/lib/active_support/core_ext/numeric/bytes.rb +15 -9
  12. data/lib/active_support/core_ext/string/access.rb +29 -5
  13. data/lib/active_support/duration.rb +4 -2
  14. data/lib/active_support/json.rb +1 -22
  15. data/lib/active_support/json/backends/jsongem.rb +38 -0
  16. data/lib/active_support/json/backends/yaml.rb +85 -0
  17. data/lib/active_support/json/decoding.rb +23 -72
  18. data/lib/active_support/json/encoders/date.rb +9 -8
  19. data/lib/active_support/json/encoders/date_time.rb +9 -8
  20. data/lib/active_support/json/encoders/enumerable.rb +14 -9
  21. data/lib/active_support/json/encoders/false_class.rb +4 -2
  22. data/lib/active_support/json/encoders/hash.rb +21 -11
  23. data/lib/active_support/json/encoders/nil_class.rb +4 -2
  24. data/lib/active_support/json/encoders/numeric.rb +16 -0
  25. data/lib/active_support/json/encoders/object.rb +6 -2
  26. data/lib/active_support/json/encoders/regexp.rb +4 -0
  27. data/lib/active_support/json/encoders/string.rb +5 -32
  28. data/lib/active_support/json/encoders/symbol.rb +2 -2
  29. data/lib/active_support/json/encoders/time.rb +9 -8
  30. data/lib/active_support/json/encoders/true_class.rb +4 -2
  31. data/lib/active_support/json/encoding.rb +80 -9
  32. data/lib/active_support/ordered_hash.rb +28 -0
  33. data/lib/active_support/test_case.rb +7 -7
  34. data/lib/active_support/testing/deprecation.rb +2 -0
  35. data/lib/active_support/time_with_zone.rb +9 -8
  36. data/lib/active_support/vendor.rb +6 -7
  37. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +0 -1
  38. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -1
  39. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -1
  40. data/lib/active_support/vendor/{memcache-client-1.6.5 → memcache-client-1.7.4}/memcache.rb +242 -70
  41. data/lib/active_support/version.rb +1 -1
  42. data/lib/active_support/xml_mini/jdom.rb +162 -0
  43. metadata +10 -4
@@ -2,7 +2,7 @@ module ActiveSupport
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 3
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,162 @@
1
+ raise "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM =~ /java/
2
+
3
+ require 'jruby'
4
+ include Java
5
+
6
+ import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder
7
+ import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory
8
+ import java.io.StringReader unless defined? StringReader
9
+ import org.xml.sax.InputSource unless defined? InputSource
10
+ import org.xml.sax.Attributes unless defined? Attributes
11
+ import org.w3c.dom.Node unless defined? Node
12
+
13
+ # = XmlMini JRuby JDOM implementation
14
+ module ActiveSupport
15
+ module XmlMini_JDOM #:nodoc:
16
+ extend self
17
+
18
+ CONTENT_KEY = '__content__'.freeze
19
+
20
+ NODE_TYPE_NAMES = %w{ATTRIBUTE_NODE CDATA_SECTION_NODE COMMENT_NODE DOCUMENT_FRAGMENT_NODE
21
+ DOCUMENT_NODE DOCUMENT_TYPE_NODE ELEMENT_NODE ENTITY_NODE ENTITY_REFERENCE_NODE NOTATION_NODE
22
+ PROCESSING_INSTRUCTION_NODE TEXT_NODE}
23
+
24
+ node_type_map = {}
25
+ NODE_TYPE_NAMES.each { |type| node_type_map[Node.send(type)] = type }
26
+
27
+ # Parse an XML Document string into a simple hash using Java's jdom.
28
+ # string::
29
+ # XML Document string to parse
30
+ def parse(string)
31
+ if string.blank?
32
+ {}
33
+ else
34
+ @dbf = DocumentBuilderFactory.new_instance
35
+ xml_string_reader = StringReader.new(string)
36
+ xml_input_source = InputSource.new(xml_string_reader)
37
+ doc = @dbf.new_document_builder.parse(xml_input_source)
38
+ merge_element!({}, doc.document_element)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ # Convert an XML element and merge into the hash
45
+ #
46
+ # hash::
47
+ # Hash to merge the converted element into.
48
+ # element::
49
+ # XML element to merge into hash
50
+ def merge_element!(hash, element)
51
+ merge!(hash, element.tag_name, collapse(element))
52
+ end
53
+
54
+ # Actually converts an XML document element into a data structure.
55
+ #
56
+ # element::
57
+ # The document element to be collapsed.
58
+ def collapse(element)
59
+ hash = get_attributes(element)
60
+
61
+ child_nodes = element.child_nodes
62
+ if child_nodes.length > 0
63
+ for i in 0...child_nodes.length
64
+ child = child_nodes.item(i)
65
+ merge_element!(hash, child) unless child.node_type == Node.TEXT_NODE
66
+ end
67
+ merge_texts!(hash, element) unless empty_content?(element)
68
+ hash
69
+ else
70
+ merge_texts!(hash, element)
71
+ end
72
+ end
73
+
74
+ # Merge all the texts of an element into the hash
75
+ #
76
+ # hash::
77
+ # Hash to add the converted emement to.
78
+ # element::
79
+ # XML element whose texts are to me merged into the hash
80
+ def merge_texts!(hash, element)
81
+ text_children = texts(element)
82
+ if text_children.join.empty?
83
+ hash
84
+ else
85
+ # must use value to prevent double-escaping
86
+ merge!(hash, CONTENT_KEY, text_children.join)
87
+ end
88
+ end
89
+
90
+ # Adds a new key/value pair to an existing Hash. If the key to be added
91
+ # already exists and the existing value associated with key is not
92
+ # an Array, it will be wrapped in an Array. Then the new value is
93
+ # appended to that Array.
94
+ #
95
+ # hash::
96
+ # Hash to add key/value pair to.
97
+ # key::
98
+ # Key to be added.
99
+ # value::
100
+ # Value to be associated with key.
101
+ def merge!(hash, key, value)
102
+ if hash.has_key?(key)
103
+ if hash[key].instance_of?(Array)
104
+ hash[key] << value
105
+ else
106
+ hash[key] = [hash[key], value]
107
+ end
108
+ elsif value.instance_of?(Array)
109
+ hash[key] = [value]
110
+ else
111
+ hash[key] = value
112
+ end
113
+ hash
114
+ end
115
+
116
+ # Converts the attributes array of an XML element into a hash.
117
+ # Returns an empty Hash if node has no attributes.
118
+ #
119
+ # element::
120
+ # XML element to extract attributes from.
121
+ def get_attributes(element)
122
+ attribute_hash = {}
123
+ attributes = element.attributes
124
+ for i in 0...attributes.length
125
+ attribute_hash[attributes.item(i).name] = attributes.item(i).value
126
+ end
127
+ attribute_hash
128
+ end
129
+
130
+ # Determines if a document element has text content
131
+ #
132
+ # element::
133
+ # XML element to be checked.
134
+ def texts(element)
135
+ texts = []
136
+ child_nodes = element.child_nodes
137
+ for i in 0...child_nodes.length
138
+ item = child_nodes.item(i)
139
+ if item.node_type == Node.TEXT_NODE
140
+ texts << item.get_data
141
+ end
142
+ end
143
+ texts
144
+ end
145
+
146
+ # Determines if a document element has text content
147
+ #
148
+ # element::
149
+ # XML element to be checked.
150
+ def empty_content?(element)
151
+ text = ''
152
+ child_nodes = element.child_nodes
153
+ for i in 0...child_nodes.length
154
+ item = child_nodes.item(i)
155
+ if item.node_type == Node.TEXT_NODE
156
+ text << item.get_data.strip
157
+ end
158
+ end
159
+ text.strip.length == 0
160
+ end
161
+ end
162
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-15 00:00:00 -05:00
12
+ date: 2009-07-20 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -176,6 +176,9 @@ files:
176
176
  - lib/active_support/inflections.rb
177
177
  - lib/active_support/inflector.rb
178
178
  - lib/active_support/json
179
+ - lib/active_support/json/backends
180
+ - lib/active_support/json/backends/jsongem.rb
181
+ - lib/active_support/json/backends/yaml.rb
179
182
  - lib/active_support/json/decoding.rb
180
183
  - lib/active_support/json/encoders
181
184
  - lib/active_support/json/encoders/date.rb
@@ -233,6 +236,8 @@ files:
233
236
  - lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb
234
237
  - lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb
235
238
  - lib/active_support/vendor/builder-2.1.2/builder.rb
239
+ - lib/active_support/vendor/i18n-0.1.1
240
+ - lib/active_support/vendor/i18n-0.1.1/lib
236
241
  - lib/active_support/vendor/i18n-0.1.3
237
242
  - lib/active_support/vendor/i18n-0.1.3/i18n.gemspec
238
243
  - lib/active_support/vendor/i18n-0.1.3/lib
@@ -252,8 +257,8 @@ files:
252
257
  - lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb
253
258
  - lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml
254
259
  - lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb
255
- - lib/active_support/vendor/memcache-client-1.6.5
256
- - lib/active_support/vendor/memcache-client-1.6.5/memcache.rb
260
+ - lib/active_support/vendor/memcache-client-1.7.4
261
+ - lib/active_support/vendor/memcache-client-1.7.4/memcache.rb
257
262
  - lib/active_support/vendor/tzinfo-0.3.12
258
263
  - lib/active_support/vendor/tzinfo-0.3.12/tzinfo
259
264
  - lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb
@@ -409,6 +414,7 @@ files:
409
414
  - lib/active_support/version.rb
410
415
  - lib/active_support/whiny_nil.rb
411
416
  - lib/active_support/xml_mini
417
+ - lib/active_support/xml_mini/jdom.rb
412
418
  - lib/active_support/xml_mini/libxml.rb
413
419
  - lib/active_support/xml_mini/nokogiri.rb
414
420
  - lib/active_support/xml_mini/rexml.rb