activesupport 4.2.11.3 → 5.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (174) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +309 -485
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +2 -3
  5. data/lib/active_support.rb +8 -15
  6. data/lib/active_support/array_inquirer.rb +44 -0
  7. data/lib/active_support/backtrace_cleaner.rb +1 -1
  8. data/lib/active_support/cache.rb +59 -72
  9. data/lib/active_support/cache/file_store.rb +27 -19
  10. data/lib/active_support/cache/mem_cache_store.rb +71 -60
  11. data/lib/active_support/cache/memory_store.rb +16 -21
  12. data/lib/active_support/cache/null_store.rb +1 -4
  13. data/lib/active_support/cache/strategy/local_cache.rb +31 -20
  14. data/lib/active_support/callbacks.rb +107 -111
  15. data/lib/active_support/concern.rb +1 -1
  16. data/lib/active_support/concurrency/latch.rb +7 -15
  17. data/lib/active_support/concurrency/share_lock.rb +142 -0
  18. data/lib/active_support/configurable.rb +1 -0
  19. data/lib/active_support/core_ext.rb +2 -1
  20. data/lib/active_support/core_ext/array.rb +1 -0
  21. data/lib/active_support/core_ext/array/access.rb +13 -1
  22. data/lib/active_support/core_ext/array/conversions.rb +6 -4
  23. data/lib/active_support/core_ext/array/inquiry.rb +17 -0
  24. data/lib/active_support/core_ext/array/wrap.rb +5 -4
  25. data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -10
  26. data/lib/active_support/core_ext/class.rb +0 -1
  27. data/lib/active_support/core_ext/class/attribute.rb +10 -9
  28. data/lib/active_support/core_ext/class/subclasses.rb +5 -2
  29. data/lib/active_support/core_ext/date.rb +1 -1
  30. data/lib/active_support/core_ext/date/blank.rb +12 -0
  31. data/lib/active_support/core_ext/date/calculations.rb +1 -1
  32. data/lib/active_support/core_ext/date/conversions.rb +3 -3
  33. data/lib/active_support/core_ext/date_and_time/calculations.rb +93 -27
  34. data/lib/active_support/core_ext/date_and_time/zones.rb +1 -2
  35. data/lib/active_support/core_ext/date_time.rb +1 -1
  36. data/lib/active_support/core_ext/date_time/blank.rb +12 -0
  37. data/lib/active_support/core_ext/date_time/calculations.rb +7 -23
  38. data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
  39. data/lib/active_support/core_ext/enumerable.rb +27 -17
  40. data/lib/active_support/core_ext/file/atomic.rb +30 -25
  41. data/lib/active_support/core_ext/hash/compact.rb +15 -19
  42. data/lib/active_support/core_ext/hash/conversions.rb +21 -2
  43. data/lib/active_support/core_ext/hash/deep_merge.rb +1 -1
  44. data/lib/active_support/core_ext/hash/except.rb +9 -8
  45. data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -1
  46. data/lib/active_support/core_ext/hash/keys.rb +22 -18
  47. data/lib/active_support/core_ext/hash/slice.rb +1 -1
  48. data/lib/active_support/core_ext/hash/transform_values.rb +13 -7
  49. data/lib/active_support/core_ext/integer/time.rb +1 -1
  50. data/lib/active_support/core_ext/kernel.rb +0 -1
  51. data/lib/active_support/core_ext/kernel/debugger.rb +3 -10
  52. data/lib/active_support/core_ext/kernel/reporting.rb +0 -84
  53. data/lib/active_support/core_ext/load_error.rb +4 -2
  54. data/lib/active_support/core_ext/marshal.rb +8 -13
  55. data/lib/active_support/core_ext/module.rb +1 -0
  56. data/lib/active_support/core_ext/module/aliasing.rb +6 -1
  57. data/lib/active_support/core_ext/module/anonymous.rb +10 -1
  58. data/lib/active_support/core_ext/module/attr_internal.rb +2 -5
  59. data/lib/active_support/core_ext/module/attribute_accessors.rb +7 -7
  60. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +141 -0
  61. data/lib/active_support/core_ext/module/concerning.rb +4 -4
  62. data/lib/active_support/core_ext/module/delegation.rb +7 -14
  63. data/lib/active_support/core_ext/module/method_transplanting.rb +3 -13
  64. data/lib/active_support/core_ext/module/qualified_const.rb +30 -12
  65. data/lib/active_support/core_ext/module/remove_method.rb +23 -0
  66. data/lib/active_support/core_ext/name_error.rb +15 -2
  67. data/lib/active_support/core_ext/numeric.rb +1 -0
  68. data/lib/active_support/core_ext/numeric/bytes.rb +20 -0
  69. data/lib/active_support/core_ext/numeric/conversions.rb +12 -23
  70. data/lib/active_support/core_ext/numeric/inquiry.rb +26 -0
  71. data/lib/active_support/core_ext/numeric/time.rb +20 -0
  72. data/lib/active_support/core_ext/object.rb +0 -1
  73. data/lib/active_support/core_ext/object/blank.rb +11 -2
  74. data/lib/active_support/core_ext/object/deep_dup.rb +10 -3
  75. data/lib/active_support/core_ext/object/duplicable.rb +39 -70
  76. data/lib/active_support/core_ext/object/inclusion.rb +2 -2
  77. data/lib/active_support/core_ext/object/instance_variables.rb +1 -1
  78. data/lib/active_support/core_ext/object/json.rb +9 -7
  79. data/lib/active_support/core_ext/object/to_query.rb +1 -1
  80. data/lib/active_support/core_ext/object/try.rb +67 -21
  81. data/lib/active_support/core_ext/object/with_options.rb +1 -1
  82. data/lib/active_support/core_ext/range/conversions.rb +18 -6
  83. data/lib/active_support/core_ext/range/each.rb +16 -18
  84. data/lib/active_support/core_ext/range/include_range.rb +20 -20
  85. data/lib/active_support/core_ext/securerandom.rb +23 -0
  86. data/lib/active_support/core_ext/string/access.rb +1 -1
  87. data/lib/active_support/core_ext/string/behavior.rb +1 -1
  88. data/lib/active_support/core_ext/string/conversions.rb +2 -2
  89. data/lib/active_support/core_ext/string/filters.rb +1 -2
  90. data/lib/active_support/core_ext/string/inflections.rb +23 -5
  91. data/lib/active_support/core_ext/string/multibyte.rb +11 -7
  92. data/lib/active_support/core_ext/string/output_safety.rb +8 -9
  93. data/lib/active_support/core_ext/string/strip.rb +3 -6
  94. data/lib/active_support/core_ext/struct.rb +3 -6
  95. data/lib/active_support/core_ext/time.rb +0 -2
  96. data/lib/active_support/core_ext/time/calculations.rb +18 -16
  97. data/lib/active_support/core_ext/time/conversions.rb +4 -2
  98. data/lib/active_support/core_ext/time/marshal.rb +2 -29
  99. data/lib/active_support/core_ext/time/zones.rb +19 -3
  100. data/lib/active_support/core_ext/uri.rb +1 -3
  101. data/lib/active_support/dependencies.rb +79 -44
  102. data/lib/active_support/dependencies/interlock.rb +47 -0
  103. data/lib/active_support/deprecation/behaviors.rb +12 -0
  104. data/lib/active_support/deprecation/method_wrappers.rb +42 -16
  105. data/lib/active_support/deprecation/proxy_wrappers.rb +47 -24
  106. data/lib/active_support/deprecation/reporting.rb +13 -2
  107. data/lib/active_support/duration.rb +5 -8
  108. data/lib/active_support/evented_file_update_checker.rb +150 -0
  109. data/lib/active_support/file_update_checker.rb +1 -1
  110. data/lib/active_support/gem_version.rb +5 -5
  111. data/lib/active_support/hash_with_indifferent_access.rb +15 -17
  112. data/lib/active_support/i18n_railtie.rb +25 -4
  113. data/lib/active_support/inflector/inflections.rb +36 -5
  114. data/lib/active_support/inflector/methods.rb +87 -89
  115. data/lib/active_support/inflector/transliterate.rb +36 -21
  116. data/lib/active_support/json/decoding.rb +2 -8
  117. data/lib/active_support/json/encoding.rb +0 -50
  118. data/lib/active_support/key_generator.rb +4 -4
  119. data/lib/active_support/log_subscriber.rb +1 -1
  120. data/lib/active_support/log_subscriber/test_helper.rb +3 -3
  121. data/lib/active_support/logger.rb +4 -52
  122. data/lib/active_support/logger_silence.rb +3 -5
  123. data/lib/active_support/message_encryptor.rb +4 -11
  124. data/lib/active_support/message_verifier.rb +64 -8
  125. data/lib/active_support/multibyte/chars.rb +12 -3
  126. data/lib/active_support/multibyte/unicode.rb +6 -8
  127. data/lib/active_support/notifications.rb +2 -2
  128. data/lib/active_support/notifications/fanout.rb +5 -5
  129. data/lib/active_support/notifications/instrumenter.rb +19 -2
  130. data/lib/active_support/number_helper.rb +21 -15
  131. data/lib/active_support/number_helper/number_to_currency_converter.rb +4 -4
  132. data/lib/active_support/number_helper/number_to_delimited_converter.rb +7 -2
  133. data/lib/active_support/number_helper/number_to_human_converter.rb +6 -4
  134. data/lib/active_support/number_helper/number_to_human_size_converter.rb +5 -1
  135. data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
  136. data/lib/active_support/number_helper/number_to_rounded_converter.rb +28 -25
  137. data/lib/active_support/ordered_options.rb +15 -1
  138. data/lib/active_support/per_thread_registry.rb +3 -0
  139. data/lib/active_support/rails.rb +2 -2
  140. data/lib/active_support/railtie.rb +6 -1
  141. data/lib/active_support/rescuable.rb +4 -4
  142. data/lib/active_support/security_utils.rb +0 -7
  143. data/lib/active_support/string_inquirer.rb +1 -1
  144. data/lib/active_support/subscriber.rb +5 -10
  145. data/lib/active_support/tagged_logging.rb +3 -1
  146. data/lib/active_support/test_case.rb +13 -25
  147. data/lib/active_support/testing/assertions.rb +15 -13
  148. data/lib/active_support/testing/autorun.rb +8 -1
  149. data/lib/active_support/testing/composite_filter.rb +54 -0
  150. data/lib/active_support/testing/deprecation.rb +9 -8
  151. data/lib/active_support/testing/file_fixtures.rb +34 -0
  152. data/lib/active_support/testing/isolation.rb +22 -8
  153. data/lib/active_support/testing/method_call_assertions.rb +41 -0
  154. data/lib/active_support/testing/stream.rb +42 -0
  155. data/lib/active_support/testing/time_helpers.rb +6 -6
  156. data/lib/active_support/time_with_zone.rb +135 -53
  157. data/lib/active_support/values/time_zone.rb +80 -46
  158. data/lib/active_support/values/unicode_tables.dat +0 -0
  159. data/lib/active_support/xml_mini.rb +15 -30
  160. data/lib/active_support/xml_mini/jdom.rb +1 -1
  161. data/lib/active_support/xml_mini/libxml.rb +5 -3
  162. data/lib/active_support/xml_mini/libxmlsax.rb +4 -1
  163. data/lib/active_support/xml_mini/nokogiri.rb +5 -3
  164. data/lib/active_support/xml_mini/nokogirisax.rb +3 -1
  165. data/lib/active_support/xml_mini/rexml.rb +3 -1
  166. metadata +57 -21
  167. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
  168. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  169. data/lib/active_support/core_ext/date_and_time/compatibility.rb +0 -15
  170. data/lib/active_support/core_ext/date_time/compatibility.rb +0 -16
  171. data/lib/active_support/core_ext/object/itself.rb +0 -15
  172. data/lib/active_support/core_ext/thread.rb +0 -86
  173. data/lib/active_support/core_ext/time/compatibility.rb +0 -14
  174. data/lib/active_support/logger_thread_safe_level.rb +0 -32
@@ -1,16 +0,0 @@
1
- require 'active_support/deprecation'
2
-
3
- ActiveSupport::Deprecation.warn 'core_ext/big_decimal/yaml_conversions is deprecated and will be removed in the future.'
4
-
5
- require 'bigdecimal'
6
- require 'yaml'
7
- require 'active_support/core_ext/big_decimal/conversions'
8
-
9
- class BigDecimal
10
- YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' }
11
-
12
- def encode_with(coder)
13
- string = to_s
14
- coder.represent_scalar(nil, YAML_MAPPING[string] || string)
15
- end
16
- end
@@ -1,45 +0,0 @@
1
- require 'active_support/core_ext/kernel/singleton_class'
2
- require 'active_support/core_ext/module/remove_method'
3
- require 'active_support/core_ext/module/deprecation'
4
-
5
-
6
- class Class
7
- def superclass_delegating_accessor(name, options = {})
8
- # Create private _name and _name= methods that can still be used if the public
9
- # methods are overridden.
10
- _superclass_delegating_accessor("_#{name}", options)
11
-
12
- # Generate the public methods name, name=, and name?.
13
- # These methods dispatch to the private _name, and _name= methods, making them
14
- # overridable.
15
- singleton_class.send(:define_method, name) { send("_#{name}") }
16
- singleton_class.send(:define_method, "#{name}?") { !!send("_#{name}") }
17
- singleton_class.send(:define_method, "#{name}=") { |value| send("_#{name}=", value) }
18
-
19
- # If an instance_reader is needed, generate public instance methods name and name?.
20
- if options[:instance_reader] != false
21
- define_method(name) { send("_#{name}") }
22
- define_method("#{name}?") { !!send("#{name}") }
23
- end
24
- end
25
-
26
- deprecate superclass_delegating_accessor: :class_attribute
27
-
28
- private
29
- # Take the object being set and store it in a method. This gives us automatic
30
- # inheritance behavior, without having to store the object in an instance
31
- # variable and look up the superclass chain manually.
32
- def _stash_object_in_method(object, method, instance_reader = true)
33
- singleton_class.remove_possible_method(method)
34
- singleton_class.send(:define_method, method) { object }
35
- remove_possible_method(method)
36
- define_method(method) { object } if instance_reader
37
- end
38
-
39
- def _superclass_delegating_accessor(name, options = {})
40
- singleton_class.send(:define_method, "#{name}=") do |value|
41
- _stash_object_in_method(value, name, options[:instance_reader] != false)
42
- end
43
- send("#{name}=", nil)
44
- end
45
- end
@@ -1,15 +0,0 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
- require 'active_support/core_ext/module/remove_method'
3
-
4
- module DateAndTime
5
- module Compatibility
6
- # If true, +to_time+ preserves the timezone offset of receiver.
7
- #
8
- # NOTE: With Ruby 2.4+ the default for +to_time+ changed from
9
- # converting to the local system time, to preserving the offset
10
- # of the receiver. For backwards compatibility we're overriding
11
- # this behavior, but new apps will have an initializer that sets
12
- # this to true, because the new behavior is preferred.
13
- mattr_accessor(:preserve_timezone, instance_writer: false) { false }
14
- end
15
- end
@@ -1,16 +0,0 @@
1
- require 'active_support/core_ext/date_and_time/compatibility'
2
- require 'active_support/core_ext/module/remove_method'
3
-
4
- class DateTime
5
- include DateAndTime::Compatibility
6
-
7
- remove_possible_method :to_time
8
-
9
- # Either return an instance of `Time` with the same UTC offset
10
- # as +self+ or an instance of `Time` representing the same time
11
- # in the the local system timezone depending on the setting of
12
- # on the setting of +ActiveSupport.to_time_preserves_timezone+.
13
- def to_time
14
- preserve_timezone ? getlocal(utc_offset) : getlocal
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- class Object
2
- # TODO: Remove this file when we drop support for Ruby < 2.2
3
- unless respond_to?(:itself)
4
- # Returns the object itself.
5
- #
6
- # Useful for chaining methods, such as Active Record scopes:
7
- #
8
- # Event.public_send(state.presence_in([ :trashed, :drafted ]) || :itself).order(:created_at)
9
- #
10
- # @return Object
11
- def itself
12
- self
13
- end
14
- end
15
- end
@@ -1,86 +0,0 @@
1
- class Thread
2
- LOCK = Mutex.new # :nodoc:
3
-
4
- # Returns the value of a thread local variable that has been set. Note that
5
- # these are different than fiber local values.
6
- #
7
- # Thread local values are carried along with threads, and do not respect
8
- # fibers. For example:
9
- #
10
- # Thread.new {
11
- # Thread.current.thread_variable_set("foo", "bar") # set a thread local
12
- # Thread.current["foo"] = "bar" # set a fiber local
13
- #
14
- # Fiber.new {
15
- # Fiber.yield [
16
- # Thread.current.thread_variable_get("foo"), # get the thread local
17
- # Thread.current["foo"], # get the fiber local
18
- # ]
19
- # }.resume
20
- # }.join.value # => ['bar', nil]
21
- #
22
- # The value <tt>"bar"</tt> is returned for the thread local, where +nil+ is returned
23
- # for the fiber local. The fiber is executed in the same thread, so the
24
- # thread local values are available.
25
- def thread_variable_get(key)
26
- _locals[key.to_sym]
27
- end
28
-
29
- # Sets a thread local with +key+ to +value+. Note that these are local to
30
- # threads, and not to fibers. Please see Thread#thread_variable_get for
31
- # more information.
32
- def thread_variable_set(key, value)
33
- _locals[key.to_sym] = value
34
- end
35
-
36
- # Returns an array of the names of the thread-local variables (as Symbols).
37
- #
38
- # thr = Thread.new do
39
- # Thread.current.thread_variable_set(:cat, 'meow')
40
- # Thread.current.thread_variable_set("dog", 'woof')
41
- # end
42
- # thr.join # => #<Thread:0x401b3f10 dead>
43
- # thr.thread_variables # => [:dog, :cat]
44
- #
45
- # Note that these are not fiber local variables. Please see Thread#thread_variable_get
46
- # for more details.
47
- def thread_variables
48
- _locals.keys
49
- end
50
-
51
- # Returns <tt>true</tt> if the given string (or symbol) exists as a
52
- # thread-local variable.
53
- #
54
- # me = Thread.current
55
- # me.thread_variable_set(:oliver, "a")
56
- # me.thread_variable?(:oliver) # => true
57
- # me.thread_variable?(:stanley) # => false
58
- #
59
- # Note that these are not fiber local variables. Please see Thread#thread_variable_get
60
- # for more details.
61
- def thread_variable?(key)
62
- _locals.has_key?(key.to_sym)
63
- end
64
-
65
- # Freezes the thread so that thread local variables cannot be set via
66
- # Thread#thread_variable_set, nor can fiber local variables be set.
67
- #
68
- # me = Thread.current
69
- # me.freeze
70
- # me.thread_variable_set(:oliver, "a") #=> RuntimeError: can't modify frozen thread locals
71
- # me[:oliver] = "a" #=> RuntimeError: can't modify frozen thread locals
72
- def freeze
73
- _locals.freeze
74
- super
75
- end
76
-
77
- private
78
-
79
- def _locals
80
- if defined?(@_locals)
81
- @_locals
82
- else
83
- LOCK.synchronize { @_locals ||= {} }
84
- end
85
- end
86
- end unless Thread.instance_methods.include?(:thread_variable_set)
@@ -1,14 +0,0 @@
1
- require "active_support/core_ext/date_and_time/compatibility"
2
- require "active_support/core_ext/module/remove_method"
3
-
4
- class Time
5
- include DateAndTime::Compatibility
6
-
7
- remove_possible_method :to_time
8
-
9
- # Either return +self+ or the time in the local system timezone depending
10
- # on the setting of +ActiveSupport.to_time_preserves_timezone+.
11
- def to_time
12
- preserve_timezone ? self : getlocal
13
- end
14
- end
@@ -1,32 +0,0 @@
1
- require 'active_support/concern'
2
- require 'thread_safe'
3
-
4
- module ActiveSupport
5
- module LoggerThreadSafeLevel
6
- extend ActiveSupport::Concern
7
-
8
- def after_initialize
9
- @local_levels = ThreadSafe::Cache.new
10
- end
11
-
12
- def local_log_id
13
- Thread.current.__id__
14
- end
15
-
16
- def local_level
17
- @local_levels[local_log_id]
18
- end
19
-
20
- def local_level=(level)
21
- if level
22
- @local_levels[local_log_id] = level
23
- else
24
- @local_levels.delete(local_log_id)
25
- end
26
- end
27
-
28
- def level
29
- local_level || super
30
- end
31
- end
32
- end