activesupport 5.0.7.2 → 5.1.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 (210) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +215 -820
  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 +42 -49
  12. data/lib/active_support/cache/file_store.rb +12 -21
  13. data/lib/active_support/cache/mem_cache_store.rb +30 -40
  14. data/lib/active_support/cache/memory_store.rb +11 -13
  15. data/lib/active_support/cache/null_store.rb +4 -4
  16. data/lib/active_support/cache/strategy/local_cache.rb +16 -25
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +8 -9
  18. data/lib/active_support/callbacks.rb +647 -584
  19. data/lib/active_support/concurrency/share_lock.rb +20 -21
  20. data/lib/active_support/configurable.rb +5 -5
  21. data/lib/active_support/core_ext.rb +1 -2
  22. data/lib/active_support/core_ext/array.rb +7 -7
  23. data/lib/active_support/core_ext/array/access.rb +1 -1
  24. data/lib/active_support/core_ext/array/conversions.rb +15 -15
  25. data/lib/active_support/core_ext/array/grouping.rb +1 -1
  26. data/lib/active_support/core_ext/array/inquiry.rb +1 -1
  27. data/lib/active_support/core_ext/array/prepend_and_append.rb +1 -1
  28. data/lib/active_support/core_ext/benchmark.rb +1 -1
  29. data/lib/active_support/core_ext/big_decimal.rb +1 -1
  30. data/lib/active_support/core_ext/big_decimal/conversions.rb +4 -6
  31. data/lib/active_support/core_ext/class.rb +2 -2
  32. data/lib/active_support/core_ext/class/attribute.rb +5 -5
  33. data/lib/active_support/core_ext/class/attribute_accessors.rb +1 -1
  34. data/lib/active_support/core_ext/class/subclasses.rb +18 -4
  35. data/lib/active_support/core_ext/date.rb +5 -5
  36. data/lib/active_support/core_ext/date/acts_like.rb +1 -1
  37. data/lib/active_support/core_ext/date/blank.rb +1 -1
  38. data/lib/active_support/core_ext/date/calculations.rb +8 -8
  39. data/lib/active_support/core_ext/date/conversions.rb +12 -12
  40. data/lib/active_support/core_ext/date/zones.rb +2 -2
  41. data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -22
  42. data/lib/active_support/core_ext/date_and_time/compatibility.rb +9 -1
  43. data/lib/active_support/core_ext/date_and_time/zones.rb +7 -8
  44. data/lib/active_support/core_ext/date_time.rb +5 -5
  45. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -2
  46. data/lib/active_support/core_ext/date_time/blank.rb +1 -1
  47. data/lib/active_support/core_ext/date_time/calculations.rb +9 -9
  48. data/lib/active_support/core_ext/date_time/compatibility.rb +2 -13
  49. data/lib/active_support/core_ext/date_time/conversions.rb +12 -12
  50. data/lib/active_support/core_ext/digest/uuid.rb +4 -4
  51. data/lib/active_support/core_ext/enumerable.rb +46 -57
  52. data/lib/active_support/core_ext/file.rb +1 -1
  53. data/lib/active_support/core_ext/file/atomic.rb +4 -4
  54. data/lib/active_support/core_ext/hash.rb +9 -9
  55. data/lib/active_support/core_ext/hash/compact.rb +12 -9
  56. data/lib/active_support/core_ext/hash/conversions.rb +36 -37
  57. data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -2
  58. data/lib/active_support/core_ext/hash/keys.rb +8 -8
  59. data/lib/active_support/core_ext/hash/reverse_merge.rb +1 -1
  60. data/lib/active_support/core_ext/hash/slice.rb +4 -4
  61. data/lib/active_support/core_ext/hash/transform_values.rb +1 -0
  62. data/lib/active_support/core_ext/integer.rb +3 -3
  63. data/lib/active_support/core_ext/integer/inflections.rb +1 -1
  64. data/lib/active_support/core_ext/integer/time.rb +2 -2
  65. data/lib/active_support/core_ext/kernel.rb +4 -4
  66. data/lib/active_support/core_ext/kernel/concern.rb +1 -1
  67. data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
  68. data/lib/active_support/core_ext/load_error.rb +1 -18
  69. data/lib/active_support/core_ext/marshal.rb +2 -2
  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 +82 -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 +24 -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 +4 -4
  92. data/lib/active_support/core_ext/object/try.rb +1 -1
  93. data/lib/active_support/core_ext/object/with_options.rb +1 -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 +23 -29
  112. data/lib/active_support/core_ext/time/compatibility.rb +1 -10
  113. data/lib/active_support/core_ext/time/conversions.rb +12 -12
  114. data/lib/active_support/core_ext/time/zones.rb +3 -3
  115. data/lib/active_support/core_ext/uri.rb +2 -2
  116. data/lib/active_support/dependencies.rb +45 -47
  117. data/lib/active_support/dependencies/interlock.rb +1 -1
  118. data/lib/active_support/deprecation.rb +8 -8
  119. data/lib/active_support/deprecation/behaviors.rb +3 -3
  120. data/lib/active_support/deprecation/instance_delegator.rb +2 -2
  121. data/lib/active_support/deprecation/method_wrappers.rb +3 -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 +30 -26
  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 -60
  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 +3 -3
  132. data/lib/active_support/gzip.rb +5 -5
  133. data/lib/active_support/hash_with_indifferent_access.rb +10 -20
  134. data/lib/active_support/i18n.rb +5 -5
  135. data/lib/active_support/i18n_railtie.rb +11 -10
  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 +51 -50
  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 +12 -30
  146. data/lib/active_support/log_subscriber.rb +5 -5
  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 +72 -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 +5 -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 +4 -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 +6 -6
  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 +6 -6
  168. data/lib/active_support/option_merger.rb +1 -1
  169. data/lib/active_support/ordered_hash.rb +3 -3
  170. data/lib/active_support/ordered_options.rb +6 -4
  171. data/lib/active_support/per_thread_registry.rb +5 -5
  172. data/lib/active_support/rails.rb +12 -6
  173. data/lib/active_support/railtie.rb +3 -3
  174. data/lib/active_support/reloader.rb +1 -1
  175. data/lib/active_support/rescuable.rb +8 -14
  176. data/lib/active_support/security_utils.rb +1 -1
  177. data/lib/active_support/string_inquirer.rb +8 -2
  178. data/lib/active_support/subscriber.rb +9 -5
  179. data/lib/active_support/tagged_logging.rb +4 -4
  180. data/lib/active_support/test_case.rb +12 -29
  181. data/lib/active_support/testing/assertions.rb +100 -2
  182. data/lib/active_support/testing/autorun.rb +6 -2
  183. data/lib/active_support/testing/constant_lookup.rb +0 -1
  184. data/lib/active_support/testing/declarative.rb +1 -1
  185. data/lib/active_support/testing/deprecation.rb +3 -2
  186. data/lib/active_support/testing/isolation.rb +13 -22
  187. data/lib/active_support/testing/method_call_assertions.rb +1 -1
  188. data/lib/active_support/testing/setup_and_teardown.rb +2 -2
  189. data/lib/active_support/testing/stream.rb +28 -28
  190. data/lib/active_support/testing/tagged_logging.rb +1 -1
  191. data/lib/active_support/testing/time_helpers.rb +45 -12
  192. data/lib/active_support/time.rb +12 -12
  193. data/lib/active_support/time_with_zone.rb +16 -26
  194. data/lib/active_support/values/time_zone.rb +40 -46
  195. data/lib/active_support/values/unicode_tables.dat +0 -0
  196. data/lib/active_support/version.rb +1 -1
  197. data/lib/active_support/xml_mini.rb +34 -36
  198. data/lib/active_support/xml_mini/jdom.rb +112 -112
  199. data/lib/active_support/xml_mini/libxml.rb +15 -12
  200. data/lib/active_support/xml_mini/libxmlsax.rb +17 -15
  201. data/lib/active_support/xml_mini/nokogiri.rb +13 -11
  202. data/lib/active_support/xml_mini/nokogirisax.rb +15 -14
  203. data/lib/active_support/xml_mini/rexml.rb +9 -9
  204. metadata +8 -19
  205. data/lib/active_support/concurrency/latch.rb +0 -26
  206. data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
  207. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
  208. data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
  209. data/lib/active_support/core_ext/struct.rb +0 -3
  210. data/lib/active_support/core_ext/time/marshal.rb +0 -3
@@ -1,5 +1,5 @@
1
- require 'thread'
2
- require 'monitor'
1
+ require "thread"
2
+ require "monitor"
3
3
 
4
4
  module ActiveSupport
5
5
  module Concurrency
@@ -13,7 +13,6 @@ module ActiveSupport
13
13
  # we need exclusive locks to be reentrant, and we need to be able
14
14
  # to upgrade share locks to exclusive.
15
15
 
16
-
17
16
  def raw_state # :nodoc:
18
17
  synchronize do
19
18
  threads = @sleeping.keys | @sharing.keys | @waiting.keys
@@ -200,27 +199,27 @@ module ActiveSupport
200
199
 
201
200
  private
202
201
 
203
- # Must be called within synchronize
204
- def busy_for_exclusive?(purpose)
205
- busy_for_sharing?(purpose) ||
206
- @sharing.size > (@sharing[Thread.current] > 0 ? 1 : 0)
207
- end
202
+ # Must be called within synchronize
203
+ def busy_for_exclusive?(purpose)
204
+ busy_for_sharing?(purpose) ||
205
+ @sharing.size > (@sharing[Thread.current] > 0 ? 1 : 0)
206
+ end
208
207
 
209
- def busy_for_sharing?(purpose)
210
- (@exclusive_thread && @exclusive_thread != Thread.current) ||
211
- @waiting.any? { |t, (_, c)| t != Thread.current && !c.include?(purpose) }
212
- end
208
+ def busy_for_sharing?(purpose)
209
+ (@exclusive_thread && @exclusive_thread != Thread.current) ||
210
+ @waiting.any? { |t, (_, c)| t != Thread.current && !c.include?(purpose) }
211
+ end
213
212
 
214
- def eligible_waiters?(compatible)
215
- @waiting.any? { |t, (p, _)| compatible.include?(p) && @waiting.all? { |t2, (_, c2)| t == t2 || c2.include?(p) } }
216
- end
213
+ def eligible_waiters?(compatible)
214
+ @waiting.any? { |t, (p, _)| compatible.include?(p) && @waiting.all? { |t2, (_, c2)| t == t2 || c2.include?(p) } }
215
+ end
217
216
 
218
- def wait_for(method)
219
- @sleeping[Thread.current] = method
220
- @cv.wait_while { yield }
221
- ensure
222
- @sleeping.delete Thread.current
223
- end
217
+ def wait_for(method)
218
+ @sleeping[Thread.current] = method
219
+ @cv.wait_while { yield }
220
+ ensure
221
+ @sleeping.delete Thread.current
222
+ end
224
223
  end
225
224
  end
226
225
  end
@@ -1,6 +1,7 @@
1
- require 'active_support/concern'
2
- require 'active_support/ordered_options'
3
- require 'active_support/core_ext/array/extract_options'
1
+ require "active_support/concern"
2
+ require "active_support/ordered_options"
3
+ require "active_support/core_ext/array/extract_options"
4
+ require "active_support/core_ext/regexp"
4
5
 
5
6
  module ActiveSupport
6
7
  # Configurable provides a <tt>config</tt> method to store and retrieve
@@ -107,7 +108,7 @@ module ActiveSupport
107
108
  options = names.extract_options!
108
109
 
109
110
  names.each do |name|
110
- raise NameError.new('invalid config attribute name') unless name =~ /\A[_A-Za-z]\w*\z/
111
+ raise NameError.new("invalid config attribute name") unless /\A[_A-Za-z]\w*\z/.match?(name)
111
112
 
112
113
  reader, reader_line = "def #{name}; config.#{name}; end", __LINE__
113
114
  writer, writer_line = "def #{name}=(value); config.#{name} = value; end", __LINE__
@@ -145,4 +146,3 @@ module ActiveSupport
145
146
  end
146
147
  end
147
148
  end
148
-
@@ -1,4 +1,3 @@
1
- DEPRECATED_FILES = ["#{File.dirname(__FILE__)}/core_ext/struct.rb"]
2
- (Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"] - DEPRECATED_FILES).each do |path|
1
+ (Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"]).each do |path|
3
2
  require path
4
3
  end
@@ -1,7 +1,7 @@
1
- require 'active_support/core_ext/array/wrap'
2
- require 'active_support/core_ext/array/access'
3
- require 'active_support/core_ext/array/conversions'
4
- require 'active_support/core_ext/array/extract_options'
5
- require 'active_support/core_ext/array/grouping'
6
- require 'active_support/core_ext/array/prepend_and_append'
7
- require 'active_support/core_ext/array/inquiry'
1
+ require "active_support/core_ext/array/wrap"
2
+ require "active_support/core_ext/array/access"
3
+ require "active_support/core_ext/array/conversions"
4
+ require "active_support/core_ext/array/extract_options"
5
+ require "active_support/core_ext/array/grouping"
6
+ require "active_support/core_ext/array/prepend_and_append"
7
+ require "active_support/core_ext/array/inquiry"
@@ -31,7 +31,7 @@ class Array
31
31
  #
32
32
  # people = ["David", "Rafael", "Aaron", "Todd"]
33
33
  # people.without "Aaron", "Todd"
34
- # => ["David", "Rafael"]
34
+ # # => ["David", "Rafael"]
35
35
  #
36
36
  # Note: This is an optimization of `Enumerable#without` that uses `Array#-`
37
37
  # instead of `Array#reject` for performance reasons.
@@ -1,8 +1,8 @@
1
- require 'active_support/xml_mini'
2
- require 'active_support/core_ext/hash/keys'
3
- require 'active_support/core_ext/string/inflections'
4
- require 'active_support/core_ext/object/to_param'
5
- require 'active_support/core_ext/object/to_query'
1
+ require "active_support/xml_mini"
2
+ require "active_support/core_ext/hash/keys"
3
+ require "active_support/core_ext/string/inflections"
4
+ require "active_support/core_ext/object/to_param"
5
+ require "active_support/core_ext/object/to_query"
6
6
 
7
7
  class Array
8
8
  # Converts the array to a comma-separated sentence where the last element is
@@ -60,9 +60,9 @@ class Array
60
60
  options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
61
61
 
62
62
  default_connectors = {
63
- :words_connector => ', ',
64
- :two_words_connector => ' and ',
65
- :last_word_connector => ', and '
63
+ words_connector: ", ",
64
+ two_words_connector: " and ",
65
+ last_word_connector: ", and "
66
66
  }
67
67
  if defined?(I18n)
68
68
  i18n_connectors = I18n.translate(:'support.array', locale: options[:locale], default: {})
@@ -72,7 +72,7 @@ class Array
72
72
 
73
73
  case length
74
74
  when 0
75
- ''
75
+ ""
76
76
  when 1
77
77
  "#{self[0]}"
78
78
  when 2
@@ -92,9 +92,9 @@ class Array
92
92
  case format
93
93
  when :db
94
94
  if empty?
95
- 'null'
95
+ "null"
96
96
  else
97
- collect(&:id).join(',')
97
+ collect(&:id).join(",")
98
98
  end
99
99
  else
100
100
  to_default_s
@@ -179,7 +179,7 @@ class Array
179
179
  # </messages>
180
180
  #
181
181
  def to_xml(options = {})
182
- require 'active_support/builder' unless defined?(Builder)
182
+ require "active_support/builder" unless defined?(Builder)
183
183
 
184
184
  options = options.dup
185
185
  options[:indent] ||= 2
@@ -187,9 +187,9 @@ class Array
187
187
  options[:root] ||= \
188
188
  if first.class != Hash && all? { |e| e.is_a?(first.class) }
189
189
  underscored = ActiveSupport::Inflector.underscore(first.class.name)
190
- ActiveSupport::Inflector.pluralize(underscored).tr('/', '_')
190
+ ActiveSupport::Inflector.pluralize(underscored).tr("/", "_")
191
191
  else
192
- 'objects'
192
+ "objects"
193
193
  end
194
194
 
195
195
  builder = options[:builder]
@@ -197,7 +197,7 @@ class Array
197
197
 
198
198
  root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options)
199
199
  children = options.delete(:children) || root.singularize
200
- attributes = options[:skip_types] ? {} : { type: 'array' }
200
+ attributes = options[:skip_types] ? {} : { type: "array" }
201
201
 
202
202
  if empty?
203
203
  builder.tag!(root, attributes)
@@ -89,7 +89,7 @@ class Array
89
89
  # [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]]
90
90
  # (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
91
91
  def split(value = nil)
92
- arr = self.dup
92
+ arr = dup
93
93
  result = []
94
94
  if block_given?
95
95
  while (idx = arr.index { |i| yield i })
@@ -1,4 +1,4 @@
1
- require 'active_support/array_inquirer'
1
+ require "active_support/array_inquirer"
2
2
 
3
3
  class Array
4
4
  # Wraps the array in an +ArrayInquirer+ object, which gives a friendlier way
@@ -4,4 +4,4 @@ class Array
4
4
 
5
5
  # The human way of thinking about adding stuff to the beginning of a list is with prepend.
6
6
  alias_method :prepend, :unshift
7
- end
7
+ end
@@ -1,4 +1,4 @@
1
- require 'benchmark'
1
+ require "benchmark"
2
2
 
3
3
  class << Benchmark
4
4
  # Benchmark realtime in milliseconds.
@@ -1 +1 @@
1
- require 'active_support/core_ext/big_decimal/conversions'
1
+ require "active_support/core_ext/big_decimal/conversions"
@@ -1,12 +1,10 @@
1
- require 'bigdecimal'
2
- require 'bigdecimal/util'
1
+ require "bigdecimal"
2
+ require "bigdecimal/util"
3
3
 
4
4
  module ActiveSupport
5
5
  module BigDecimalWithDefaultFormat #:nodoc:
6
- DEFAULT_STRING_FORMAT = 'F'
7
-
8
- def to_s(format = nil)
9
- super(format || DEFAULT_STRING_FORMAT)
6
+ def to_s(format = "F")
7
+ super(format)
10
8
  end
11
9
  end
12
10
  end
@@ -1,2 +1,2 @@
1
- require 'active_support/core_ext/class/attribute'
2
- require 'active_support/core_ext/class/subclasses'
1
+ require "active_support/core_ext/class/attribute"
2
+ require "active_support/core_ext/class/subclasses"
@@ -1,6 +1,6 @@
1
- require 'active_support/core_ext/kernel/singleton_class'
2
- require 'active_support/core_ext/module/remove_method'
3
- require 'active_support/core_ext/array/extract_options'
1
+ require "active_support/core_ext/kernel/singleton_class"
2
+ require "active_support/core_ext/module/remove_method"
3
+ require "active_support/core_ext/array/extract_options"
4
4
 
5
5
  class Class
6
6
  # Declare a class-level attribute whose value is inheritable by subclasses.
@@ -20,14 +20,14 @@ class Class
20
20
  # Base.setting # => true
21
21
  #
22
22
  # In the above case as long as Subclass does not assign a value to setting
23
- # by performing <tt>Subclass.setting = _something_ </tt>, <tt>Subclass.setting</tt>
23
+ # by performing <tt>Subclass.setting = _something_</tt>, <tt>Subclass.setting</tt>
24
24
  # would read value assigned to parent class. Once Subclass assigns a value then
25
25
  # the value assigned by Subclass would be returned.
26
26
  #
27
27
  # This matches normal Ruby method inheritance: think of writing an attribute
28
28
  # on a subclass as overriding the reader method. However, you need to be aware
29
29
  # when using +class_attribute+ with mutable structures as +Array+ or +Hash+.
30
- # In such cases, you don't want to do changes in places but use setters:
30
+ # In such cases, you don't want to do changes in place. Instead use setters:
31
31
  #
32
32
  # Base.setting = []
33
33
  # Base.setting # => []
@@ -1,4 +1,4 @@
1
1
  # cattr_* became mattr_* aliases in 7dfbd91b0780fbd6a1dd9bfbc176e10894871d2d,
2
2
  # but we keep this around for libraries that directly require it knowing they
3
3
  # want cattr_*. No need to deprecate.
4
- require 'active_support/core_ext/module/attribute_accessors'
4
+ require "active_support/core_ext/module/attribute_accessors"
@@ -1,20 +1,34 @@
1
- require 'active_support/core_ext/module/anonymous'
2
- require 'active_support/core_ext/module/reachable'
1
+ require "active_support/core_ext/module/anonymous"
2
+ require "active_support/core_ext/module/reachable"
3
3
 
4
4
  class Class
5
5
  begin
6
6
  # Test if this Ruby supports each_object against singleton_class
7
7
  ObjectSpace.each_object(Numeric.singleton_class) {}
8
8
 
9
- def descendants # :nodoc:
9
+ # Returns an array with all classes that are < than its receiver.
10
+ #
11
+ # class C; end
12
+ # C.descendants # => []
13
+ #
14
+ # class B < C; end
15
+ # C.descendants # => [B]
16
+ #
17
+ # class A < B; end
18
+ # C.descendants # => [B, A]
19
+ #
20
+ # class D < C; end
21
+ # C.descendants # => [B, A, D]
22
+ def descendants
10
23
  descendants = []
11
24
  ObjectSpace.each_object(singleton_class) do |k|
25
+ next if k.singleton_class?
12
26
  descendants.unshift k unless k == self
13
27
  end
14
28
  descendants
15
29
  end
16
30
  rescue StandardError # JRuby 9.0.4.0 and earlier
17
- def descendants # :nodoc:
31
+ def descendants
18
32
  descendants = []
19
33
  ObjectSpace.each_object(Class) do |k|
20
34
  descendants.unshift k if k < self
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/date/acts_like'
2
- require 'active_support/core_ext/date/blank'
3
- require 'active_support/core_ext/date/calculations'
4
- require 'active_support/core_ext/date/conversions'
5
- require 'active_support/core_ext/date/zones'
1
+ require "active_support/core_ext/date/acts_like"
2
+ require "active_support/core_ext/date/blank"
3
+ require "active_support/core_ext/date/calculations"
4
+ require "active_support/core_ext/date/conversions"
5
+ require "active_support/core_ext/date/zones"
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/object/acts_like'
1
+ require "active_support/core_ext/object/acts_like"
2
2
 
3
3
  class Date
4
4
  # 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 Date #:nodoc:
4
4
  # No Date is blank:
@@ -1,9 +1,9 @@
1
- require 'date'
2
- require 'active_support/duration'
3
- require 'active_support/core_ext/object/acts_like'
4
- require 'active_support/core_ext/date/zones'
5
- require 'active_support/core_ext/time/zones'
6
- require 'active_support/core_ext/date_and_time/calculations'
1
+ require "date"
2
+ require "active_support/duration"
3
+ require "active_support/core_ext/object/acts_like"
4
+ require "active_support/core_ext/date/zones"
5
+ require "active_support/core_ext/time/zones"
6
+ require "active_support/core_ext/date_and_time/calculations"
7
7
 
8
8
  class Date
9
9
  include DateAndTime::Calculations
@@ -129,11 +129,11 @@ class Date
129
129
  options.fetch(:day, day)
130
130
  )
131
131
  end
132
-
132
+
133
133
  # Allow Date to be compared with Time by converting to DateTime and relying on the <=> from there.
134
134
  def compare_with_coercion(other)
135
135
  if other.is_a?(Time)
136
- self.to_datetime <=> other
136
+ to_datetime <=> other
137
137
  else
138
138
  compare_without_coercion(other)
139
139
  end
@@ -1,20 +1,20 @@
1
- require 'date'
2
- require 'active_support/inflector/methods'
3
- require 'active_support/core_ext/date/zones'
4
- require 'active_support/core_ext/module/remove_method'
1
+ require "date"
2
+ require "active_support/inflector/methods"
3
+ require "active_support/core_ext/date/zones"
4
+ require "active_support/core_ext/module/remove_method"
5
5
 
6
6
  class Date
7
7
  DATE_FORMATS = {
8
- :short => '%d %b',
9
- :long => '%B %d, %Y',
10
- :db => '%Y-%m-%d',
11
- :number => '%Y%m%d',
12
- :long_ordinal => lambda { |date|
8
+ short: "%d %b",
9
+ long: "%B %d, %Y",
10
+ db: "%Y-%m-%d",
11
+ number: "%Y%m%d",
12
+ long_ordinal: lambda { |date|
13
13
  day_format = ActiveSupport::Inflector.ordinalize(date.day)
14
14
  date.strftime("%B #{day_format}, %Y") # => "April 25th, 2007"
15
15
  },
16
- :rfc822 => '%d %b %Y',
17
- :iso8601 => lambda { |date| date.iso8601 }
16
+ rfc822: "%d %b %Y",
17
+ iso8601: lambda { |date| date.iso8601 }
18
18
  }
19
19
 
20
20
  # Ruby 1.9 has Date#to_time which converts to localtime only.
@@ -65,7 +65,7 @@ class Date
65
65
 
66
66
  # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005"
67
67
  def readable_inspect
68
- strftime('%a, %d %b %Y')
68
+ strftime("%a, %d %b %Y")
69
69
  end
70
70
  alias_method :default_inspect, :inspect
71
71
  alias_method :inspect, :readable_inspect
@@ -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