activesupport 5.0.7.2 → 5.1.7

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 (211) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +464 -694
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/active_support.rb +8 -4
  6. data/lib/active_support/all.rb +3 -3
  7. data/lib/active_support/array_inquirer.rb +7 -5
  8. data/lib/active_support/backtrace_cleaner.rb +4 -4
  9. data/lib/active_support/benchmarkable.rb +3 -3
  10. data/lib/active_support/builder.rb +1 -1
  11. data/lib/active_support/cache.rb +41 -48
  12. data/lib/active_support/cache/file_store.rb +11 -20
  13. data/lib/active_support/cache/mem_cache_store.rb +30 -40
  14. data/lib/active_support/cache/memory_store.rb +13 -13
  15. data/lib/active_support/cache/null_store.rb +4 -4
  16. data/lib/active_support/cache/strategy/local_cache.rb +13 -22
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +4 -5
  18. data/lib/active_support/callbacks.rb +649 -584
  19. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
  20. data/lib/active_support/concurrency/share_lock.rb +20 -21
  21. data/lib/active_support/configurable.rb +5 -5
  22. data/lib/active_support/core_ext.rb +1 -2
  23. data/lib/active_support/core_ext/array.rb +7 -7
  24. data/lib/active_support/core_ext/array/access.rb +1 -1
  25. data/lib/active_support/core_ext/array/conversions.rb +15 -15
  26. data/lib/active_support/core_ext/array/grouping.rb +1 -1
  27. data/lib/active_support/core_ext/array/inquiry.rb +1 -1
  28. data/lib/active_support/core_ext/array/prepend_and_append.rb +1 -1
  29. data/lib/active_support/core_ext/benchmark.rb +1 -1
  30. data/lib/active_support/core_ext/big_decimal.rb +1 -1
  31. data/lib/active_support/core_ext/big_decimal/conversions.rb +4 -6
  32. data/lib/active_support/core_ext/class.rb +2 -2
  33. data/lib/active_support/core_ext/class/attribute.rb +5 -5
  34. data/lib/active_support/core_ext/class/attribute_accessors.rb +1 -1
  35. data/lib/active_support/core_ext/class/subclasses.rb +18 -4
  36. data/lib/active_support/core_ext/date.rb +5 -5
  37. data/lib/active_support/core_ext/date/acts_like.rb +1 -1
  38. data/lib/active_support/core_ext/date/blank.rb +1 -1
  39. data/lib/active_support/core_ext/date/calculations.rb +8 -8
  40. data/lib/active_support/core_ext/date/conversions.rb +12 -12
  41. data/lib/active_support/core_ext/date/zones.rb +2 -2
  42. data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -22
  43. data/lib/active_support/core_ext/date_and_time/compatibility.rb +1 -1
  44. data/lib/active_support/core_ext/date_and_time/zones.rb +7 -8
  45. data/lib/active_support/core_ext/date_time.rb +5 -5
  46. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -2
  47. data/lib/active_support/core_ext/date_time/blank.rb +1 -1
  48. data/lib/active_support/core_ext/date_time/calculations.rb +20 -10
  49. data/lib/active_support/core_ext/date_time/compatibility.rb +2 -2
  50. data/lib/active_support/core_ext/date_time/conversions.rb +12 -12
  51. data/lib/active_support/core_ext/digest/uuid.rb +4 -4
  52. data/lib/active_support/core_ext/enumerable.rb +23 -12
  53. data/lib/active_support/core_ext/file.rb +1 -1
  54. data/lib/active_support/core_ext/file/atomic.rb +4 -4
  55. data/lib/active_support/core_ext/hash.rb +9 -9
  56. data/lib/active_support/core_ext/hash/compact.rb +12 -9
  57. data/lib/active_support/core_ext/hash/conversions.rb +36 -37
  58. data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -2
  59. data/lib/active_support/core_ext/hash/keys.rb +6 -6
  60. data/lib/active_support/core_ext/hash/reverse_merge.rb +1 -1
  61. data/lib/active_support/core_ext/hash/slice.rb +4 -4
  62. data/lib/active_support/core_ext/hash/transform_values.rb +1 -0
  63. data/lib/active_support/core_ext/integer.rb +3 -3
  64. data/lib/active_support/core_ext/integer/inflections.rb +1 -1
  65. data/lib/active_support/core_ext/integer/time.rb +2 -2
  66. data/lib/active_support/core_ext/kernel.rb +4 -4
  67. data/lib/active_support/core_ext/kernel/concern.rb +1 -1
  68. data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
  69. data/lib/active_support/core_ext/load_error.rb +1 -18
  70. data/lib/active_support/core_ext/module.rb +11 -12
  71. data/lib/active_support/core_ext/module/aliasing.rb +3 -48
  72. data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
  73. data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -5
  74. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +20 -13
  75. data/lib/active_support/core_ext/module/concerning.rb +1 -1
  76. data/lib/active_support/core_ext/module/delegation.rb +85 -16
  77. data/lib/active_support/core_ext/module/introspection.rb +3 -11
  78. data/lib/active_support/core_ext/module/reachable.rb +2 -2
  79. data/lib/active_support/core_ext/numeric.rb +4 -4
  80. data/lib/active_support/core_ext/numeric/conversions.rb +3 -9
  81. data/lib/active_support/core_ext/numeric/inquiry.rb +21 -21
  82. data/lib/active_support/core_ext/numeric/time.rb +5 -5
  83. data/lib/active_support/core_ext/object.rb +12 -12
  84. data/lib/active_support/core_ext/object/blank.rb +3 -1
  85. data/lib/active_support/core_ext/object/conversions.rb +4 -4
  86. data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
  87. data/lib/active_support/core_ext/object/duplicable.rb +34 -4
  88. data/lib/active_support/core_ext/object/inclusion.rb +1 -1
  89. data/lib/active_support/core_ext/object/json.rb +26 -12
  90. data/lib/active_support/core_ext/object/to_param.rb +1 -1
  91. data/lib/active_support/core_ext/object/to_query.rb +8 -5
  92. data/lib/active_support/core_ext/object/try.rb +1 -1
  93. data/lib/active_support/core_ext/object/with_options.rb +12 -1
  94. data/lib/active_support/core_ext/range.rb +4 -4
  95. data/lib/active_support/core_ext/range/conversions.rb +1 -1
  96. data/lib/active_support/core_ext/regexp.rb +4 -0
  97. data/lib/active_support/core_ext/securerandom.rb +3 -3
  98. data/lib/active_support/core_ext/string.rb +13 -13
  99. data/lib/active_support/core_ext/string/access.rb +6 -6
  100. data/lib/active_support/core_ext/string/conversions.rb +2 -2
  101. data/lib/active_support/core_ext/string/filters.rb +3 -3
  102. data/lib/active_support/core_ext/string/indent.rb +4 -4
  103. data/lib/active_support/core_ext/string/inflections.rb +10 -14
  104. data/lib/active_support/core_ext/string/inquiry.rb +1 -1
  105. data/lib/active_support/core_ext/string/multibyte.rb +1 -1
  106. data/lib/active_support/core_ext/string/output_safety.rb +19 -20
  107. data/lib/active_support/core_ext/string/strip.rb +1 -1
  108. data/lib/active_support/core_ext/string/zones.rb +2 -2
  109. data/lib/active_support/core_ext/time.rb +5 -5
  110. data/lib/active_support/core_ext/time/acts_like.rb +1 -1
  111. data/lib/active_support/core_ext/time/calculations.rb +46 -29
  112. data/lib/active_support/core_ext/time/conversions.rb +15 -12
  113. data/lib/active_support/core_ext/time/zones.rb +3 -3
  114. data/lib/active_support/core_ext/uri.rb +2 -2
  115. data/lib/active_support/dependencies.rb +45 -46
  116. data/lib/active_support/dependencies/interlock.rb +1 -1
  117. data/lib/active_support/deprecation.rb +9 -8
  118. data/lib/active_support/deprecation/behaviors.rb +3 -3
  119. data/lib/active_support/deprecation/constant_accessor.rb +50 -0
  120. data/lib/active_support/deprecation/instance_delegator.rb +2 -2
  121. data/lib/active_support/deprecation/method_wrappers.rb +10 -3
  122. data/lib/active_support/deprecation/proxy_wrappers.rb +6 -4
  123. data/lib/active_support/deprecation/reporting.rb +7 -7
  124. data/lib/active_support/duration.rb +221 -28
  125. data/lib/active_support/duration/iso8601_parser.rb +66 -65
  126. data/lib/active_support/duration/iso8601_serializer.rb +11 -9
  127. data/lib/active_support/evented_file_update_checker.rb +59 -55
  128. data/lib/active_support/execution_wrapper.rb +3 -3
  129. data/lib/active_support/executor.rb +1 -1
  130. data/lib/active_support/file_update_checker.rb +54 -50
  131. data/lib/active_support/gem_version.rb +2 -2
  132. data/lib/active_support/gzip.rb +4 -4
  133. data/lib/active_support/hash_with_indifferent_access.rb +40 -28
  134. data/lib/active_support/i18n.rb +5 -5
  135. data/lib/active_support/i18n_railtie.rb +14 -9
  136. data/lib/active_support/inflections.rb +11 -11
  137. data/lib/active_support/inflector.rb +5 -5
  138. data/lib/active_support/inflector/inflections.rb +11 -9
  139. data/lib/active_support/inflector/methods.rb +52 -51
  140. data/lib/active_support/inflector/transliterate.rb +8 -11
  141. data/lib/active_support/json.rb +2 -2
  142. data/lib/active_support/json/decoding.rb +3 -3
  143. data/lib/active_support/json/encoding.rb +8 -7
  144. data/lib/active_support/key_generator.rb +17 -17
  145. data/lib/active_support/lazy_load_hooks.rb +2 -2
  146. data/lib/active_support/log_subscriber.rb +9 -7
  147. data/lib/active_support/log_subscriber/test_helper.rb +9 -9
  148. data/lib/active_support/logger.rb +3 -3
  149. data/lib/active_support/logger_silence.rb +3 -3
  150. data/lib/active_support/logger_thread_safe_level.rb +1 -1
  151. data/lib/active_support/message_encryptor.rb +77 -35
  152. data/lib/active_support/message_verifier.rb +7 -7
  153. data/lib/active_support/multibyte.rb +2 -2
  154. data/lib/active_support/multibyte/chars.rb +23 -21
  155. data/lib/active_support/multibyte/unicode.rb +68 -89
  156. data/lib/active_support/notifications.rb +7 -5
  157. data/lib/active_support/notifications/fanout.rb +3 -3
  158. data/lib/active_support/notifications/instrumenter.rb +5 -5
  159. data/lib/active_support/number_helper.rb +5 -4
  160. data/lib/active_support/number_helper/number_converter.rb +11 -11
  161. data/lib/active_support/number_helper/number_to_currency_converter.rb +3 -3
  162. data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -2
  163. data/lib/active_support/number_helper/number_to_human_converter.rb +8 -10
  164. data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -11
  165. data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
  166. data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -3
  167. data/lib/active_support/number_helper/number_to_rounded_converter.rb +12 -32
  168. data/lib/active_support/number_helper/rounding_helper.rb +64 -0
  169. data/lib/active_support/option_merger.rb +1 -1
  170. data/lib/active_support/ordered_hash.rb +3 -3
  171. data/lib/active_support/ordered_options.rb +6 -4
  172. data/lib/active_support/per_thread_registry.rb +5 -5
  173. data/lib/active_support/rails.rb +12 -6
  174. data/lib/active_support/railtie.rb +3 -3
  175. data/lib/active_support/reloader.rb +1 -1
  176. data/lib/active_support/rescuable.rb +6 -6
  177. data/lib/active_support/security_utils.rb +1 -1
  178. data/lib/active_support/string_inquirer.rb +8 -2
  179. data/lib/active_support/subscriber.rb +9 -5
  180. data/lib/active_support/tagged_logging.rb +4 -4
  181. data/lib/active_support/test_case.rb +12 -29
  182. data/lib/active_support/testing/assertions.rb +100 -2
  183. data/lib/active_support/testing/autorun.rb +2 -2
  184. data/lib/active_support/testing/constant_lookup.rb +0 -1
  185. data/lib/active_support/testing/declarative.rb +1 -1
  186. data/lib/active_support/testing/deprecation.rb +3 -2
  187. data/lib/active_support/testing/isolation.rb +15 -22
  188. data/lib/active_support/testing/method_call_assertions.rb +1 -1
  189. data/lib/active_support/testing/setup_and_teardown.rb +2 -2
  190. data/lib/active_support/testing/stream.rb +28 -28
  191. data/lib/active_support/testing/tagged_logging.rb +1 -1
  192. data/lib/active_support/testing/time_helpers.rb +45 -11
  193. data/lib/active_support/time.rb +12 -12
  194. data/lib/active_support/time_with_zone.rb +16 -14
  195. data/lib/active_support/values/time_zone.rb +100 -31
  196. data/lib/active_support/values/unicode_tables.dat +0 -0
  197. data/lib/active_support/version.rb +1 -1
  198. data/lib/active_support/xml_mini.rb +34 -36
  199. data/lib/active_support/xml_mini/jdom.rb +112 -112
  200. data/lib/active_support/xml_mini/libxml.rb +12 -11
  201. data/lib/active_support/xml_mini/libxmlsax.rb +13 -14
  202. data/lib/active_support/xml_mini/nokogiri.rb +10 -10
  203. data/lib/active_support/xml_mini/nokogirisax.rb +12 -13
  204. data/lib/active_support/xml_mini/rexml.rb +9 -9
  205. metadata +8 -9
  206. data/lib/active_support/concurrency/latch.rb +0 -26
  207. data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
  208. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
  209. data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
  210. data/lib/active_support/core_ext/struct.rb +0 -3
  211. data/lib/active_support/core_ext/time/marshal.rb +0 -3
@@ -1,5 +1,5 @@
1
- require 'date'
2
- require 'active_support/core_ext/date_and_time/zones'
1
+ require "date"
2
+ require "active_support/core_ext/date_and_time/zones"
3
3
 
4
4
  class Date
5
5
  include DateAndTime::Zones
@@ -1,15 +1,15 @@
1
- require 'active_support/core_ext/object/try'
1
+ require "active_support/core_ext/object/try"
2
2
 
3
3
  module DateAndTime
4
4
  module Calculations
5
5
  DAYS_INTO_WEEK = {
6
- :monday => 0,
7
- :tuesday => 1,
8
- :wednesday => 2,
9
- :thursday => 3,
10
- :friday => 4,
11
- :saturday => 5,
12
- :sunday => 6
6
+ monday: 0,
7
+ tuesday: 1,
8
+ wednesday: 2,
9
+ thursday: 3,
10
+ friday: 4,
11
+ saturday: 5,
12
+ sunday: 6
13
13
  }
14
14
  WEEKEND_DAYS = [ 6, 0 ]
15
15
 
@@ -60,42 +60,42 @@ module DateAndTime
60
60
 
61
61
  # Returns a new date/time the specified number of days ago.
62
62
  def days_ago(days)
63
- advance(:days => -days)
63
+ advance(days: -days)
64
64
  end
65
65
 
66
66
  # Returns a new date/time the specified number of days in the future.
67
67
  def days_since(days)
68
- advance(:days => days)
68
+ advance(days: days)
69
69
  end
70
70
 
71
71
  # Returns a new date/time the specified number of weeks ago.
72
72
  def weeks_ago(weeks)
73
- advance(:weeks => -weeks)
73
+ advance(weeks: -weeks)
74
74
  end
75
75
 
76
76
  # Returns a new date/time the specified number of weeks in the future.
77
77
  def weeks_since(weeks)
78
- advance(:weeks => weeks)
78
+ advance(weeks: weeks)
79
79
  end
80
80
 
81
81
  # Returns a new date/time the specified number of months ago.
82
82
  def months_ago(months)
83
- advance(:months => -months)
83
+ advance(months: -months)
84
84
  end
85
85
 
86
86
  # Returns a new date/time the specified number of months in the future.
87
87
  def months_since(months)
88
- advance(:months => months)
88
+ advance(months: months)
89
89
  end
90
90
 
91
91
  # Returns a new date/time the specified number of years ago.
92
92
  def years_ago(years)
93
- advance(:years => -years)
93
+ advance(years: -years)
94
94
  end
95
95
 
96
96
  # Returns a new date/time the specified number of years in the future.
97
97
  def years_since(years)
98
- advance(:years => years)
98
+ advance(years: years)
99
99
  end
100
100
 
101
101
  # Returns a new date/time at the start of the month.
@@ -108,7 +108,7 @@ module DateAndTime
108
108
  # now = DateTime.current # => Thu, 18 Jun 2015 15:23:13 +0000
109
109
  # now.beginning_of_month # => Mon, 01 Jun 2015 00:00:00 +0000
110
110
  def beginning_of_month
111
- first_hour(change(:day => 1))
111
+ first_hour(change(day: 1))
112
112
  end
113
113
  alias :at_beginning_of_month :beginning_of_month
114
114
 
@@ -123,7 +123,7 @@ module DateAndTime
123
123
  # now.beginning_of_quarter # => Wed, 01 Jul 2015 00:00:00 +0000
124
124
  def beginning_of_quarter
125
125
  first_quarter_month = [10, 7, 4, 1].detect { |m| m <= month }
126
- beginning_of_month.change(:month => first_quarter_month)
126
+ beginning_of_month.change(month: first_quarter_month)
127
127
  end
128
128
  alias :at_beginning_of_quarter :beginning_of_quarter
129
129
 
@@ -138,7 +138,7 @@ module DateAndTime
138
138
  # now.end_of_quarter # => Wed, 30 Sep 2015 23:59:59 +0000
139
139
  def end_of_quarter
140
140
  last_quarter_month = [3, 6, 9, 12].detect { |m| m >= month }
141
- beginning_of_month.change(:month => last_quarter_month).end_of_month
141
+ beginning_of_month.change(month: last_quarter_month).end_of_month
142
142
  end
143
143
  alias :at_end_of_quarter :end_of_quarter
144
144
 
@@ -152,7 +152,7 @@ module DateAndTime
152
152
  # now = DateTime.current # => Fri, 10 Jul 2015 18:41:29 +0000
153
153
  # now.beginning_of_year # => Thu, 01 Jan 2015 00:00:00 +0000
154
154
  def beginning_of_year
155
- change(:month => 1).beginning_of_month
155
+ change(month: 1).beginning_of_month
156
156
  end
157
157
  alias :at_beginning_of_year :beginning_of_year
158
158
 
@@ -290,12 +290,17 @@ module DateAndTime
290
290
  # Returns a new date/time representing the end of the year.
291
291
  # DateTime objects will have a time set to 23:59:59.
292
292
  def end_of_year
293
- change(:month => 12).end_of_month
293
+ change(month: 12).end_of_month
294
294
  end
295
295
  alias :at_end_of_year :end_of_year
296
296
 
297
+ # Returns a Range representing the whole day of the current date/time.
298
+ def all_day
299
+ beginning_of_day..end_of_day
300
+ end
301
+
297
302
  # Returns a Range representing the whole week of the current date/time.
298
- # Week starts on start_day, default is <tt>Date.week_start</tt> or <tt>config.week_start</tt> when set.
303
+ # Week starts on start_day, default is <tt>Date.beginning_of_week</tt> or <tt>config.beginning_of_week</tt> when set.
299
304
  def all_week(start_day = Date.beginning_of_week)
300
305
  beginning_of_week(start_day)..end_of_week(start_day)
301
306
  end
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
1
+ require "active_support/core_ext/module/attribute_accessors"
2
2
 
3
3
  module DateAndTime
4
4
  module Compatibility
@@ -22,19 +22,18 @@ module DateAndTime
22
22
  if time_zone
23
23
  time_with_zone(time, time_zone)
24
24
  else
25
- time || self.to_time
25
+ time || to_time
26
26
  end
27
27
  end
28
28
 
29
29
  private
30
30
 
31
- def time_with_zone(time, zone)
32
- if time
33
- ActiveSupport::TimeWithZone.new(time.utc? ? time : time.getutc, zone)
34
- else
35
- ActiveSupport::TimeWithZone.new(nil, zone, to_time(:utc))
31
+ def time_with_zone(time, zone)
32
+ if time
33
+ ActiveSupport::TimeWithZone.new(time.utc? ? time : time.getutc, zone)
34
+ else
35
+ ActiveSupport::TimeWithZone.new(nil, zone, to_time(:utc))
36
+ end
36
37
  end
37
- end
38
38
  end
39
39
  end
40
-
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/date_time/acts_like'
2
- require 'active_support/core_ext/date_time/blank'
3
- require 'active_support/core_ext/date_time/calculations'
4
- require 'active_support/core_ext/date_time/compatibility'
5
- require 'active_support/core_ext/date_time/conversions'
1
+ require "active_support/core_ext/date_time/acts_like"
2
+ require "active_support/core_ext/date_time/blank"
3
+ require "active_support/core_ext/date_time/calculations"
4
+ require "active_support/core_ext/date_time/compatibility"
5
+ require "active_support/core_ext/date_time/conversions"
@@ -1,5 +1,5 @@
1
- require 'date'
2
- require 'active_support/core_ext/object/acts_like'
1
+ require "date"
2
+ require "active_support/core_ext/object/acts_like"
3
3
 
4
4
  class DateTime
5
5
  # Duck-types as a Date-like class. See Object#acts_like?.
@@ -1,4 +1,4 @@
1
- require 'date'
1
+ require "date"
2
2
 
3
3
  class DateTime #:nodoc:
4
4
  # No DateTime is ever blank:
@@ -1,4 +1,4 @@
1
- require 'date'
1
+ require "date"
2
2
 
3
3
  class DateTime
4
4
  class << self
@@ -47,13 +47,23 @@ class DateTime
47
47
  # DateTime.new(2012, 8, 29, 22, 35, 0).change(year: 1981, day: 1) # => DateTime.new(1981, 8, 1, 22, 35, 0)
48
48
  # DateTime.new(2012, 8, 29, 22, 35, 0).change(year: 1981, hour: 0) # => DateTime.new(1981, 8, 29, 0, 0, 0)
49
49
  def change(options)
50
+ if new_nsec = options[:nsec]
51
+ raise ArgumentError, "Can't change both :nsec and :usec at the same time: #{options.inspect}" if options[:usec]
52
+ new_fraction = Rational(new_nsec, 1000000000)
53
+ else
54
+ new_usec = options.fetch(:usec, (options[:hour] || options[:min] || options[:sec]) ? 0 : Rational(nsec, 1000))
55
+ new_fraction = Rational(new_usec, 1000000)
56
+ end
57
+
58
+ raise ArgumentError, "argument out of range" if new_fraction >= 1
59
+
50
60
  ::DateTime.civil(
51
61
  options.fetch(:year, year),
52
62
  options.fetch(:month, month),
53
63
  options.fetch(:day, day),
54
64
  options.fetch(:hour, hour),
55
65
  options.fetch(:min, options[:hour] ? 0 : min),
56
- options.fetch(:sec, (options[:hour] || options[:min]) ? 0 : sec + sec_fraction),
66
+ options.fetch(:sec, (options[:hour] || options[:min]) ? 0 : sec) + new_fraction,
57
67
  options.fetch(:offset, offset),
58
68
  options.fetch(:start, start)
59
69
  )
@@ -75,7 +85,7 @@ class DateTime
75
85
  end
76
86
 
77
87
  d = to_date.advance(options)
78
- datetime_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
88
+ datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day)
79
89
  seconds_to_advance = \
80
90
  options.fetch(:seconds, 0) +
81
91
  options.fetch(:minutes, 0) * 60 +
@@ -104,7 +114,7 @@ class DateTime
104
114
 
105
115
  # Returns a new DateTime representing the start of the day (0:00).
106
116
  def beginning_of_day
107
- change(:hour => 0)
117
+ change(hour: 0)
108
118
  end
109
119
  alias :midnight :beginning_of_day
110
120
  alias :at_midnight :beginning_of_day
@@ -112,7 +122,7 @@ class DateTime
112
122
 
113
123
  # Returns a new DateTime representing the middle of the day (12:00)
114
124
  def middle_of_day
115
- change(:hour => 12)
125
+ change(hour: 12)
116
126
  end
117
127
  alias :midday :middle_of_day
118
128
  alias :noon :middle_of_day
@@ -122,31 +132,31 @@ class DateTime
122
132
 
123
133
  # Returns a new DateTime representing the end of the day (23:59:59).
124
134
  def end_of_day
125
- change(:hour => 23, :min => 59, :sec => 59)
135
+ change(hour: 23, min: 59, sec: 59, usec: Rational(999999999, 1000))
126
136
  end
127
137
  alias :at_end_of_day :end_of_day
128
138
 
129
139
  # Returns a new DateTime representing the start of the hour (hh:00:00).
130
140
  def beginning_of_hour
131
- change(:min => 0)
141
+ change(min: 0)
132
142
  end
133
143
  alias :at_beginning_of_hour :beginning_of_hour
134
144
 
135
145
  # Returns a new DateTime representing the end of the hour (hh:59:59).
136
146
  def end_of_hour
137
- change(:min => 59, :sec => 59)
147
+ change(min: 59, sec: 59, usec: Rational(999999999, 1000))
138
148
  end
139
149
  alias :at_end_of_hour :end_of_hour
140
150
 
141
151
  # Returns a new DateTime representing the start of the minute (hh:mm:00).
142
152
  def beginning_of_minute
143
- change(:sec => 0)
153
+ change(sec: 0)
144
154
  end
145
155
  alias :at_beginning_of_minute :beginning_of_minute
146
156
 
147
157
  # Returns a new DateTime representing the end of the minute (hh:mm:59).
148
158
  def end_of_minute
149
- change(:sec => 59)
159
+ change(sec: 59, usec: Rational(999999999, 1000))
150
160
  end
151
161
  alias :at_end_of_minute :end_of_minute
152
162
 
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/date_and_time/compatibility'
2
- require 'active_support/core_ext/module/remove_method'
1
+ require "active_support/core_ext/date_and_time/compatibility"
2
+ require "active_support/core_ext/module/remove_method"
3
3
 
4
4
  class DateTime
5
5
  include DateAndTime::Compatibility
@@ -1,8 +1,8 @@
1
- require 'date'
2
- require 'active_support/inflector/methods'
3
- require 'active_support/core_ext/time/conversions'
4
- require 'active_support/core_ext/date_time/calculations'
5
- require 'active_support/values/time_zone'
1
+ require "date"
2
+ require "active_support/inflector/methods"
3
+ require "active_support/core_ext/time/conversions"
4
+ require "active_support/core_ext/date_time/calculations"
5
+ require "active_support/values/time_zone"
6
6
 
7
7
  class DateTime
8
8
  # Convert to a formatted string. See Time::DATE_FORMATS for predefined formats.
@@ -64,7 +64,7 @@ class DateTime
64
64
  # # => Sun, 01 Jan 2012 00:00:00 +0300
65
65
  # DateTime.civil_from_format :local, 2012, 12, 17
66
66
  # # => Mon, 17 Dec 2012 00:00:00 +0000
67
- def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0)
67
+ def self.civil_from_format(utc_or_local, year, month = 1, day = 1, hour = 0, min = 0, sec = 0)
68
68
  if utc_or_local.to_sym == :local
69
69
  offset = ::Time.local(year, month, day).utc_offset.to_r / 86400
70
70
  else
@@ -95,11 +95,11 @@ class DateTime
95
95
 
96
96
  private
97
97
 
98
- def offset_in_seconds
99
- (offset * 86400).to_i
100
- end
98
+ def offset_in_seconds
99
+ (offset * 86400).to_i
100
+ end
101
101
 
102
- def seconds_since_unix_epoch
103
- (jd - 2440588) * 86400 - offset_in_seconds + seconds_since_midnight
104
- end
102
+ def seconds_since_unix_epoch
103
+ (jd - 2440588) * 86400 - offset_in_seconds + seconds_since_midnight
104
+ end
105
105
  end
@@ -1,4 +1,4 @@
1
- require 'securerandom'
1
+ require "securerandom"
2
2
 
3
3
  module Digest
4
4
  module UUID
@@ -26,7 +26,7 @@ module Digest
26
26
  hash.update(uuid_namespace)
27
27
  hash.update(name)
28
28
 
29
- ary = hash.digest.unpack('NnnnnN')
29
+ ary = hash.digest.unpack("NnnnnN")
30
30
  ary[2] = (ary[2] & 0x0FFF) | (version << 12)
31
31
  ary[3] = (ary[3] & 0x3FFF) | 0x8000
32
32
 
@@ -35,12 +35,12 @@ module Digest
35
35
 
36
36
  # Convenience method for uuid_from_hash using Digest::MD5.
37
37
  def self.uuid_v3(uuid_namespace, name)
38
- self.uuid_from_hash(Digest::MD5, uuid_namespace, name)
38
+ uuid_from_hash(Digest::MD5, uuid_namespace, name)
39
39
  end
40
40
 
41
41
  # Convenience method for uuid_from_hash using Digest::SHA1.
42
42
  def self.uuid_v5(uuid_namespace, name)
43
- self.uuid_from_hash(Digest::SHA1, uuid_namespace, name)
43
+ uuid_from_hash(Digest::SHA1, uuid_namespace, name)
44
44
  end
45
45
 
46
46
  # Convenience method for SecureRandom.uuid.
@@ -51,12 +51,14 @@ module Enumerable
51
51
  # Convert an enumerable to a hash.
52
52
  #
53
53
  # people.index_by(&:login)
54
- # => { "nextangle" => <Person ...>, "chade-" => <Person ...>, ...}
54
+ # # => { "nextangle" => <Person ...>, "chade-" => <Person ...>, ...}
55
55
  # people.index_by { |person| "#{person.first_name} #{person.last_name}" }
56
- # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...}
56
+ # # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...}
57
57
  def index_by
58
58
  if block_given?
59
- Hash[map { |elem| [yield(elem), elem] }]
59
+ result = {}
60
+ each { |elem| result[yield(elem)] = elem }
61
+ result
60
62
  else
61
63
  to_enum(:index_by) { size if respond_to?(:size) }
62
64
  end
@@ -87,10 +89,10 @@ module Enumerable
87
89
  # Returns a copy of the enumerable without the specified elements.
88
90
  #
89
91
  # ["David", "Rafael", "Aaron", "Todd"].without "Aaron", "Todd"
90
- # => ["David", "Rafael"]
92
+ # # => ["David", "Rafael"]
91
93
  #
92
94
  # {foo: 1, bar: 2, baz: 3}.without :bar
93
- # => {foo: 1, baz: 3}
95
+ # # => {foo: 1, baz: 3}
94
96
  def without(*elements)
95
97
  reject { |element| elements.include?(element) }
96
98
  end
@@ -98,10 +100,10 @@ module Enumerable
98
100
  # Convert an enumerable to an array based on the given key.
99
101
  #
100
102
  # [{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pluck(:name)
101
- # => ["David", "Rafael", "Aaron"]
103
+ # # => ["David", "Rafael", "Aaron"]
102
104
  #
103
105
  # [{ id: 1, name: "David" }, { id: 2, name: "Rafael" }].pluck(:id, :name)
104
- # => [[1, "David"], [2, "Rafael"]]
106
+ # # => [[1, "David"], [2, "Rafael"]]
105
107
  def pluck(*keys)
106
108
  if keys.many?
107
109
  map { |element| keys.map { |key| element[key] } }
@@ -135,12 +137,21 @@ end
135
137
  # and fall back to the compatible implementation, but that's much slower than
136
138
  # just calling the compat method in the first place.
137
139
  if Array.instance_methods(false).include?(:sum) && !(%w[a].sum rescue false)
138
- class Array
139
- remove_method :sum
140
+ # Using Refinements here in order not to expose our internal method
141
+ using Module.new {
142
+ refine Array do
143
+ alias :orig_sum :sum
144
+ end
145
+ }
140
146
 
141
- def sum(*args) #:nodoc:
142
- # Use Enumerable#sum instead.
143
- super
147
+ class Array
148
+ def sum(init = nil, &block) #:nodoc:
149
+ if init.is_a?(Numeric) || first.is_a?(Numeric)
150
+ init ||= 0
151
+ orig_sum(init, &block)
152
+ else
153
+ super
154
+ end
144
155
  end
145
156
  end
146
157
  end
@@ -1 +1 @@
1
- require 'active_support/core_ext/file/atomic'
1
+ require "active_support/core_ext/file/atomic"