activesupport 4.2.0 → 5.0.0.1

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 (185) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +630 -220
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +2 -3
  5. data/lib/active_support/array_inquirer.rb +44 -0
  6. data/lib/active_support/backtrace_cleaner.rb +1 -1
  7. data/lib/active_support/benchmarkable.rb +1 -1
  8. data/lib/active_support/cache/file_store.rb +36 -22
  9. data/lib/active_support/cache/mem_cache_store.rb +63 -54
  10. data/lib/active_support/cache/memory_store.rb +16 -21
  11. data/lib/active_support/cache/null_store.rb +1 -4
  12. data/lib/active_support/cache/strategy/local_cache.rb +31 -20
  13. data/lib/active_support/cache.rb +73 -89
  14. data/lib/active_support/callbacks.rb +195 -155
  15. data/lib/active_support/concern.rb +2 -2
  16. data/lib/active_support/concurrency/latch.rb +7 -15
  17. data/lib/active_support/concurrency/share_lock.rb +186 -0
  18. data/lib/active_support/configurable.rb +1 -0
  19. data/lib/active_support/core_ext/array/access.rb +27 -1
  20. data/lib/active_support/core_ext/array/conversions.rb +6 -4
  21. data/lib/active_support/core_ext/array/grouping.rb +9 -18
  22. data/lib/active_support/core_ext/array/inquiry.rb +17 -0
  23. data/lib/active_support/core_ext/array/wrap.rb +5 -4
  24. data/lib/active_support/core_ext/array.rb +1 -0
  25. data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -10
  26. data/lib/active_support/core_ext/class/attribute.rb +10 -9
  27. data/lib/active_support/core_ext/class/subclasses.rb +3 -4
  28. data/lib/active_support/core_ext/class.rb +0 -1
  29. data/lib/active_support/core_ext/date/blank.rb +12 -0
  30. data/lib/active_support/core_ext/date/calculations.rb +1 -1
  31. data/lib/active_support/core_ext/date/conversions.rb +13 -6
  32. data/lib/active_support/core_ext/date.rb +1 -1
  33. data/lib/active_support/core_ext/date_and_time/calculations.rb +109 -25
  34. data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -0
  35. data/lib/active_support/core_ext/date_and_time/zones.rb +3 -4
  36. data/lib/active_support/core_ext/date_time/blank.rb +12 -0
  37. data/lib/active_support/core_ext/date_time/calculations.rb +36 -10
  38. data/lib/active_support/core_ext/date_time/compatibility.rb +5 -0
  39. data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
  40. data/lib/active_support/core_ext/date_time.rb +2 -1
  41. data/lib/active_support/core_ext/enumerable.rb +49 -5
  42. data/lib/active_support/core_ext/file/atomic.rb +30 -25
  43. data/lib/active_support/core_ext/hash/conversions.rb +23 -4
  44. data/lib/active_support/core_ext/hash/deep_merge.rb +1 -1
  45. data/lib/active_support/core_ext/hash/except.rb +9 -8
  46. data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -1
  47. data/lib/active_support/core_ext/hash/keys.rb +23 -19
  48. data/lib/active_support/core_ext/hash/slice.rb +1 -1
  49. data/lib/active_support/core_ext/hash/transform_values.rb +11 -5
  50. data/lib/active_support/core_ext/integer/time.rb +1 -16
  51. data/lib/active_support/core_ext/kernel/concern.rb +2 -0
  52. data/lib/active_support/core_ext/kernel/debugger.rb +3 -10
  53. data/lib/active_support/core_ext/kernel/reporting.rb +2 -83
  54. data/lib/active_support/core_ext/kernel.rb +0 -1
  55. data/lib/active_support/core_ext/load_error.rb +4 -2
  56. data/lib/active_support/core_ext/marshal.rb +12 -11
  57. data/lib/active_support/core_ext/module/aliasing.rb +6 -1
  58. data/lib/active_support/core_ext/module/anonymous.rb +10 -1
  59. data/lib/active_support/core_ext/module/attr_internal.rb +2 -5
  60. data/lib/active_support/core_ext/module/attribute_accessors.rb +15 -15
  61. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +141 -0
  62. data/lib/active_support/core_ext/module/concerning.rb +4 -4
  63. data/lib/active_support/core_ext/module/delegation.rb +35 -25
  64. data/lib/active_support/core_ext/module/deprecation.rb +2 -2
  65. data/lib/active_support/core_ext/module/introspection.rb +4 -0
  66. data/lib/active_support/core_ext/module/method_transplanting.rb +3 -11
  67. data/lib/active_support/core_ext/module/qualified_const.rb +30 -12
  68. data/lib/active_support/core_ext/module/remove_method.rb +23 -0
  69. data/lib/active_support/core_ext/module.rb +1 -0
  70. data/lib/active_support/core_ext/name_error.rb +15 -2
  71. data/lib/active_support/core_ext/numeric/bytes.rb +20 -0
  72. data/lib/active_support/core_ext/numeric/conversions.rb +74 -64
  73. data/lib/active_support/core_ext/numeric/inquiry.rb +26 -0
  74. data/lib/active_support/core_ext/numeric/time.rb +24 -19
  75. data/lib/active_support/core_ext/numeric.rb +1 -0
  76. data/lib/active_support/core_ext/object/blank.rb +17 -5
  77. data/lib/active_support/core_ext/object/deep_dup.rb +10 -3
  78. data/lib/active_support/core_ext/object/duplicable.rb +8 -13
  79. data/lib/active_support/core_ext/object/inclusion.rb +2 -2
  80. data/lib/active_support/core_ext/object/instance_variables.rb +1 -1
  81. data/lib/active_support/core_ext/object/json.rb +15 -7
  82. data/lib/active_support/core_ext/object/to_query.rb +1 -1
  83. data/lib/active_support/core_ext/object/try.rb +68 -22
  84. data/lib/active_support/core_ext/object/with_options.rb +1 -1
  85. data/lib/active_support/core_ext/object.rb +0 -1
  86. data/lib/active_support/core_ext/range/conversions.rb +18 -6
  87. data/lib/active_support/core_ext/range/each.rb +16 -18
  88. data/lib/active_support/core_ext/range/include_range.rb +20 -20
  89. data/lib/active_support/core_ext/securerandom.rb +23 -0
  90. data/lib/active_support/core_ext/string/access.rb +1 -1
  91. data/lib/active_support/core_ext/string/behavior.rb +1 -1
  92. data/lib/active_support/core_ext/string/conversions.rb +4 -3
  93. data/lib/active_support/core_ext/string/filters.rb +5 -5
  94. data/lib/active_support/core_ext/string/inflections.rb +32 -5
  95. data/lib/active_support/core_ext/string/multibyte.rb +11 -7
  96. data/lib/active_support/core_ext/string/output_safety.rb +18 -16
  97. data/lib/active_support/core_ext/string/strip.rb +3 -6
  98. data/lib/active_support/core_ext/struct.rb +3 -6
  99. data/lib/active_support/core_ext/time/calculations.rb +36 -11
  100. data/lib/active_support/core_ext/time/compatibility.rb +5 -0
  101. data/lib/active_support/core_ext/time/conversions.rb +4 -2
  102. data/lib/active_support/core_ext/time/marshal.rb +2 -29
  103. data/lib/active_support/core_ext/time/zones.rb +36 -4
  104. data/lib/active_support/core_ext/time.rb +1 -1
  105. data/lib/active_support/core_ext/uri.rb +1 -3
  106. data/lib/active_support/core_ext.rb +2 -1
  107. data/lib/active_support/dependencies/interlock.rb +51 -0
  108. data/lib/active_support/dependencies.rb +87 -95
  109. data/lib/active_support/deprecation/behaviors.rb +16 -2
  110. data/lib/active_support/deprecation/method_wrappers.rb +42 -16
  111. data/lib/active_support/deprecation/proxy_wrappers.rb +47 -24
  112. data/lib/active_support/deprecation/reporting.rb +23 -5
  113. data/lib/active_support/deprecation.rb +1 -1
  114. data/lib/active_support/duration/iso8601_parser.rb +122 -0
  115. data/lib/active_support/duration/iso8601_serializer.rb +51 -0
  116. data/lib/active_support/duration.rb +55 -10
  117. data/lib/active_support/evented_file_update_checker.rb +194 -0
  118. data/lib/active_support/execution_wrapper.rb +117 -0
  119. data/lib/active_support/executor.rb +6 -0
  120. data/lib/active_support/file_update_checker.rb +23 -3
  121. data/lib/active_support/gem_version.rb +4 -4
  122. data/lib/active_support/hash_with_indifferent_access.rb +46 -13
  123. data/lib/active_support/i18n_railtie.rb +25 -4
  124. data/lib/active_support/inflector/inflections.rb +36 -5
  125. data/lib/active_support/inflector/methods.rb +97 -90
  126. data/lib/active_support/inflector/transliterate.rb +36 -21
  127. data/lib/active_support/json/decoding.rb +11 -10
  128. data/lib/active_support/json/encoding.rb +4 -49
  129. data/lib/active_support/key_generator.rb +7 -9
  130. data/lib/active_support/locale/en.yml +2 -0
  131. data/lib/active_support/log_subscriber/test_helper.rb +3 -3
  132. data/lib/active_support/log_subscriber.rb +1 -1
  133. data/lib/active_support/logger.rb +50 -1
  134. data/lib/active_support/logger_silence.rb +8 -4
  135. data/lib/active_support/logger_thread_safe_level.rb +31 -0
  136. data/lib/active_support/message_encryptor.rb +4 -4
  137. data/lib/active_support/message_verifier.rb +70 -8
  138. data/lib/active_support/multibyte/chars.rb +13 -4
  139. data/lib/active_support/multibyte/unicode.rb +44 -21
  140. data/lib/active_support/notifications/fanout.rb +6 -6
  141. data/lib/active_support/notifications/instrumenter.rb +20 -2
  142. data/lib/active_support/notifications.rb +2 -2
  143. data/lib/active_support/number_helper/number_to_currency_converter.rb +7 -9
  144. data/lib/active_support/number_helper/number_to_delimited_converter.rb +8 -3
  145. data/lib/active_support/number_helper/number_to_human_converter.rb +6 -4
  146. data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -2
  147. data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
  148. data/lib/active_support/number_helper/number_to_phone_converter.rb +11 -2
  149. data/lib/active_support/number_helper/number_to_rounded_converter.rb +30 -25
  150. data/lib/active_support/number_helper.rb +90 -67
  151. data/lib/active_support/ordered_hash.rb +1 -1
  152. data/lib/active_support/ordered_options.rb +15 -1
  153. data/lib/active_support/per_thread_registry.rb +8 -3
  154. data/lib/active_support/rails.rb +2 -2
  155. data/lib/active_support/railtie.rb +6 -1
  156. data/lib/active_support/reloader.rb +129 -0
  157. data/lib/active_support/rescuable.rb +93 -47
  158. data/lib/active_support/security_utils.rb +7 -0
  159. data/lib/active_support/string_inquirer.rb +1 -1
  160. data/lib/active_support/subscriber.rb +5 -10
  161. data/lib/active_support/tagged_logging.rb +3 -1
  162. data/lib/active_support/test_case.rb +15 -29
  163. data/lib/active_support/testing/assertions.rb +15 -13
  164. data/lib/active_support/testing/autorun.rb +8 -1
  165. data/lib/active_support/testing/deprecation.rb +9 -8
  166. data/lib/active_support/testing/file_fixtures.rb +34 -0
  167. data/lib/active_support/testing/isolation.rb +22 -8
  168. data/lib/active_support/testing/method_call_assertions.rb +41 -0
  169. data/lib/active_support/testing/stream.rb +42 -0
  170. data/lib/active_support/testing/time_helpers.rb +13 -10
  171. data/lib/active_support/time_with_zone.rb +135 -46
  172. data/lib/active_support/values/time_zone.rb +95 -47
  173. data/lib/active_support/values/unicode_tables.dat +0 -0
  174. data/lib/active_support/xml_mini/jdom.rb +7 -6
  175. data/lib/active_support/xml_mini/libxml.rb +2 -2
  176. data/lib/active_support/xml_mini/nokogiri.rb +2 -2
  177. data/lib/active_support/xml_mini/rexml.rb +7 -8
  178. data/lib/active_support/xml_mini.rb +22 -14
  179. data/lib/active_support.rb +20 -6
  180. metadata +33 -35
  181. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -14
  182. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  183. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
  184. data/lib/active_support/core_ext/object/itself.rb +0 -15
  185. data/lib/active_support/core_ext/thread.rb +0 -86
@@ -1,23 +1,27 @@
1
1
  class Hash
2
- # Returns a new hash with all keys converted using the block operation.
2
+ # Returns a new hash with all keys converted using the +block+ operation.
3
3
  #
4
4
  # hash = { name: 'Rob', age: '28' }
5
5
  #
6
- # hash.transform_keys{ |key| key.to_s.upcase }
7
- # # => {"NAME"=>"Rob", "AGE"=>"28"}
6
+ # hash.transform_keys { |key| key.to_s.upcase } # => {"NAME"=>"Rob", "AGE"=>"28"}
7
+ #
8
+ # If you do not provide a +block+, it will return an Enumerator
9
+ # for chaining with other methods:
10
+ #
11
+ # hash.transform_keys.with_index { |k, i| [k, i].join } # => {"name0"=>"Rob", "age1"=>"28"}
8
12
  def transform_keys
9
- return enum_for(:transform_keys) unless block_given?
10
- result = self.class.new
13
+ return enum_for(:transform_keys) { size } unless block_given?
14
+ result = {}
11
15
  each_key do |key|
12
16
  result[yield(key)] = self[key]
13
17
  end
14
18
  result
15
19
  end
16
20
 
17
- # Destructively convert all keys using the block operations.
18
- # Same as transform_keys but modifies +self+.
21
+ # Destructively converts all keys using the +block+ operations.
22
+ # Same as +transform_keys+ but modifies +self+.
19
23
  def transform_keys!
20
- return enum_for(:transform_keys!) unless block_given?
24
+ return enum_for(:transform_keys!) { size } unless block_given?
21
25
  keys.each do |key|
22
26
  self[yield(key)] = delete(key)
23
27
  end
@@ -31,13 +35,13 @@ class Hash
31
35
  # hash.stringify_keys
32
36
  # # => {"name"=>"Rob", "age"=>"28"}
33
37
  def stringify_keys
34
- transform_keys{ |key| key.to_s }
38
+ transform_keys(&:to_s)
35
39
  end
36
40
 
37
- # Destructively convert all keys to strings. Same as
41
+ # Destructively converts all keys to strings. Same as
38
42
  # +stringify_keys+, but modifies +self+.
39
43
  def stringify_keys!
40
- transform_keys!{ |key| key.to_s }
44
+ transform_keys!(&:to_s)
41
45
  end
42
46
 
43
47
  # Returns a new hash with all keys converted to symbols, as long as
@@ -52,15 +56,15 @@ class Hash
52
56
  end
53
57
  alias_method :to_options, :symbolize_keys
54
58
 
55
- # Destructively convert all keys to symbols, as long as they respond
59
+ # Destructively converts all keys to symbols, as long as they respond
56
60
  # to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
57
61
  def symbolize_keys!
58
62
  transform_keys!{ |key| key.to_sym rescue key }
59
63
  end
60
64
  alias_method :to_options!, :symbolize_keys!
61
65
 
62
- # Validate all keys in a hash match <tt>*valid_keys</tt>, raising
63
- # ArgumentError on a mismatch.
66
+ # Validates all keys in a hash match <tt>*valid_keys</tt>, raising
67
+ # +ArgumentError+ on a mismatch.
64
68
  #
65
69
  # Note that keys are treated differently than HashWithIndifferentAccess,
66
70
  # meaning that string and symbol keys will not match.
@@ -89,7 +93,7 @@ class Hash
89
93
  _deep_transform_keys_in_object(self, &block)
90
94
  end
91
95
 
92
- # Destructively convert all keys by using the block operation.
96
+ # Destructively converts all keys by using the block operation.
93
97
  # This includes the keys from the root hash and from all
94
98
  # nested hashes and arrays.
95
99
  def deep_transform_keys!(&block)
@@ -105,14 +109,14 @@ class Hash
105
109
  # hash.deep_stringify_keys
106
110
  # # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
107
111
  def deep_stringify_keys
108
- deep_transform_keys{ |key| key.to_s }
112
+ deep_transform_keys(&:to_s)
109
113
  end
110
114
 
111
- # Destructively convert all keys to strings.
115
+ # Destructively converts all keys to strings.
112
116
  # This includes the keys from the root hash and from all
113
117
  # nested hashes and arrays.
114
118
  def deep_stringify_keys!
115
- deep_transform_keys!{ |key| key.to_s }
119
+ deep_transform_keys!(&:to_s)
116
120
  end
117
121
 
118
122
  # Returns a new hash with all keys converted to symbols, as long as
@@ -127,7 +131,7 @@ class Hash
127
131
  deep_transform_keys{ |key| key.to_sym rescue key }
128
132
  end
129
133
 
130
- # Destructively convert all keys to symbols, as long as they respond
134
+ # Destructively converts all keys to symbols, as long as they respond
131
135
  # to +to_sym+. This includes the keys from the root hash and from all
132
136
  # nested hashes and arrays.
133
137
  def deep_symbolize_keys!
@@ -1,5 +1,5 @@
1
1
  class Hash
2
- # Slice a hash to include only the given keys. Returns a hash containing
2
+ # Slices a hash to include only the given keys. Returns a hash containing
3
3
  # the given keys.
4
4
  #
5
5
  # { a: 1, b: 2, c: 3, d: 4 }.slice(:a, :b)
@@ -2,10 +2,15 @@ class Hash
2
2
  # Returns a new hash with the results of running +block+ once for every value.
3
3
  # The keys are unchanged.
4
4
  #
5
- # { a: 1, b: 2, c: 3 }.transform_values { |x| x * 2 }
6
- # # => { a: 2, b: 4, c: 6 }
5
+ # { a: 1, b: 2, c: 3 }.transform_values { |x| x * 2 } # => { a: 2, b: 4, c: 6 }
6
+ #
7
+ # If you do not provide a +block+, it will return an Enumerator
8
+ # for chaining with other methods:
9
+ #
10
+ # { a: 1, b: 2 }.transform_values.with_index { |v, i| [v, i].join.to_i } # => { a: 10, b: 21 }
7
11
  def transform_values
8
- return enum_for(:transform_values) unless block_given?
12
+ return enum_for(:transform_values) { size } unless block_given?
13
+ return {} if empty?
9
14
  result = self.class.new
10
15
  each do |key, value|
11
16
  result[key] = yield(value)
@@ -13,9 +18,10 @@ class Hash
13
18
  result
14
19
  end
15
20
 
16
- # Destructive +transform_values+
21
+ # Destructively converts all values using the +block+ operations.
22
+ # Same as +transform_values+ but modifies +self+.
17
23
  def transform_values!
18
- return enum_for(:transform_values!) unless block_given?
24
+ return enum_for(:transform_values!) { size } unless block_given?
19
25
  each do |key, value|
20
26
  self[key] = yield(value)
21
27
  end
@@ -17,28 +17,13 @@ class Integer
17
17
  #
18
18
  # # equivalent to Time.now.advance(months: 4, years: 5)
19
19
  # (4.months + 5.years).from_now
20
- #
21
- # While these methods provide precise calculation when used as in the examples
22
- # above, care should be taken to note that this is not true if the result of
23
- # +months+, +years+, etc is converted before use:
24
- #
25
- # # equivalent to 30.days.to_i.from_now
26
- # 1.month.to_i.from_now
27
- #
28
- # # equivalent to 365.25.days.to_f.from_now
29
- # 1.year.to_f.from_now
30
- #
31
- # In such cases, Ruby's core
32
- # Date[http://ruby-doc.org/stdlib/libdoc/date/rdoc/Date.html] and
33
- # Time[http://ruby-doc.org/stdlib/libdoc/time/rdoc/Time.html] should be used for precision
34
- # date and time arithmetic.
35
20
  def months
36
21
  ActiveSupport::Duration.new(self * 30.days, [[:months, self]])
37
22
  end
38
23
  alias :month :months
39
24
 
40
25
  def years
41
- ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]])
26
+ ActiveSupport::Duration.new(self * 365.25.days.to_i, [[:years, self]])
42
27
  end
43
28
  alias :year :years
44
29
  end
@@ -1,6 +1,8 @@
1
1
  require 'active_support/core_ext/module/concerning'
2
2
 
3
3
  module Kernel
4
+ module_function
5
+
4
6
  # A shortcut to define a toplevel concern, not within a module.
5
7
  #
6
8
  # See Module::Concerning for more.
@@ -1,10 +1,3 @@
1
- module Kernel
2
- unless respond_to?(:debugger)
3
- # Starts a debugging session if the +debugger+ gem has been loaded (call rails server --debugger to do load it).
4
- def debugger
5
- message = "\n***** Debugger requested, but was not available (ensure the debugger gem is listed in Gemfile/installed as gem): Start server with --debugger to enable *****\n"
6
- defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
7
- end
8
- alias breakpoint debugger unless respond_to?(:breakpoint)
9
- end
10
- end
1
+ require 'active_support/deprecation'
2
+
3
+ ActiveSupport::Deprecation.warn("This file is deprecated and will be removed in Rails 5.1 with no replacement.")
@@ -1,7 +1,6 @@
1
- require 'rbconfig'
2
- require 'tempfile'
3
-
4
1
  module Kernel
2
+ module_function
3
+
5
4
  # Sets $VERBOSE to nil for the duration of the block and back to its original
6
5
  # value afterwards.
7
6
  #
@@ -29,34 +28,6 @@ module Kernel
29
28
  $VERBOSE = old_verbose
30
29
  end
31
30
 
32
- # For compatibility
33
- def silence_stderr #:nodoc:
34
- ActiveSupport::Deprecation.warn(
35
- "`#silence_stderr` is deprecated and will be removed in the next release."
36
- ) #not thread-safe
37
- silence_stream(STDERR) { yield }
38
- end
39
-
40
- # Deprecated : this method is not thread safe
41
- # Silences any stream for the duration of the block.
42
- #
43
- # silence_stream(STDOUT) do
44
- # puts 'This will never be seen'
45
- # end
46
- #
47
- # puts 'But this will'
48
- #
49
- # This method is not thread-safe.
50
- def silence_stream(stream)
51
- old_stream = stream.dup
52
- stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
53
- stream.sync = true
54
- yield
55
- ensure
56
- stream.reopen(old_stream)
57
- old_stream.close
58
- end
59
-
60
31
  # Blocks and ignores any exception passed as argument if raised within the block.
61
32
  #
62
33
  # suppress(ZeroDivisionError) do
@@ -69,56 +40,4 @@ module Kernel
69
40
  yield
70
41
  rescue *exception_classes
71
42
  end
72
-
73
- # Captures the given stream and returns it:
74
- #
75
- # stream = capture(:stdout) { puts 'notice' }
76
- # stream # => "notice\n"
77
- #
78
- # stream = capture(:stderr) { warn 'error' }
79
- # stream # => "error\n"
80
- #
81
- # even for subprocesses:
82
- #
83
- # stream = capture(:stdout) { system('echo notice') }
84
- # stream # => "notice\n"
85
- #
86
- # stream = capture(:stderr) { system('echo error 1>&2') }
87
- # stream # => "error\n"
88
- def capture(stream)
89
- ActiveSupport::Deprecation.warn(
90
- "`#capture(stream)` is deprecated and will be removed in the next release."
91
- ) #not thread-safe
92
- stream = stream.to_s
93
- captured_stream = Tempfile.new(stream)
94
- stream_io = eval("$#{stream}")
95
- origin_stream = stream_io.dup
96
- stream_io.reopen(captured_stream)
97
-
98
- yield
99
-
100
- stream_io.rewind
101
- return captured_stream.read
102
- ensure
103
- captured_stream.close
104
- captured_stream.unlink
105
- stream_io.reopen(origin_stream)
106
- end
107
- alias :silence :capture
108
-
109
- # Silences both STDOUT and STDERR, even for subprocesses.
110
- #
111
- # quietly { system 'bundle install' }
112
- #
113
- # This method is not thread-safe.
114
- def quietly
115
- ActiveSupport::Deprecation.warn(
116
- "`#quietly` is deprecated and will be removed in the next release."
117
- ) #not thread-safe
118
- silence_stream(STDOUT) do
119
- silence_stream(STDERR) do
120
- yield
121
- end
122
- end
123
- end
124
43
  end
@@ -1,5 +1,4 @@
1
1
  require 'active_support/core_ext/kernel/agnostics'
2
2
  require 'active_support/core_ext/kernel/concern'
3
- require 'active_support/core_ext/kernel/debugger' if RUBY_VERSION < '2.0.0'
4
3
  require 'active_support/core_ext/kernel/reporting'
5
4
  require 'active_support/core_ext/kernel/singleton_class'
@@ -1,3 +1,5 @@
1
+ require 'active_support/deprecation/proxy_wrappers'
2
+
1
3
  class LoadError
2
4
  REGEXPS = [
3
5
  /^no such file to load -- (.+)$/i,
@@ -21,8 +23,8 @@ class LoadError
21
23
  # Returns true if the given path name (except perhaps for the ".rb"
22
24
  # extension) is the missing file which caused the exception to be raised.
23
25
  def is_missing?(location)
24
- location.sub(/\.rb$/, '') == path.sub(/\.rb$/, '')
26
+ location.sub(/\.rb$/, ''.freeze) == path.sub(/\.rb$/, ''.freeze)
25
27
  end
26
28
  end
27
29
 
28
- MissingSourceFile = LoadError
30
+ MissingSourceFile = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('MissingSourceFile', 'LoadError')
@@ -1,21 +1,22 @@
1
- require 'active_support/core_ext/module/aliasing'
2
-
3
- module Marshal
4
- class << self
5
- def load_with_autoloading(source)
6
- load_without_autoloading(source)
1
+ module ActiveSupport
2
+ module MarshalWithAutoloading # :nodoc:
3
+ def load(source)
4
+ super(source)
7
5
  rescue ArgumentError, NameError => exc
8
- if exc.message.match(%r|undefined class/module (.+)|)
6
+ if exc.message.match(%r|undefined class/module (.+?)(?:::)?\z|)
9
7
  # try loading the class/module
10
- $1.constantize
11
- # if it is a IO we need to go back to read the object
8
+ loaded = $1.constantize
9
+
10
+ raise unless $1 == loaded.name
11
+
12
+ # if it is an IO we need to go back to read the object
12
13
  source.rewind if source.respond_to?(:rewind)
13
14
  retry
14
15
  else
15
16
  raise exc
16
17
  end
17
18
  end
18
-
19
- alias_method_chain :load, :autoloading
20
19
  end
21
20
  end
21
+
22
+ Marshal.singleton_class.prepend(ActiveSupport::MarshalWithAutoloading)
@@ -1,4 +1,7 @@
1
1
  class Module
2
+ # NOTE: This method is deprecated. Please use <tt>Module#prepend</tt> that
3
+ # comes with Ruby 2.0 or newer instead.
4
+ #
2
5
  # Encapsulates the common pattern of:
3
6
  #
4
7
  # alias_method :foo_without_feature, :foo
@@ -21,6 +24,8 @@ class Module
21
24
  #
22
25
  # so you can safely chain foo, foo?, foo! and/or foo= with the same feature.
23
26
  def alias_method_chain(target, feature)
27
+ ActiveSupport::Deprecation.warn("alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super.")
28
+
24
29
  # Strip out punctuation on predicates, bang or writer methods since
25
30
  # e.g. target?_without_feature is not a valid method name.
26
31
  aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
@@ -43,7 +48,7 @@ class Module
43
48
  end
44
49
 
45
50
  # Allows you to make aliases for attributes, which includes
46
- # getter, setter, and query methods.
51
+ # getter, setter, and a predicate.
47
52
  #
48
53
  # class Content < ActiveRecord::Base
49
54
  # # has a title attribute
@@ -7,12 +7,21 @@ class Module
7
7
  # m = Module.new
8
8
  # m.name # => nil
9
9
  #
10
+ # +anonymous?+ method returns true if module does not have a name, false otherwise:
11
+ #
12
+ # Module.new.anonymous? # => true
13
+ #
14
+ # module M; end
15
+ # M.anonymous? # => false
16
+ #
10
17
  # A module gets a name when it is first assigned to a constant. Either
11
18
  # via the +module+ or +class+ keyword or by an explicit assignment:
12
19
  #
13
20
  # m = Module.new # creates an anonymous module
14
- # M = m # => m gets a name here as a side-effect
21
+ # m.anonymous? # => true
22
+ # M = m # m gets a name here as a side-effect
15
23
  # m.name # => "M"
24
+ # m.anonymous? # => false
16
25
  def anonymous?
17
26
  name.nil?
18
27
  end
@@ -27,11 +27,8 @@ class Module
27
27
 
28
28
  def attr_internal_define(attr_name, type)
29
29
  internal_name = attr_internal_ivar_name(attr_name).sub(/\A@/, '')
30
- # class_eval is necessary on 1.9 or else the methods are made private
31
- class_eval do
32
- # use native attr_* methods as they are faster on some Ruby implementations
33
- send("attr_#{type}", internal_name)
34
- end
30
+ # use native attr_* methods as they are faster on some Ruby implementations
31
+ send("attr_#{type}", internal_name)
35
32
  attr_name, internal_name = "#{attr_name}=", "#{internal_name}=" if type == :writer
36
33
  alias_method attr_name, internal_name
37
34
  remove_method internal_name
@@ -5,7 +5,7 @@ require 'active_support/core_ext/array/extract_options'
5
5
  # attributes.
6
6
  class Module
7
7
  # Defines a class attribute and creates a class and instance reader methods.
8
- # The underlying the class variable is set to +nil+, if it is not previously
8
+ # The underlying class variable is set to +nil+, if it is not previously
9
9
  # defined.
10
10
  #
11
11
  # module HairColors
@@ -19,15 +19,15 @@ class Module
19
19
  # The attribute name must be a valid method name in Ruby.
20
20
  #
21
21
  # module Foo
22
- # mattr_reader :"1_Badname "
22
+ # mattr_reader :"1_Badname"
23
23
  # end
24
- # # => NameError: invalid attribute name
24
+ # # => NameError: invalid attribute name: 1_Badname
25
25
  #
26
26
  # If you want to opt out the creation on the instance reader method, pass
27
27
  # <tt>instance_reader: false</tt> or <tt>instance_accessor: false</tt>.
28
28
  #
29
29
  # module HairColors
30
- # mattr_writer :hair_colors, instance_reader: false
30
+ # mattr_reader :hair_colors, instance_reader: false
31
31
  # end
32
32
  #
33
33
  # class Person
@@ -40,7 +40,7 @@ class Module
40
40
  # Also, you can pass a block to set up the attribute with a default value.
41
41
  #
42
42
  # module HairColors
43
- # cattr_reader :hair_colors do
43
+ # mattr_reader :hair_colors do
44
44
  # [:brown, :black, :blonde, :red]
45
45
  # end
46
46
  # end
@@ -49,11 +49,11 @@ class Module
49
49
  # include HairColors
50
50
  # end
51
51
  #
52
- # Person.hair_colors # => [:brown, :black, :blonde, :red]
52
+ # Person.new.hair_colors # => [:brown, :black, :blonde, :red]
53
53
  def mattr_reader(*syms)
54
54
  options = syms.extract_options!
55
55
  syms.each do |sym|
56
- raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
56
+ raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /\A[_A-Za-z]\w*\z/
57
57
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
58
58
  @@#{sym} = nil unless defined? @@#{sym}
59
59
 
@@ -105,7 +105,7 @@ class Module
105
105
  #
106
106
  # Also, you can pass a block to set up the attribute with a default value.
107
107
  #
108
- # class HairColors
108
+ # module HairColors
109
109
  # mattr_writer :hair_colors do
110
110
  # [:brown, :black, :blonde, :red]
111
111
  # end
@@ -119,7 +119,7 @@ class Module
119
119
  def mattr_writer(*syms)
120
120
  options = syms.extract_options!
121
121
  syms.each do |sym|
122
- raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
122
+ raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /\A[_A-Za-z]\w*\z/
123
123
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
124
124
  @@#{sym} = nil unless defined? @@#{sym}
125
125
 
@@ -150,8 +150,8 @@ class Module
150
150
  # include HairColors
151
151
  # end
152
152
  #
153
- # Person.hair_colors = [:brown, :black, :blonde, :red]
154
- # Person.hair_colors # => [:brown, :black, :blonde, :red]
153
+ # HairColors.hair_colors = [:brown, :black, :blonde, :red]
154
+ # HairColors.hair_colors # => [:brown, :black, :blonde, :red]
155
155
  # Person.new.hair_colors # => [:brown, :black, :blonde, :red]
156
156
  #
157
157
  # If a subclass changes the value then that would also change the value for
@@ -161,8 +161,8 @@ class Module
161
161
  # class Male < Person
162
162
  # end
163
163
  #
164
- # Male.hair_colors << :blue
165
- # Person.hair_colors # => [:brown, :black, :blonde, :red, :blue]
164
+ # Male.new.hair_colors << :blue
165
+ # Person.new.hair_colors # => [:brown, :black, :blonde, :red, :blue]
166
166
  #
167
167
  # To opt out of the instance writer method, pass <tt>instance_writer: false</tt>.
168
168
  # To opt out of the instance reader method, pass <tt>instance_reader: false</tt>.
@@ -203,10 +203,10 @@ class Module
203
203
  # include HairColors
204
204
  # end
205
205
  #
206
- # Person.class_variable_get("@@hair_colors") #=> [:brown, :black, :blonde, :red]
206
+ # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
207
207
  def mattr_accessor(*syms, &blk)
208
208
  mattr_reader(*syms, &blk)
209
- mattr_writer(*syms, &blk)
209
+ mattr_writer(*syms)
210
210
  end
211
211
  alias :cattr_accessor :mattr_accessor
212
212
  end
@@ -0,0 +1,141 @@
1
+ require 'active_support/core_ext/array/extract_options'
2
+
3
+ # Extends the module object with class/module and instance accessors for
4
+ # class/module attributes, just like the native attr* accessors for instance
5
+ # attributes, but does so on a per-thread basis.
6
+ #
7
+ # So the values are scoped within the Thread.current space under the class name
8
+ # of the module.
9
+ class Module
10
+ # Defines a per-thread class attribute and creates class and instance reader methods.
11
+ # The underlying per-thread class variable is set to +nil+, if it is not previously defined.
12
+ #
13
+ # module Current
14
+ # thread_mattr_reader :user
15
+ # end
16
+ #
17
+ # Current.user # => nil
18
+ # Thread.current[:attr_Current_user] = "DHH"
19
+ # Current.user # => "DHH"
20
+ #
21
+ # The attribute name must be a valid method name in Ruby.
22
+ #
23
+ # module Foo
24
+ # thread_mattr_reader :"1_Badname"
25
+ # end
26
+ # # => NameError: invalid attribute name: 1_Badname
27
+ #
28
+ # If you want to opt out the creation on the instance reader method, pass
29
+ # <tt>instance_reader: false</tt> or <tt>instance_accessor: false</tt>.
30
+ #
31
+ # class Current
32
+ # thread_mattr_reader :user, instance_reader: false
33
+ # end
34
+ #
35
+ # Current.new.user # => NoMethodError
36
+ def thread_mattr_reader(*syms)
37
+ options = syms.extract_options!
38
+
39
+ syms.each do |sym|
40
+ raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
41
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
42
+ def self.#{sym}
43
+ Thread.current[:"attr_#{name}_#{sym}"]
44
+ end
45
+ EOS
46
+
47
+ unless options[:instance_reader] == false || options[:instance_accessor] == false
48
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
49
+ def #{sym}
50
+ Thread.current[:"attr_#{name}_#{sym}"]
51
+ end
52
+ EOS
53
+ end
54
+ end
55
+ end
56
+ alias :thread_cattr_reader :thread_mattr_reader
57
+
58
+ # Defines a per-thread class attribute and creates a class and instance writer methods to
59
+ # allow assignment to the attribute.
60
+ #
61
+ # module Current
62
+ # thread_mattr_writer :user
63
+ # end
64
+ #
65
+ # Current.user = "DHH"
66
+ # Thread.current[:attr_Current_user] # => "DHH"
67
+ #
68
+ # If you want to opt out the instance writer method, pass
69
+ # <tt>instance_writer: false</tt> or <tt>instance_accessor: false</tt>.
70
+ #
71
+ # class Current
72
+ # thread_mattr_writer :user, instance_writer: false
73
+ # end
74
+ #
75
+ # Current.new.user = "DHH" # => NoMethodError
76
+ def thread_mattr_writer(*syms)
77
+ options = syms.extract_options!
78
+ syms.each do |sym|
79
+ raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
80
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
81
+ def self.#{sym}=(obj)
82
+ Thread.current[:"attr_#{name}_#{sym}"] = obj
83
+ end
84
+ EOS
85
+
86
+ unless options[:instance_writer] == false || options[:instance_accessor] == false
87
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
88
+ def #{sym}=(obj)
89
+ Thread.current[:"attr_#{name}_#{sym}"] = obj
90
+ end
91
+ EOS
92
+ end
93
+ end
94
+ end
95
+ alias :thread_cattr_writer :thread_mattr_writer
96
+
97
+ # Defines both class and instance accessors for class attributes.
98
+ #
99
+ # class Account
100
+ # thread_mattr_accessor :user
101
+ # end
102
+ #
103
+ # Account.user = "DHH"
104
+ # Account.user # => "DHH"
105
+ # Account.new.user # => "DHH"
106
+ #
107
+ # If a subclass changes the value, the parent class' value is not changed.
108
+ # Similarly, if the parent class changes the value, the value of subclasses
109
+ # is not changed.
110
+ #
111
+ # class Customer < Account
112
+ # end
113
+ #
114
+ # Customer.user = "Rafael"
115
+ # Customer.user # => "Rafael"
116
+ # Account.user # => "DHH"
117
+ #
118
+ # To opt out of the instance writer method, pass <tt>instance_writer: false</tt>.
119
+ # To opt out of the instance reader method, pass <tt>instance_reader: false</tt>.
120
+ #
121
+ # class Current
122
+ # thread_mattr_accessor :user, instance_writer: false, instance_reader: false
123
+ # end
124
+ #
125
+ # Current.new.user = "DHH" # => NoMethodError
126
+ # Current.new.user # => NoMethodError
127
+ #
128
+ # Or pass <tt>instance_accessor: false</tt>, to opt out both instance methods.
129
+ #
130
+ # class Current
131
+ # mattr_accessor :user, instance_accessor: false
132
+ # end
133
+ #
134
+ # Current.new.user = "DHH" # => NoMethodError
135
+ # Current.new.user # => NoMethodError
136
+ def thread_mattr_accessor(*syms, &blk)
137
+ thread_mattr_reader(*syms, &blk)
138
+ thread_mattr_writer(*syms, &blk)
139
+ end
140
+ alias :thread_cattr_accessor :thread_mattr_accessor
141
+ end