activesupport 3.2.22.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +364 -135
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +6 -4
  5. data/lib/active_support/backtrace_cleaner.rb +33 -25
  6. data/lib/active_support/basic_object.rb +7 -17
  7. data/lib/active_support/benchmarkable.rb +19 -15
  8. data/lib/active_support/buffered_logger.rb +9 -113
  9. data/lib/active_support/cache/file_store.rb +14 -14
  10. data/lib/active_support/cache/mem_cache_store.rb +24 -30
  11. data/lib/active_support/cache/memory_store.rb +2 -0
  12. data/lib/active_support/cache/strategy/local_cache.rb +48 -37
  13. data/lib/active_support/cache.rb +228 -183
  14. data/lib/active_support/callbacks.rb +201 -253
  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/array/access.rb +17 -9
  19. data/lib/active_support/core_ext/array/conversions.rb +115 -55
  20. data/lib/active_support/core_ext/array/extract_options.rb +2 -2
  21. data/lib/active_support/core_ext/array/grouping.rb +21 -22
  22. data/lib/active_support/core_ext/array/uniq_by.rb +12 -9
  23. data/lib/active_support/core_ext/array/wrap.rb +13 -16
  24. data/lib/active_support/core_ext/array.rb +0 -1
  25. data/lib/active_support/core_ext/benchmark.rb +7 -0
  26. data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -24
  27. data/lib/active_support/core_ext/class/attribute.rb +40 -32
  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/calculations.rb +44 -187
  32. data/lib/active_support/core_ext/date/conversions.rb +16 -38
  33. data/lib/active_support/core_ext/date/zones.rb +25 -2
  34. data/lib/active_support/core_ext/date.rb +5 -0
  35. data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
  36. data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
  37. data/lib/active_support/core_ext/date_time/calculations.rb +77 -62
  38. data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
  39. data/lib/active_support/core_ext/date_time/zones.rb +11 -8
  40. data/lib/active_support/core_ext/date_time.rb +4 -0
  41. data/lib/active_support/core_ext/enumerable.rb +26 -73
  42. data/lib/active_support/core_ext/file/atomic.rb +27 -11
  43. data/lib/active_support/core_ext/file.rb +0 -1
  44. data/lib/active_support/core_ext/hash/conversions.rb +145 -79
  45. data/lib/active_support/core_ext/hash/deep_merge.rb +14 -8
  46. data/lib/active_support/core_ext/hash/diff.rb +5 -4
  47. data/lib/active_support/core_ext/hash/except.rb +1 -9
  48. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -5
  49. data/lib/active_support/core_ext/hash/keys.rb +108 -24
  50. data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
  51. data/lib/active_support/core_ext/hash/slice.rb +12 -12
  52. data/lib/active_support/core_ext/hash.rb +0 -1
  53. data/lib/active_support/core_ext/integer/inflections.rb +13 -1
  54. data/lib/active_support/core_ext/integer/time.rb +17 -12
  55. data/lib/active_support/core_ext/kernel/debugger.rb +2 -2
  56. data/lib/active_support/core_ext/kernel/reporting.rb +36 -22
  57. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
  58. data/lib/active_support/core_ext/load_error.rb +7 -5
  59. data/lib/active_support/core_ext/logger.rb +7 -23
  60. data/lib/active_support/core_ext/marshal.rb +21 -0
  61. data/lib/active_support/core_ext/module/aliasing.rb +8 -9
  62. data/lib/active_support/core_ext/module/anonymous.rb +2 -7
  63. data/lib/active_support/core_ext/module/attr_internal.rb +0 -1
  64. data/lib/active_support/core_ext/module/attribute_accessors.rb +12 -10
  65. data/lib/active_support/core_ext/module/delegation.rb +92 -49
  66. data/lib/active_support/core_ext/module/deprecation.rb +19 -3
  67. data/lib/active_support/core_ext/module/introspection.rb +17 -27
  68. data/lib/active_support/core_ext/module/qualified_const.rb +8 -20
  69. data/lib/active_support/core_ext/module/remove_method.rb +1 -5
  70. data/lib/active_support/core_ext/module.rb +1 -3
  71. data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
  72. data/lib/active_support/core_ext/numeric/time.rb +6 -6
  73. data/lib/active_support/core_ext/numeric.rb +1 -0
  74. data/lib/active_support/core_ext/object/acts_like.rb +4 -4
  75. data/lib/active_support/core_ext/object/blank.rb +7 -23
  76. data/lib/active_support/core_ext/object/deep_dup.rb +46 -0
  77. data/lib/active_support/core_ext/object/duplicable.rb +1 -30
  78. data/lib/active_support/core_ext/object/inclusion.rb +8 -7
  79. data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
  80. data/lib/active_support/core_ext/object/to_json.rb +8 -0
  81. data/lib/active_support/core_ext/object/to_param.rb +5 -2
  82. data/lib/active_support/core_ext/object/try.rb +46 -25
  83. data/lib/active_support/core_ext/object/with_options.rb +7 -8
  84. data/lib/active_support/core_ext/object.rb +1 -0
  85. data/lib/active_support/core_ext/proc.rb +3 -0
  86. data/lib/active_support/core_ext/range/conversions.rb +0 -2
  87. data/lib/active_support/core_ext/range/include_range.rb +3 -1
  88. data/lib/active_support/core_ext/range/overlaps.rb +1 -1
  89. data/lib/active_support/core_ext/range.rb +0 -2
  90. data/lib/active_support/core_ext/string/access.rb +95 -90
  91. data/lib/active_support/core_ext/string/conversions.rb +27 -38
  92. data/lib/active_support/core_ext/string/encoding.rb +6 -9
  93. data/lib/active_support/core_ext/string/filters.rb +24 -18
  94. data/lib/active_support/core_ext/string/indent.rb +43 -0
  95. data/lib/active_support/core_ext/string/inflections.rb +70 -60
  96. data/lib/active_support/core_ext/string/inquiry.rb +2 -2
  97. data/lib/active_support/core_ext/string/multibyte.rb +41 -64
  98. data/lib/active_support/core_ext/string/output_safety.rb +59 -51
  99. data/lib/active_support/core_ext/string/zones.rb +13 -0
  100. data/lib/active_support/core_ext/string.rb +2 -3
  101. data/lib/active_support/core_ext/struct.rb +6 -0
  102. data/lib/active_support/core_ext/thread.rb +74 -0
  103. data/lib/active_support/core_ext/time/calculations.rb +108 -184
  104. data/lib/active_support/core_ext/time/conversions.rb +27 -51
  105. data/lib/active_support/core_ext/time/marshal.rb +0 -27
  106. data/lib/active_support/core_ext/time/zones.rb +27 -17
  107. data/lib/active_support/core_ext/time.rb +5 -0
  108. data/lib/active_support/core_ext/uri.rb +13 -17
  109. data/lib/active_support/core_ext.rb +3 -2
  110. data/lib/active_support/dependencies/autoload.rb +47 -20
  111. data/lib/active_support/dependencies.rb +160 -141
  112. data/lib/active_support/deprecation/behaviors.rb +44 -30
  113. data/lib/active_support/deprecation/instance_delegator.rb +24 -0
  114. data/lib/active_support/deprecation/method_wrappers.rb +33 -18
  115. data/lib/active_support/deprecation/proxy_wrappers.rb +58 -13
  116. data/lib/active_support/deprecation/reporting.rb +40 -11
  117. data/lib/active_support/deprecation.rb +39 -14
  118. data/lib/active_support/descendants_tracker.rb +34 -19
  119. data/lib/active_support/duration.rb +6 -8
  120. data/lib/active_support/file_update_checker.rb +63 -47
  121. data/lib/active_support/gzip.rb +11 -5
  122. data/lib/active_support/hash_with_indifferent_access.rb +127 -42
  123. data/lib/active_support/i18n.rb +4 -0
  124. data/lib/active_support/i18n_railtie.rb +5 -22
  125. data/lib/active_support/inflections.rb +14 -12
  126. data/lib/active_support/inflector/inflections.rb +108 -71
  127. data/lib/active_support/inflector/methods.rb +181 -160
  128. data/lib/active_support/inflector/transliterate.rb +16 -17
  129. data/lib/active_support/json/decoding.rb +18 -17
  130. data/lib/active_support/json/encoding.rb +93 -39
  131. data/lib/active_support/json/variable.rb +10 -1
  132. data/lib/active_support/key_generator.rb +75 -0
  133. data/lib/active_support/lazy_load_hooks.rb +21 -19
  134. data/lib/active_support/locale/en.yml +100 -3
  135. data/lib/active_support/log_subscriber/test_helper.rb +18 -15
  136. data/lib/active_support/log_subscriber.rb +35 -52
  137. data/lib/active_support/logger.rb +57 -0
  138. data/lib/active_support/logger_silence.rb +24 -0
  139. data/lib/active_support/message_encryptor.rb +38 -35
  140. data/lib/active_support/message_verifier.rb +9 -15
  141. data/lib/active_support/multibyte/chars.rb +80 -333
  142. data/lib/active_support/multibyte/unicode.rb +74 -64
  143. data/lib/active_support/multibyte.rb +5 -28
  144. data/lib/active_support/notifications/fanout.rb +112 -18
  145. data/lib/active_support/notifications/instrumenter.rb +33 -14
  146. data/lib/active_support/notifications.rb +79 -26
  147. data/lib/active_support/number_helper.rb +637 -0
  148. data/lib/active_support/ordered_hash.rb +8 -190
  149. data/lib/active_support/ordered_options.rb +21 -23
  150. data/lib/active_support/per_thread_registry.rb +52 -0
  151. data/lib/active_support/proxy_object.rb +13 -0
  152. data/lib/active_support/rails.rb +27 -0
  153. data/lib/active_support/railtie.rb +12 -32
  154. data/lib/active_support/rescuable.rb +9 -4
  155. data/lib/active_support/string_inquirer.rb +13 -8
  156. data/lib/active_support/subscriber.rb +93 -0
  157. data/lib/active_support/tagged_logging.rb +51 -73
  158. data/lib/active_support/test_case.rb +46 -17
  159. data/lib/active_support/testing/assertions.rb +56 -26
  160. data/lib/active_support/testing/autorun.rb +5 -0
  161. data/lib/active_support/testing/constant_lookup.rb +54 -0
  162. data/lib/active_support/testing/declarative.rb +1 -1
  163. data/lib/active_support/testing/deprecation.rb +0 -19
  164. data/lib/active_support/testing/isolation.rb +29 -58
  165. data/lib/active_support/testing/pending.rb +5 -43
  166. data/lib/active_support/testing/setup_and_teardown.rb +6 -92
  167. data/lib/active_support/testing/tagged_logging.rb +25 -0
  168. data/lib/active_support/time.rb +6 -21
  169. data/lib/active_support/time_with_zone.rb +80 -43
  170. data/lib/active_support/values/time_zone.rb +81 -60
  171. data/lib/active_support/values/unicode_tables.dat +0 -0
  172. data/lib/active_support/version.rb +7 -6
  173. data/lib/active_support/xml_mini/jdom.rb +9 -11
  174. data/lib/active_support/xml_mini/libxml.rb +1 -2
  175. data/lib/active_support/xml_mini/libxmlsax.rb +2 -3
  176. data/lib/active_support/xml_mini/nokogiri.rb +1 -2
  177. data/lib/active_support/xml_mini/nokogirisax.rb +2 -3
  178. data/lib/active_support/xml_mini/rexml.rb +6 -8
  179. data/lib/active_support/xml_mini.rb +35 -17
  180. data/lib/active_support.rb +8 -21
  181. metadata +104 -72
  182. data/lib/active_support/base64.rb +0 -54
  183. data/lib/active_support/core_ext/array/random_access.rb +0 -30
  184. data/lib/active_support/core_ext/date/freeze.rb +0 -33
  185. data/lib/active_support/core_ext/exception.rb +0 -3
  186. data/lib/active_support/core_ext/file/path.rb +0 -5
  187. data/lib/active_support/core_ext/float/rounding.rb +0 -19
  188. data/lib/active_support/core_ext/float.rb +0 -1
  189. data/lib/active_support/core_ext/hash/deep_dup.rb +0 -18
  190. data/lib/active_support/core_ext/io.rb +0 -15
  191. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  192. data/lib/active_support/core_ext/module/synchronization.rb +0 -45
  193. data/lib/active_support/core_ext/process/daemon.rb +0 -23
  194. data/lib/active_support/core_ext/process.rb +0 -1
  195. data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
  196. data/lib/active_support/core_ext/range/cover.rb +0 -3
  197. data/lib/active_support/core_ext/rexml.rb +0 -46
  198. data/lib/active_support/core_ext/string/interpolation.rb +0 -2
  199. data/lib/active_support/core_ext/string/xchar.rb +0 -18
  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/jruby.rb +0 -115
  208. data/lib/active_support/testing/performance/rubinius.rb +0 -113
  209. data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
  210. data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
  211. data/lib/active_support/testing/performance/ruby.rb +0 -152
  212. data/lib/active_support/testing/performance.rb +0 -317
  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 146
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",
@@ -55,6 +62,7 @@ module ActiveSupport
55
62
  "Newfoundland" => "America/St_Johns",
56
63
  "Brasilia" => "America/Sao_Paulo",
57
64
  "Buenos Aires" => "America/Argentina/Buenos_Aires",
65
+ "Montevideo" => "America/Montevideo",
58
66
  "Georgetown" => "America/Guyana",
59
67
  "Greenland" => "America/Godthab",
60
68
  "Mid-Atlantic" => "Atlantic/South_Georgia",
@@ -143,7 +151,7 @@ module ActiveSupport
143
151
  "Taipei" => "Asia/Taipei",
144
152
  "Perth" => "Australia/Perth",
145
153
  "Irkutsk" => "Asia/Irkutsk",
146
- "Ulaan Bataar" => "Asia/Ulaanbaatar",
154
+ "Ulaanbaatar" => "Asia/Ulaanbaatar",
147
155
  "Seoul" => "Asia/Seoul",
148
156
  "Osaka" => "Asia/Tokyo",
149
157
  "Sapporo" => "Asia/Tokyo",
@@ -160,7 +168,7 @@ module ActiveSupport
160
168
  "Guam" => "Pacific/Guam",
161
169
  "Port Moresby" => "Pacific/Port_Moresby",
162
170
  "Magadan" => "Asia/Magadan",
163
- "Solomon Is." => "Asia/Magadan",
171
+ "Solomon Is." => "Pacific/Guadalcanal",
164
172
  "New Caledonia" => "Pacific/Noumea",
165
173
  "Fiji" => "Pacific/Fiji",
166
174
  "Kamchatka" => "Asia/Kamchatka",
@@ -169,15 +177,15 @@ module ActiveSupport
169
177
  "Wellington" => "Pacific/Auckland",
170
178
  "Nuku'alofa" => "Pacific/Tongatapu",
171
179
  "Tokelau Is." => "Pacific/Fakaofo",
180
+ "Chatham Is." => "Pacific/Chatham",
172
181
  "Samoa" => "Pacific/Apia"
173
- }.each { |name, zone| name.freeze; zone.freeze }
174
- MAPPING.freeze
182
+ }
175
183
 
176
184
  UTC_OFFSET_WITH_COLON = '%s%02d:%02d'
177
185
  UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '')
178
186
 
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:
187
+ # Assumes self represents an offset from UTC in seconds (as returned from
188
+ # Time#utc_offset) and turns this into an +HH:MM formatted string.
181
189
  #
182
190
  # TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00"
183
191
  def self.seconds_to_utc_offset(seconds, colon = true)
@@ -194,8 +202,8 @@ module ActiveSupport
194
202
 
195
203
  # Create a new TimeZone object with the given name and offset. The
196
204
  # 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).
205
+ # (GMT). Seconds were chosen as the offset unit because that is the unit
206
+ # that Ruby uses to represent time zone offsets (see Time#utc_offset).
199
207
  def initialize(name, utc_offset = nil, tzinfo = nil)
200
208
  self.class.send(:require_tzinfo)
201
209
 
@@ -205,6 +213,7 @@ module ActiveSupport
205
213
  @current_period = nil
206
214
  end
207
215
 
216
+ # Returns the offset of this time zone from UTC in seconds.
208
217
  def utc_offset
209
218
  if @utc_offset
210
219
  @utc_offset
@@ -223,16 +232,15 @@ module ActiveSupport
223
232
  # Compare this time zone to the parameter. The two are compared first on
224
233
  # their offsets, and then by name.
225
234
  def <=>(zone)
226
- return unless zone.respond_to?(:utc_offset) && zone.respond_to?(:name)
227
235
  result = (utc_offset <=> zone.utc_offset)
228
236
  result = (name <=> zone.name) if result == 0
229
237
  result
230
238
  end
231
239
 
232
- # Compare #name and TZInfo identifier to a supplied regexp, returning true
240
+ # Compare #name and TZInfo identifier to a supplied regexp, returning +true+
233
241
  # if a match is found.
234
242
  def =~(re)
235
- return true if name =~ re || MAPPING[name] =~ re
243
+ re === name || re === MAPPING[name]
236
244
  end
237
245
 
238
246
  # Returns a textual representation of this time zone.
@@ -240,62 +248,65 @@ module ActiveSupport
240
248
  "(GMT#{formatted_offset}) #{name}"
241
249
  end
242
250
 
243
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example:
251
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone
252
+ # of +self+ from given values.
244
253
  #
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
254
+ # Time.zone = 'Hawaii' # => "Hawaii"
255
+ # Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
247
256
  def local(*args)
248
- time = Time.utc_time(*args)
257
+ time = Time.utc(*args)
249
258
  ActiveSupport::TimeWithZone.new(nil, self, time)
250
259
  end
251
260
 
252
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch. Example:
261
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone
262
+ # of +self+ from number of seconds since the Unix epoch.
253
263
  #
254
- # Time.zone = "Hawaii" # => "Hawaii"
264
+ # Time.zone = 'Hawaii' # => "Hawaii"
255
265
  # Time.utc(2000).to_f # => 946684800.0
256
266
  # Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
257
267
  def at(secs)
258
- utc = Time.at(secs).utc rescue DateTime.civil(1970).since(secs)
259
- utc.in_time_zone(self)
268
+ Time.at(secs).utc.in_time_zone(self)
260
269
  end
261
270
 
262
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example:
271
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone
272
+ # of +self+ from parsed string.
263
273
  #
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
274
+ # Time.zone = 'Hawaii' # => "Hawaii"
275
+ # Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
266
276
  #
267
- # If upper components are missing from the string, they are supplied from TimeZone#now:
277
+ # If upper components are missing from the string, they are supplied from
278
+ # TimeZone#now:
268
279
  #
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)
280
+ # Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
281
+ # Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
282
+ def parse(str, now=now)
272
283
  parts = Date._parse(str, false)
273
284
  return if parts.empty?
274
285
 
275
- time = Time.utc(
286
+ time = Time.new(
276
287
  parts.fetch(:year, now.year),
277
288
  parts.fetch(:mon, now.month),
278
289
  parts.fetch(:mday, now.day),
279
290
  parts.fetch(:hour, 0),
280
291
  parts.fetch(:min, 0),
281
- parts.fetch(:sec, 0),
282
- parts.fetch(:sec_fraction, 0) * 1000000
292
+ parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
293
+ parts.fetch(:offset, 0)
283
294
  )
284
295
 
285
296
  if parts[:offset]
286
- TimeWithZone.new(time - parts[:offset], self)
297
+ TimeWithZone.new(time.utc, self)
287
298
  else
288
299
  TimeWithZone.new(nil, self, time)
289
300
  end
290
301
  end
291
302
 
292
- # Returns an ActiveSupport::TimeWithZone instance representing the current time
293
- # in the time zone represented by +self+. Example:
303
+ # Returns an ActiveSupport::TimeWithZone instance representing the current
304
+ # time in the time zone represented by +self+.
294
305
  #
295
306
  # Time.zone = 'Hawaii' # => "Hawaii"
296
307
  # Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00
297
308
  def now
298
- Time.now.utc.in_time_zone(self)
309
+ time_now.utc.in_time_zone(self)
299
310
  end
300
311
 
301
312
  # Return the current date in this time zone.
@@ -303,23 +314,27 @@ module ActiveSupport
303
314
  tzinfo.now.to_date
304
315
  end
305
316
 
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.
317
+ # Adjust the given time to the simultaneous time in the time zone
318
+ # represented by +self+. Returns a Time.utc() instance -- if you want an
319
+ # ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
308
320
  def utc_to_local(time)
309
321
  tzinfo.utc_to_local(time)
310
322
  end
311
323
 
312
- # Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance.
324
+ # Adjust the given time to the simultaneous time in UTC. Returns a
325
+ # Time.utc() instance.
313
326
  def local_to_utc(time, dst=true)
314
327
  tzinfo.local_to_utc(time, dst)
315
328
  end
316
329
 
317
- # Available so that TimeZone instances respond like TZInfo::Timezone instances
330
+ # Available so that TimeZone instances respond like TZInfo::Timezone
331
+ # instances.
318
332
  def period_for_utc(time)
319
333
  tzinfo.period_for_utc(time)
320
334
  end
321
335
 
322
- # Available so that TimeZone instances respond like TZInfo::Timezone instances
336
+ # Available so that TimeZone instances respond like TZInfo::Timezone
337
+ # instances.
323
338
  def period_for_local(time, dst=true)
324
339
  tzinfo.period_for_local(time, dst)
325
340
  end
@@ -404,5 +419,11 @@ module ActiveSupport
404
419
  end
405
420
  end
406
421
  end
422
+
423
+ private
424
+
425
+ def time_now
426
+ Time.now
427
+ end
407
428
  end
408
429
  end
@@ -1,10 +1,11 @@
1
1
  module ActiveSupport
2
- module VERSION #:nodoc:
3
- MAJOR = 3
4
- MINOR = 2
5
- TINY = 22
6
- PRE = "5"
2
+ # Returns the version of the currently loaded ActiveSupport as a Gem::Version
3
+ def self.version
4
+ Gem::Version.new "4.0.0"
5
+ end
7
6
 
8
- STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
7
+ module VERSION #:nodoc:
8
+ MAJOR, MINOR, TINY, PRE = ActiveSupport.version.segments
9
+ STRING = ActiveSupport.version.to_s
9
10
  end
10
11
  end
@@ -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
@@ -47,7 +46,7 @@ module ActiveSupport
47
46
  xml_string_reader = StringReader.new(data)
48
47
  xml_input_source = InputSource.new(xml_string_reader)
49
48
  doc = @dbf.new_document_builder.parse(xml_input_source)
50
- merge_element!({CONTENT_KEY => ''}, doc.document_element, XmlMini.depth)
49
+ merge_element!({CONTENT_KEY => ''}, doc.document_element)
51
50
  end
52
51
  end
53
52
 
@@ -59,10 +58,9 @@ module ActiveSupport
59
58
  # Hash to merge the converted element into.
60
59
  # element::
61
60
  # XML element to merge into hash
62
- def merge_element!(hash, element, depth)
63
- raise 'Document too deep!' if depth == 0
61
+ def merge_element!(hash, element)
64
62
  delete_empty(hash)
65
- merge!(hash, element.tag_name, collapse(element, depth))
63
+ merge!(hash, element.tag_name, collapse(element))
66
64
  end
67
65
 
68
66
  def delete_empty(hash)
@@ -73,14 +71,14 @@ module ActiveSupport
73
71
  #
74
72
  # element::
75
73
  # The document element to be collapsed.
76
- def collapse(element, depth)
74
+ def collapse(element)
77
75
  hash = get_attributes(element)
78
76
 
79
77
  child_nodes = element.child_nodes
80
78
  if child_nodes.length > 0
81
- for i in 0...child_nodes.length
79
+ (0...child_nodes.length).each do |i|
82
80
  child = child_nodes.item(i)
83
- merge_element!(hash, child, depth - 1) unless child.node_type == Node.TEXT_NODE
81
+ merge_element!(hash, child) unless child.node_type == Node.TEXT_NODE
84
82
  end
85
83
  merge_texts!(hash, element) unless empty_content?(element)
86
84
  hash
@@ -140,7 +138,7 @@ module ActiveSupport
140
138
  def get_attributes(element)
141
139
  attribute_hash = {}
142
140
  attributes = element.attributes
143
- for i in 0...attributes.length
141
+ (0...attributes.length).each do |i|
144
142
  attribute_hash[CONTENT_KEY] ||= ''
145
143
  attribute_hash[attributes.item(i).name] = attributes.item(i).value
146
144
  end
@@ -154,7 +152,7 @@ module ActiveSupport
154
152
  def texts(element)
155
153
  texts = []
156
154
  child_nodes = element.child_nodes
157
- for i in 0...child_nodes.length
155
+ (0...child_nodes.length).each do |i|
158
156
  item = child_nodes.item(i)
159
157
  if item.node_type == Node.TEXT_NODE
160
158
  texts << item.get_data
@@ -170,7 +168,7 @@ module ActiveSupport
170
168
  def empty_content?(element)
171
169
  text = ''
172
170
  child_nodes = element.child_nodes
173
- for i in 0...child_nodes.length
171
+ (0...child_nodes.length).each do |i|
174
172
  item = child_nodes.item(i)
175
173
  if item.node_type == Node.TEXT_NODE
176
174
  text << item.get_data.strip
@@ -2,7 +2,6 @@ require 'libxml'
2
2
  require 'active_support/core_ext/object/blank'
3
3
  require 'stringio'
4
4
 
5
- # = XmlMini LibXML implementation
6
5
  module ActiveSupport
7
6
  module XmlMini_LibXML #:nodoc:
8
7
  extend self
@@ -38,7 +37,7 @@ module LibXML #:nodoc:
38
37
  module Node #:nodoc:
39
38
  CONTENT_ROOT = '__content__'.freeze
40
39
 
41
- # Convert XML document to hash
40
+ # Convert XML document to hash.
42
41
  #
43
42
  # hash::
44
43
  # Hash to merge the converted element into.
@@ -2,9 +2,8 @@ require 'libxml'
2
2
  require 'active_support/core_ext/object/blank'
3
3
  require 'stringio'
4
4
 
5
- # = XmlMini LibXML implementation using a SAX-based parser
6
5
  module ActiveSupport
7
- module XmlMini_LibXMLSAX
6
+ module XmlMini_LibXMLSAX #:nodoc:
8
7
  extend self
9
8
 
10
9
  # Class that will build the hash while the XML document
@@ -33,7 +32,7 @@ module ActiveSupport
33
32
  end
34
33
 
35
34
  def on_start_element(name, attrs = {})
36
- new_hash = { CONTENT_KEY => '' }.merge(attrs)
35
+ new_hash = { CONTENT_KEY => '' }.merge!(attrs)
37
36
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
38
37
 
39
38
  case current_hash[name]
@@ -7,7 +7,6 @@ end
7
7
  require 'active_support/core_ext/object/blank'
8
8
  require 'stringio'
9
9
 
10
- # = XmlMini Nokogiri implementation
11
10
  module ActiveSupport
12
11
  module XmlMini_Nokogiri #:nodoc:
13
12
  extend self
@@ -41,7 +40,7 @@ module ActiveSupport
41
40
  module Node #:nodoc:
42
41
  CONTENT_ROOT = '__content__'.freeze
43
42
 
44
- # Convert XML document to hash
43
+ # Convert XML document to hash.
45
44
  #
46
45
  # hash::
47
46
  # Hash to merge the converted element into.
@@ -7,9 +7,8 @@ end
7
7
  require 'active_support/core_ext/object/blank'
8
8
  require 'stringio'
9
9
 
10
- # = XmlMini Nokogiri implementation using a SAX-based parser
11
10
  module ActiveSupport
12
- module XmlMini_NokogiriSAX
11
+ module XmlMini_NokogiriSAX #:nodoc:
13
12
  extend self
14
13
 
15
14
  # Class that will build the hash while the XML document
@@ -39,7 +38,7 @@ module ActiveSupport
39
38
  end
40
39
 
41
40
  def start_element(name, attrs = [])
42
- new_hash = { CONTENT_KEY => '' }.merge(Hash[attrs])
41
+ new_hash = { CONTENT_KEY => '' }.merge!(Hash[attrs])
43
42
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
44
43
 
45
44
  case current_hash[name]
@@ -2,14 +2,13 @@ require 'active_support/core_ext/kernel/reporting'
2
2
  require 'active_support/core_ext/object/blank'
3
3
  require 'stringio'
4
4
 
5
- # = XmlMini ReXML implementation
6
5
  module ActiveSupport
7
6
  module XmlMini_REXML #:nodoc:
8
7
  extend self
9
8
 
10
9
  CONTENT_KEY = '__content__'.freeze
11
10
 
12
- # Parse an XML Document string or IO into a simple hash
11
+ # Parse an XML Document string or IO into a simple hash.
13
12
  #
14
13
  # Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
15
14
  # and uses the defaults from Active Support.
@@ -30,7 +29,7 @@ module ActiveSupport
30
29
  doc = REXML::Document.new(data)
31
30
 
32
31
  if doc.root
33
- merge_element!({}, doc.root, XmlMini.depth)
32
+ merge_element!({}, doc.root)
34
33
  else
35
34
  raise REXML::ParseException,
36
35
  "The document #{doc.to_s.inspect} does not have a valid root"
@@ -45,20 +44,19 @@ module ActiveSupport
45
44
  # Hash to merge the converted element into.
46
45
  # element::
47
46
  # XML element to merge into hash
48
- def merge_element!(hash, element, depth)
49
- raise REXML::ParseException, "The document is too deep" if depth == 0
50
- merge!(hash, element.name, collapse(element, depth))
47
+ def merge_element!(hash, element)
48
+ merge!(hash, element.name, collapse(element))
51
49
  end
52
50
 
53
51
  # Actually converts an XML document element into a data structure.
54
52
  #
55
53
  # element::
56
54
  # The document element to be collapsed.
57
- def collapse(element, depth)
55
+ def collapse(element)
58
56
  hash = get_attributes(element)
59
57
 
60
58
  if element.has_elements?
61
- element.each_element {|child| merge_element!(hash, child, depth - 1) }
59
+ element.each_element {|child| merge_element!(hash, child) }
62
60
  merge_texts!(hash, element) unless empty_content?(element)
63
61
  hash
64
62
  else
@@ -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'
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2011 David Heinemeier Hansson
2
+ # Copyright (c) 2005-2013 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -22,59 +22,46 @@
22
22
  #++
23
23
 
24
24
  require 'securerandom'
25
-
26
- module ActiveSupport
27
- class << self
28
- attr_accessor :load_all_hooks
29
- def on_load_all(&hook) load_all_hooks << hook end
30
- def load_all!; load_all_hooks.each { |hook| hook.call } end
31
- end
32
- self.load_all_hooks = []
33
-
34
- on_load_all do
35
- [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte]
36
- end
37
- end
38
-
39
25
  require "active_support/dependencies/autoload"
40
26
  require "active_support/version"
27
+ require "active_support/logger"
28
+ require "active_support/lazy_load_hooks"
41
29
 
42
30
  module ActiveSupport
43
31
  extend ActiveSupport::Autoload
44
32
 
33
+ autoload :Concern
34
+ autoload :Dependencies
45
35
  autoload :DescendantsTracker
46
36
  autoload :FileUpdateChecker
47
37
  autoload :LogSubscriber
48
38
  autoload :Notifications
49
39
 
50
- # TODO: Narrow this list down
51
40
  eager_autoload do
52
41
  autoload :BacktraceCleaner
53
- autoload :Base64
54
42
  autoload :BasicObject
43
+ autoload :ProxyObject
55
44
  autoload :Benchmarkable
56
- autoload :BufferedLogger
57
45
  autoload :Cache
58
46
  autoload :Callbacks
59
- autoload :Concern
60
47
  autoload :Configurable
61
48
  autoload :Deprecation
62
49
  autoload :Gzip
63
50
  autoload :Inflector
64
51
  autoload :JSON
65
- autoload :Memoizable
52
+ autoload :KeyGenerator
66
53
  autoload :MessageEncryptor
67
54
  autoload :MessageVerifier
68
55
  autoload :Multibyte
69
56
  autoload :OptionMerger
70
57
  autoload :OrderedHash
71
58
  autoload :OrderedOptions
72
- autoload :Rescuable
73
59
  autoload :StringInquirer
74
60
  autoload :TaggedLogging
75
61
  autoload :XmlMini
76
62
  end
77
63
 
64
+ autoload :Rescuable
78
65
  autoload :SafeBuffer, "active_support/core_ext/string/output_safety"
79
66
  autoload :TestCase
80
67
  end