activesupport 3.2.22.5 → 4.0.0.beta1

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 (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +325 -136
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +4 -2
  5. data/lib/active_support.rb +8 -21
  6. data/lib/active_support/backtrace_cleaner.rb +33 -25
  7. data/lib/active_support/basic_object.rb +7 -17
  8. data/lib/active_support/benchmarkable.rb +19 -15
  9. data/lib/active_support/buffered_logger.rb +9 -113
  10. data/lib/active_support/cache.rb +203 -171
  11. data/lib/active_support/cache/file_store.rb +12 -12
  12. data/lib/active_support/cache/mem_cache_store.rb +24 -30
  13. data/lib/active_support/cache/memory_store.rb +2 -0
  14. data/lib/active_support/callbacks.rb +195 -247
  15. data/lib/active_support/concern.rb +16 -23
  16. data/lib/active_support/concurrency/latch.rb +27 -0
  17. data/lib/active_support/configurable.rb +69 -12
  18. data/lib/active_support/core_ext.rb +1 -0
  19. data/lib/active_support/core_ext/array.rb +0 -1
  20. data/lib/active_support/core_ext/array/access.rb +17 -9
  21. data/lib/active_support/core_ext/array/conversions.rb +113 -55
  22. data/lib/active_support/core_ext/array/extract_options.rb +2 -2
  23. data/lib/active_support/core_ext/array/grouping.rb +21 -22
  24. data/lib/active_support/core_ext/array/uniq_by.rb +12 -9
  25. data/lib/active_support/core_ext/array/wrap.rb +11 -14
  26. data/lib/active_support/core_ext/big_decimal/conversions.rb +7 -24
  27. data/lib/active_support/core_ext/class/attribute.rb +12 -8
  28. data/lib/active_support/core_ext/class/attribute_accessors.rb +14 -12
  29. data/lib/active_support/core_ext/class/delegating_attributes.rb +15 -19
  30. data/lib/active_support/core_ext/class/subclasses.rb +11 -5
  31. data/lib/active_support/core_ext/date.rb +6 -0
  32. data/lib/active_support/core_ext/date/calculations.rb +34 -188
  33. data/lib/active_support/core_ext/date/conversions.rb +16 -38
  34. data/lib/active_support/core_ext/date/infinite_comparable.rb +5 -0
  35. data/lib/active_support/core_ext/date/zones.rb +25 -2
  36. data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
  37. data/lib/active_support/core_ext/date_time.rb +5 -0
  38. data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
  39. data/lib/active_support/core_ext/date_time/calculations.rb +73 -65
  40. data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
  41. data/lib/active_support/core_ext/date_time/infinite_comparable.rb +5 -0
  42. data/lib/active_support/core_ext/date_time/zones.rb +11 -8
  43. data/lib/active_support/core_ext/enumerable.rb +26 -73
  44. data/lib/active_support/core_ext/file.rb +0 -1
  45. data/lib/active_support/core_ext/file/atomic.rb +27 -11
  46. data/lib/active_support/core_ext/hash.rb +0 -1
  47. data/lib/active_support/core_ext/hash/conversions.rb +145 -79
  48. data/lib/active_support/core_ext/hash/deep_merge.rb +14 -8
  49. data/lib/active_support/core_ext/hash/diff.rb +5 -4
  50. data/lib/active_support/core_ext/hash/except.rb +1 -9
  51. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -5
  52. data/lib/active_support/core_ext/hash/keys.rb +108 -24
  53. data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
  54. data/lib/active_support/core_ext/hash/slice.rb +12 -12
  55. data/lib/active_support/core_ext/infinite_comparable.rb +35 -0
  56. data/lib/active_support/core_ext/integer/inflections.rb +13 -1
  57. data/lib/active_support/core_ext/integer/time.rb +17 -12
  58. data/lib/active_support/core_ext/kernel/debugger.rb +2 -2
  59. data/lib/active_support/core_ext/kernel/reporting.rb +36 -22
  60. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
  61. data/lib/active_support/core_ext/load_error.rb +7 -5
  62. data/lib/active_support/core_ext/logger.rb +7 -23
  63. data/lib/active_support/core_ext/marshal.rb +19 -0
  64. data/lib/active_support/core_ext/module.rb +1 -3
  65. data/lib/active_support/core_ext/module/aliasing.rb +8 -9
  66. data/lib/active_support/core_ext/module/anonymous.rb +2 -7
  67. data/lib/active_support/core_ext/module/attr_internal.rb +0 -1
  68. data/lib/active_support/core_ext/module/attribute_accessors.rb +12 -10
  69. data/lib/active_support/core_ext/module/delegation.rb +57 -40
  70. data/lib/active_support/core_ext/module/deprecation.rb +19 -3
  71. data/lib/active_support/core_ext/module/introspection.rb +17 -27
  72. data/lib/active_support/core_ext/module/qualified_const.rb +8 -20
  73. data/lib/active_support/core_ext/module/remove_method.rb +1 -5
  74. data/lib/active_support/core_ext/numeric.rb +2 -0
  75. data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
  76. data/lib/active_support/core_ext/numeric/infinite_comparable.rb +9 -0
  77. data/lib/active_support/core_ext/numeric/time.rb +6 -6
  78. data/lib/active_support/core_ext/object.rb +1 -0
  79. data/lib/active_support/core_ext/object/acts_like.rb +4 -4
  80. data/lib/active_support/core_ext/object/blank.rb +7 -23
  81. data/lib/active_support/core_ext/object/deep_dup.rb +46 -0
  82. data/lib/active_support/core_ext/object/duplicable.rb +1 -30
  83. data/lib/active_support/core_ext/object/inclusion.rb +6 -6
  84. data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
  85. data/lib/active_support/core_ext/object/to_json.rb +8 -0
  86. data/lib/active_support/core_ext/object/to_param.rb +5 -2
  87. data/lib/active_support/core_ext/object/try.rb +46 -25
  88. data/lib/active_support/core_ext/object/with_options.rb +7 -8
  89. data/lib/active_support/core_ext/proc.rb +3 -0
  90. data/lib/active_support/core_ext/range.rb +0 -2
  91. data/lib/active_support/core_ext/range/conversions.rb +0 -2
  92. data/lib/active_support/core_ext/range/include_range.rb +1 -1
  93. data/lib/active_support/core_ext/range/overlaps.rb +1 -1
  94. data/lib/active_support/core_ext/string.rb +2 -2
  95. data/lib/active_support/core_ext/string/access.rb +95 -90
  96. data/lib/active_support/core_ext/string/conversions.rb +29 -38
  97. data/lib/active_support/core_ext/string/encoding.rb +6 -9
  98. data/lib/active_support/core_ext/string/filters.rb +24 -18
  99. data/lib/active_support/core_ext/string/indent.rb +43 -0
  100. data/lib/active_support/core_ext/string/inflections.rb +70 -60
  101. data/lib/active_support/core_ext/string/inquiry.rb +2 -2
  102. data/lib/active_support/core_ext/string/multibyte.rb +41 -64
  103. data/lib/active_support/core_ext/string/output_safety.rb +59 -51
  104. data/lib/active_support/core_ext/string/zones.rb +13 -0
  105. data/lib/active_support/core_ext/struct.rb +6 -0
  106. data/lib/active_support/core_ext/thread.rb +74 -0
  107. data/lib/active_support/core_ext/time.rb +6 -0
  108. data/lib/active_support/core_ext/time/calculations.rb +105 -193
  109. data/lib/active_support/core_ext/time/conversions.rb +27 -51
  110. data/lib/active_support/core_ext/time/infinite_comparable.rb +5 -0
  111. data/lib/active_support/core_ext/time/marshal.rb +0 -27
  112. data/lib/active_support/core_ext/time/zones.rb +27 -17
  113. data/lib/active_support/core_ext/uri.rb +13 -17
  114. data/lib/active_support/dependencies.rb +160 -141
  115. data/lib/active_support/dependencies/autoload.rb +47 -20
  116. data/lib/active_support/deprecation.rb +39 -14
  117. data/lib/active_support/deprecation/behaviors.rb +44 -30
  118. data/lib/active_support/deprecation/instance_delegator.rb +24 -0
  119. data/lib/active_support/deprecation/method_wrappers.rb +33 -18
  120. data/lib/active_support/deprecation/proxy_wrappers.rb +58 -13
  121. data/lib/active_support/deprecation/reporting.rb +40 -11
  122. data/lib/active_support/descendants_tracker.rb +34 -19
  123. data/lib/active_support/duration.rb +6 -8
  124. data/lib/active_support/file_update_checker.rb +63 -47
  125. data/lib/active_support/gzip.rb +11 -5
  126. data/lib/active_support/hash_with_indifferent_access.rb +112 -37
  127. data/lib/active_support/i18n.rb +4 -0
  128. data/lib/active_support/i18n_railtie.rb +5 -22
  129. data/lib/active_support/inflections.rb +14 -12
  130. data/lib/active_support/inflector/inflections.rb +108 -71
  131. data/lib/active_support/inflector/methods.rb +181 -160
  132. data/lib/active_support/inflector/transliterate.rb +16 -17
  133. data/lib/active_support/json/decoding.rb +18 -17
  134. data/lib/active_support/json/encoding.rb +93 -39
  135. data/lib/active_support/json/variable.rb +10 -1
  136. data/lib/active_support/key_generator.rb +75 -0
  137. data/lib/active_support/lazy_load_hooks.rb +21 -19
  138. data/lib/active_support/locale/en.yml +100 -3
  139. data/lib/active_support/log_subscriber.rb +56 -36
  140. data/lib/active_support/log_subscriber/test_helper.rb +18 -15
  141. data/lib/active_support/logger.rb +57 -0
  142. data/lib/active_support/logger_silence.rb +24 -0
  143. data/lib/active_support/message_encryptor.rb +32 -29
  144. data/lib/active_support/message_verifier.rb +8 -14
  145. data/lib/active_support/multibyte.rb +5 -28
  146. data/lib/active_support/multibyte/chars.rb +80 -333
  147. data/lib/active_support/multibyte/unicode.rb +74 -64
  148. data/lib/active_support/notifications.rb +57 -25
  149. data/lib/active_support/notifications/fanout.rb +105 -18
  150. data/lib/active_support/notifications/instrumenter.rb +32 -13
  151. data/lib/active_support/number_helper.rb +636 -0
  152. data/lib/active_support/ordered_hash.rb +8 -190
  153. data/lib/active_support/ordered_options.rb +21 -23
  154. data/lib/active_support/proxy_object.rb +13 -0
  155. data/lib/active_support/rails.rb +27 -0
  156. data/lib/active_support/railtie.rb +12 -32
  157. data/lib/active_support/rescuable.rb +9 -4
  158. data/lib/active_support/string_inquirer.rb +13 -8
  159. data/lib/active_support/tagged_logging.rb +51 -73
  160. data/lib/active_support/test_case.rb +46 -17
  161. data/lib/active_support/testing/assertions.rb +56 -26
  162. data/lib/active_support/testing/autorun.rb +5 -0
  163. data/lib/active_support/testing/constant_lookup.rb +52 -0
  164. data/lib/active_support/testing/declarative.rb +1 -1
  165. data/lib/active_support/testing/deprecation.rb +0 -19
  166. data/lib/active_support/testing/isolation.rb +25 -58
  167. data/lib/active_support/testing/pending.rb +5 -43
  168. data/lib/active_support/testing/setup_and_teardown.rb +6 -92
  169. data/lib/active_support/testing/tagged_logging.rb +25 -0
  170. data/lib/active_support/time.rb +6 -21
  171. data/lib/active_support/time_with_zone.rb +78 -43
  172. data/lib/active_support/values/time_zone.rb +77 -58
  173. data/lib/active_support/values/unicode_tables.dat +0 -0
  174. data/lib/active_support/version.rb +4 -4
  175. data/lib/active_support/xml_mini.rb +35 -17
  176. data/lib/active_support/xml_mini/jdom.rb +9 -17
  177. data/lib/active_support/xml_mini/libxml.rb +1 -2
  178. data/lib/active_support/xml_mini/libxmlsax.rb +1 -2
  179. data/lib/active_support/xml_mini/nokogiri.rb +1 -2
  180. data/lib/active_support/xml_mini/nokogirisax.rb +1 -2
  181. data/lib/active_support/xml_mini/rexml.rb +6 -8
  182. metadata +107 -77
  183. data/lib/active_support/base64.rb +0 -54
  184. data/lib/active_support/core_ext/array/random_access.rb +0 -30
  185. data/lib/active_support/core_ext/date/freeze.rb +0 -33
  186. data/lib/active_support/core_ext/exception.rb +0 -3
  187. data/lib/active_support/core_ext/file/path.rb +0 -5
  188. data/lib/active_support/core_ext/float.rb +0 -1
  189. data/lib/active_support/core_ext/float/rounding.rb +0 -19
  190. data/lib/active_support/core_ext/hash/deep_dup.rb +0 -18
  191. data/lib/active_support/core_ext/io.rb +0 -15
  192. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  193. data/lib/active_support/core_ext/module/synchronization.rb +0 -45
  194. data/lib/active_support/core_ext/process.rb +0 -1
  195. data/lib/active_support/core_ext/process/daemon.rb +0 -23
  196. data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
  197. data/lib/active_support/core_ext/range/cover.rb +0 -3
  198. data/lib/active_support/core_ext/rexml.rb +0 -46
  199. data/lib/active_support/core_ext/string/interpolation.rb +0 -2
  200. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
  201. data/lib/active_support/memoizable.rb +0 -116
  202. data/lib/active_support/multibyte/exceptions.rb +0 -8
  203. data/lib/active_support/multibyte/utils.rb +0 -60
  204. data/lib/active_support/ruby/shim.rb +0 -22
  205. data/lib/active_support/security_utils.rb +0 -27
  206. data/lib/active_support/testing/mochaing.rb +0 -7
  207. data/lib/active_support/testing/performance.rb +0 -317
  208. data/lib/active_support/testing/performance/jruby.rb +0 -115
  209. data/lib/active_support/testing/performance/rubinius.rb +0 -113
  210. data/lib/active_support/testing/performance/ruby.rb +0 -152
  211. data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
  212. data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
  213. data/lib/active_support/time/autoload.rb +0 -5
  214. data/lib/active_support/whiny_nil.rb +0 -24
@@ -1,30 +1,37 @@
1
1
  require 'active_support/core_ext/object/blank'
2
2
  require 'active_support/core_ext/object/try'
3
3
 
4
- # The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following:
5
- #
6
- # * Limit the set of zones provided by TZInfo to a meaningful subset of 142 zones.
7
- # * Retrieve and display zones with a friendlier name (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
8
- # * Lazily load TZInfo::Timezone instances only when they're needed.
9
- # * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+, +parse+, +at+ and +now+ methods.
10
- #
11
- # If you set <tt>config.time_zone</tt> in the Rails Application, you can access this TimeZone object via <tt>Time.zone</tt>:
12
- #
13
- # # application.rb:
14
- # class Application < Rails::Application
15
- # config.time_zone = "Eastern Time (US & Canada)"
16
- # end
17
- #
18
- # Time.zone # => #<TimeZone:0x514834...>
19
- # Time.zone.name # => "Eastern Time (US & Canada)"
20
- # Time.zone.now # => Sun, 18 May 2008 14:30:44 EDT -04:00
21
- #
22
- # The version of TZInfo bundled with Active Support only includes the definitions necessary to support the zones
23
- # defined by the TimeZone class. If you need to use zones that aren't defined by TimeZone, you'll need to install the TZInfo gem
24
- # (if a recent version of the gem is installed locally, this will be used instead of the bundled version.)
25
4
  module ActiveSupport
5
+ # The TimeZone class serves as a wrapper around TZInfo::Timezone instances.
6
+ # It allows us to do the following:
7
+ #
8
+ # * Limit the set of zones provided by TZInfo to a meaningful subset of 142
9
+ # zones.
10
+ # * Retrieve and display zones with a friendlier name
11
+ # (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
12
+ # * Lazily load TZInfo::Timezone instances only when they're needed.
13
+ # * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+,
14
+ # +parse+, +at+ and +now+ methods.
15
+ #
16
+ # If you set <tt>config.time_zone</tt> in the Rails Application, you can
17
+ # access this TimeZone object via <tt>Time.zone</tt>:
18
+ #
19
+ # # application.rb:
20
+ # class Application < Rails::Application
21
+ # config.time_zone = 'Eastern Time (US & Canada)'
22
+ # end
23
+ #
24
+ # Time.zone # => #<TimeZone:0x514834...>
25
+ # Time.zone.name # => "Eastern Time (US & Canada)"
26
+ # Time.zone.now # => Sun, 18 May 2008 14:30:44 EDT -04:00
27
+ #
28
+ # The version of TZInfo bundled with Active Support only includes the
29
+ # definitions necessary to support the zones defined by the TimeZone class.
30
+ # If you need to use zones that aren't defined by TimeZone, you'll need to
31
+ # install the TZInfo gem (if a recent version of the gem is installed locally,
32
+ # this will be used instead of the bundled version.)
26
33
  class TimeZone
27
- # Keys are Rails TimeZone names, values are TZInfo identifiers
34
+ # Keys are Rails TimeZone names, values are TZInfo identifiers.
28
35
  MAPPING = {
29
36
  "International Date Line West" => "Pacific/Midway",
30
37
  "Midway Island" => "Pacific/Midway",
@@ -160,7 +167,7 @@ module ActiveSupport
160
167
  "Guam" => "Pacific/Guam",
161
168
  "Port Moresby" => "Pacific/Port_Moresby",
162
169
  "Magadan" => "Asia/Magadan",
163
- "Solomon Is." => "Asia/Magadan",
170
+ "Solomon Is." => "Pacific/Guadalcanal",
164
171
  "New Caledonia" => "Pacific/Noumea",
165
172
  "Fiji" => "Pacific/Fiji",
166
173
  "Kamchatka" => "Asia/Kamchatka",
@@ -170,14 +177,13 @@ module ActiveSupport
170
177
  "Nuku'alofa" => "Pacific/Tongatapu",
171
178
  "Tokelau Is." => "Pacific/Fakaofo",
172
179
  "Samoa" => "Pacific/Apia"
173
- }.each { |name, zone| name.freeze; zone.freeze }
174
- MAPPING.freeze
180
+ }
175
181
 
176
182
  UTC_OFFSET_WITH_COLON = '%s%02d:%02d'
177
183
  UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '')
178
184
 
179
- # Assumes self represents an offset from UTC in seconds (as returned from Time#utc_offset)
180
- # and turns this into an +HH:MM formatted string. Example:
185
+ # Assumes self represents an offset from UTC in seconds (as returned from
186
+ # Time#utc_offset) and turns this into an +HH:MM formatted string.
181
187
  #
182
188
  # TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00"
183
189
  def self.seconds_to_utc_offset(seconds, colon = true)
@@ -194,8 +200,8 @@ module ActiveSupport
194
200
 
195
201
  # Create a new TimeZone object with the given name and offset. The
196
202
  # offset is the number of seconds that this time zone is offset from UTC
197
- # (GMT). Seconds were chosen as the offset unit because that is the unit that
198
- # Ruby uses to represent time zone offsets (see Time#utc_offset).
203
+ # (GMT). Seconds were chosen as the offset unit because that is the unit
204
+ # that Ruby uses to represent time zone offsets (see Time#utc_offset).
199
205
  def initialize(name, utc_offset = nil, tzinfo = nil)
200
206
  self.class.send(:require_tzinfo)
201
207
 
@@ -205,6 +211,7 @@ module ActiveSupport
205
211
  @current_period = nil
206
212
  end
207
213
 
214
+ # Returns the offset of this time zone from UTC in seconds.
208
215
  def utc_offset
209
216
  if @utc_offset
210
217
  @utc_offset
@@ -223,13 +230,12 @@ module ActiveSupport
223
230
  # Compare this time zone to the parameter. The two are compared first on
224
231
  # their offsets, and then by name.
225
232
  def <=>(zone)
226
- return unless zone.respond_to?(:utc_offset) && zone.respond_to?(:name)
227
233
  result = (utc_offset <=> zone.utc_offset)
228
234
  result = (name <=> zone.name) if result == 0
229
235
  result
230
236
  end
231
237
 
232
- # Compare #name and TZInfo identifier to a supplied regexp, returning true
238
+ # Compare #name and TZInfo identifier to a supplied regexp, returning +true+
233
239
  # if a match is found.
234
240
  def =~(re)
235
241
  return true if name =~ re || MAPPING[name] =~ re
@@ -240,62 +246,65 @@ module ActiveSupport
240
246
  "(GMT#{formatted_offset}) #{name}"
241
247
  end
242
248
 
243
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example:
249
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone
250
+ # of +self+ from given values.
244
251
  #
245
- # Time.zone = "Hawaii" # => "Hawaii"
246
- # Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
252
+ # Time.zone = 'Hawaii' # => "Hawaii"
253
+ # Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
247
254
  def local(*args)
248
- time = Time.utc_time(*args)
255
+ time = Time.utc(*args)
249
256
  ActiveSupport::TimeWithZone.new(nil, self, time)
250
257
  end
251
258
 
252
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch. Example:
259
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone
260
+ # of +self+ from number of seconds since the Unix epoch.
253
261
  #
254
- # Time.zone = "Hawaii" # => "Hawaii"
262
+ # Time.zone = 'Hawaii' # => "Hawaii"
255
263
  # Time.utc(2000).to_f # => 946684800.0
256
264
  # Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
257
265
  def at(secs)
258
- utc = Time.at(secs).utc rescue DateTime.civil(1970).since(secs)
259
- utc.in_time_zone(self)
266
+ Time.at(secs).utc.in_time_zone(self)
260
267
  end
261
268
 
262
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example:
269
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone
270
+ # of +self+ from parsed string.
263
271
  #
264
- # Time.zone = "Hawaii" # => "Hawaii"
265
- # Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
272
+ # Time.zone = 'Hawaii' # => "Hawaii"
273
+ # Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
266
274
  #
267
- # If upper components are missing from the string, they are supplied from TimeZone#now:
275
+ # If upper components are missing from the string, they are supplied from
276
+ # TimeZone#now:
268
277
  #
269
- # Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
270
- # Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
271
- def parse(str, now=self.now)
278
+ # Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
279
+ # Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
280
+ def parse(str, now=now)
272
281
  parts = Date._parse(str, false)
273
282
  return if parts.empty?
274
283
 
275
- time = Time.utc(
284
+ time = Time.new(
276
285
  parts.fetch(:year, now.year),
277
286
  parts.fetch(:mon, now.month),
278
287
  parts.fetch(:mday, now.day),
279
288
  parts.fetch(:hour, 0),
280
289
  parts.fetch(:min, 0),
281
- parts.fetch(:sec, 0),
282
- parts.fetch(:sec_fraction, 0) * 1000000
290
+ parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
291
+ parts.fetch(:offset, 0)
283
292
  )
284
293
 
285
294
  if parts[:offset]
286
- TimeWithZone.new(time - parts[:offset], self)
295
+ TimeWithZone.new(time.utc, self)
287
296
  else
288
297
  TimeWithZone.new(nil, self, time)
289
298
  end
290
299
  end
291
300
 
292
- # Returns an ActiveSupport::TimeWithZone instance representing the current time
293
- # in the time zone represented by +self+. Example:
301
+ # Returns an ActiveSupport::TimeWithZone instance representing the current
302
+ # time in the time zone represented by +self+.
294
303
  #
295
304
  # Time.zone = 'Hawaii' # => "Hawaii"
296
305
  # Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00
297
306
  def now
298
- Time.now.utc.in_time_zone(self)
307
+ time_now.utc.in_time_zone(self)
299
308
  end
300
309
 
301
310
  # Return the current date in this time zone.
@@ -303,23 +312,27 @@ module ActiveSupport
303
312
  tzinfo.now.to_date
304
313
  end
305
314
 
306
- # Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a
307
- # Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
315
+ # Adjust the given time to the simultaneous time in the time zone
316
+ # represented by +self+. Returns a Time.utc() instance -- if you want an
317
+ # ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
308
318
  def utc_to_local(time)
309
319
  tzinfo.utc_to_local(time)
310
320
  end
311
321
 
312
- # Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance.
322
+ # Adjust the given time to the simultaneous time in UTC. Returns a
323
+ # Time.utc() instance.
313
324
  def local_to_utc(time, dst=true)
314
325
  tzinfo.local_to_utc(time, dst)
315
326
  end
316
327
 
317
- # Available so that TimeZone instances respond like TZInfo::Timezone instances
328
+ # Available so that TimeZone instances respond like TZInfo::Timezone
329
+ # instances.
318
330
  def period_for_utc(time)
319
331
  tzinfo.period_for_utc(time)
320
332
  end
321
333
 
322
- # Available so that TimeZone instances respond like TZInfo::Timezone instances
334
+ # Available so that TimeZone instances respond like TZInfo::Timezone
335
+ # instances.
323
336
  def period_for_local(time, dst=true)
324
337
  tzinfo.period_for_local(time, dst)
325
338
  end
@@ -404,5 +417,11 @@ module ActiveSupport
404
417
  end
405
418
  end
406
419
  end
420
+
421
+ private
422
+
423
+ def time_now
424
+ Time.now
425
+ end
407
426
  end
408
427
  end
@@ -1,9 +1,9 @@
1
1
  module ActiveSupport
2
2
  module VERSION #:nodoc:
3
- MAJOR = 3
4
- MINOR = 2
5
- TINY = 22
6
- PRE = "5"
3
+ MAJOR = 4
4
+ MINOR = 0
5
+ TINY = 0
6
+ PRE = "beta1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
@@ -1,5 +1,5 @@
1
1
  require 'time'
2
- require 'active_support/base64'
2
+ require 'base64'
3
3
  require 'active_support/core_ext/module/delegation'
4
4
  require 'active_support/core_ext/string/inflections'
5
5
 
@@ -39,8 +39,8 @@ module ActiveSupport
39
39
  "TrueClass" => "boolean",
40
40
  "FalseClass" => "boolean",
41
41
  "Date" => "date",
42
- "DateTime" => "datetime",
43
- "Time" => "datetime",
42
+ "DateTime" => "dateTime",
43
+ "Time" => "dateTime",
44
44
  "Array" => "array",
45
45
  "Hash" => "hash"
46
46
  } unless defined?(TYPE_NAMES)
@@ -48,7 +48,7 @@ module ActiveSupport
48
48
  FORMATTING = {
49
49
  "symbol" => Proc.new { |symbol| symbol.to_s },
50
50
  "date" => Proc.new { |date| date.to_s(:db) },
51
- "datetime" => Proc.new { |time| time.xmlschema },
51
+ "dateTime" => Proc.new { |time| time.xmlschema },
52
52
  "binary" => Proc.new { |binary| ::Base64.encode64(binary) },
53
53
  "yaml" => Proc.new { |yaml| yaml.to_yaml }
54
54
  } unless defined?(FORMATTING)
@@ -76,26 +76,24 @@ module ActiveSupport
76
76
  )
77
77
  end
78
78
 
79
- attr_reader :backend
80
- attr_accessor :depth
81
- self.depth = 100
82
-
83
79
  delegate :parse, :to => :backend
84
80
 
81
+ def backend
82
+ current_thread_backend || @backend
83
+ end
84
+
85
85
  def backend=(name)
86
- if name.is_a?(Module)
87
- @backend = name
88
- else
89
- require "active_support/xml_mini/#{name.to_s.downcase}"
90
- @backend = ActiveSupport.const_get("XmlMini_#{name}")
91
- end
86
+ backend = name && cast_backend_name_to_module(name)
87
+ self.current_thread_backend = backend if current_thread_backend
88
+ @backend = backend
92
89
  end
93
90
 
94
91
  def with_backend(name)
95
- old_backend, self.backend = backend, name
92
+ old_backend = current_thread_backend
93
+ self.current_thread_backend = name && cast_backend_name_to_module(name)
96
94
  yield
97
95
  ensure
98
- self.backend = old_backend
96
+ self.current_thread_backend = old_backend
99
97
  end
100
98
 
101
99
  def to_tag(key, value, options)
@@ -114,6 +112,7 @@ module ActiveSupport
114
112
  type_name ||= TYPE_NAMES[value.class.name]
115
113
  type_name ||= value.class.name if value && !value.respond_to?(:to_str)
116
114
  type_name = type_name.to_s if type_name
115
+ type_name = "dateTime" if type_name == "datetime"
117
116
 
118
117
  key = rename_key(key.to_s, options)
119
118
 
@@ -148,7 +147,7 @@ module ActiveSupport
148
147
  "#{left}#{middle.tr('_ ', '--')}#{right}"
149
148
  end
150
149
 
151
- # TODO: Add support for other encodings
150
+ # TODO: Add support for other encodings
152
151
  def _parse_binary(bin, entity) #:nodoc:
153
152
  case entity['encoding']
154
153
  when 'base64'
@@ -165,6 +164,25 @@ module ActiveSupport
165
164
  f.content_type = entity['content_type']
166
165
  f
167
166
  end
167
+
168
+ private
169
+
170
+ def current_thread_backend
171
+ Thread.current[:xml_mini_backend]
172
+ end
173
+
174
+ def current_thread_backend=(name)
175
+ Thread.current[:xml_mini_backend] = name && cast_backend_name_to_module(name)
176
+ end
177
+
178
+ def cast_backend_name_to_module(name)
179
+ if name.is_a?(Module)
180
+ name
181
+ else
182
+ require "active_support/xml_mini/#{name.downcase}"
183
+ ActiveSupport.const_get("XmlMini_#{name}")
184
+ end
185
+ end
168
186
  end
169
187
 
170
188
  XmlMini.backend = 'REXML'
@@ -12,7 +12,6 @@ java_import org.xml.sax.InputSource unless defined? InputSource
12
12
  java_import org.xml.sax.Attributes unless defined? Attributes
13
13
  java_import org.w3c.dom.Node unless defined? Node
14
14
 
15
- # = XmlMini JRuby JDOM implementation
16
15
  module ActiveSupport
17
16
  module XmlMini_JDOM #:nodoc:
18
17
  extend self
@@ -38,16 +37,10 @@ module ActiveSupport
38
37
  {}
39
38
  else
40
39
  @dbf = DocumentBuilderFactory.new_instance
41
- # secure processing of java xml
42
- # http://www.ibm.com/developerworks/xml/library/x-tipcfsx/index.html
43
- @dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
44
- @dbf.setFeature("http://xml.org/sax/features/external-general-entities", false)
45
- @dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false)
46
- @dbf.setFeature(javax.xml.XMLConstants::FEATURE_SECURE_PROCESSING, true)
47
40
  xml_string_reader = StringReader.new(data)
48
41
  xml_input_source = InputSource.new(xml_string_reader)
49
42
  doc = @dbf.new_document_builder.parse(xml_input_source)
50
- merge_element!({CONTENT_KEY => ''}, doc.document_element, XmlMini.depth)
43
+ merge_element!({CONTENT_KEY => ''}, doc.document_element)
51
44
  end
52
45
  end
53
46
 
@@ -59,10 +52,9 @@ module ActiveSupport
59
52
  # Hash to merge the converted element into.
60
53
  # element::
61
54
  # XML element to merge into hash
62
- def merge_element!(hash, element, depth)
63
- raise 'Document too deep!' if depth == 0
55
+ def merge_element!(hash, element)
64
56
  delete_empty(hash)
65
- merge!(hash, element.tag_name, collapse(element, depth))
57
+ merge!(hash, element.tag_name, collapse(element))
66
58
  end
67
59
 
68
60
  def delete_empty(hash)
@@ -73,14 +65,14 @@ module ActiveSupport
73
65
  #
74
66
  # element::
75
67
  # The document element to be collapsed.
76
- def collapse(element, depth)
68
+ def collapse(element)
77
69
  hash = get_attributes(element)
78
70
 
79
71
  child_nodes = element.child_nodes
80
72
  if child_nodes.length > 0
81
- for i in 0...child_nodes.length
73
+ (0...child_nodes.length).each do |i|
82
74
  child = child_nodes.item(i)
83
- merge_element!(hash, child, depth - 1) unless child.node_type == Node.TEXT_NODE
75
+ merge_element!(hash, child) unless child.node_type == Node.TEXT_NODE
84
76
  end
85
77
  merge_texts!(hash, element) unless empty_content?(element)
86
78
  hash
@@ -140,7 +132,7 @@ module ActiveSupport
140
132
  def get_attributes(element)
141
133
  attribute_hash = {}
142
134
  attributes = element.attributes
143
- for i in 0...attributes.length
135
+ (0...attributes.length).each do |i|
144
136
  attribute_hash[CONTENT_KEY] ||= ''
145
137
  attribute_hash[attributes.item(i).name] = attributes.item(i).value
146
138
  end
@@ -154,7 +146,7 @@ module ActiveSupport
154
146
  def texts(element)
155
147
  texts = []
156
148
  child_nodes = element.child_nodes
157
- for i in 0...child_nodes.length
149
+ (0...child_nodes.length).each do |i|
158
150
  item = child_nodes.item(i)
159
151
  if item.node_type == Node.TEXT_NODE
160
152
  texts << item.get_data
@@ -170,7 +162,7 @@ module ActiveSupport
170
162
  def empty_content?(element)
171
163
  text = ''
172
164
  child_nodes = element.child_nodes
173
- for i in 0...child_nodes.length
165
+ (0...child_nodes.length).each do |i|
174
166
  item = child_nodes.item(i)
175
167
  if item.node_type == Node.TEXT_NODE
176
168
  text << item.get_data.strip