activesupport 5.1.7 → 5.2.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 (238) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +303 -617
  3. data/README.rdoc +1 -1
  4. data/lib/active_support.rb +3 -12
  5. data/lib/active_support/all.rb +2 -0
  6. data/lib/active_support/array_inquirer.rb +2 -0
  7. data/lib/active_support/backtrace_cleaner.rb +2 -0
  8. data/lib/active_support/benchmarkable.rb +2 -0
  9. data/lib/active_support/builder.rb +2 -0
  10. data/lib/active_support/cache.rb +127 -58
  11. data/lib/active_support/cache/file_store.rb +4 -3
  12. data/lib/active_support/cache/mem_cache_store.rb +12 -4
  13. data/lib/active_support/cache/memory_store.rb +2 -0
  14. data/lib/active_support/cache/null_store.rb +2 -0
  15. data/lib/active_support/cache/redis_cache_store.rb +404 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +9 -2
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +2 -0
  18. data/lib/active_support/callbacks.rb +26 -37
  19. data/lib/active_support/concern.rb +3 -1
  20. data/lib/active_support/concurrency/share_lock.rb +2 -0
  21. data/lib/active_support/configurable.rb +2 -0
  22. data/lib/active_support/core_ext.rb +3 -1
  23. data/lib/active_support/core_ext/array.rb +2 -0
  24. data/lib/active_support/core_ext/array/access.rb +4 -2
  25. data/lib/active_support/core_ext/array/conversions.rb +2 -0
  26. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  27. data/lib/active_support/core_ext/array/grouping.rb +2 -0
  28. data/lib/active_support/core_ext/array/inquiry.rb +2 -0
  29. data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -2
  30. data/lib/active_support/core_ext/array/wrap.rb +2 -0
  31. data/lib/active_support/core_ext/benchmark.rb +2 -0
  32. data/lib/active_support/core_ext/big_decimal.rb +2 -0
  33. data/lib/active_support/core_ext/big_decimal/conversions.rb +2 -0
  34. data/lib/active_support/core_ext/class.rb +2 -0
  35. data/lib/active_support/core_ext/class/attribute.rb +34 -16
  36. data/lib/active_support/core_ext/class/attribute_accessors.rb +2 -0
  37. data/lib/active_support/core_ext/class/subclasses.rb +1 -2
  38. data/lib/active_support/core_ext/date.rb +2 -0
  39. data/lib/active_support/core_ext/date/acts_like.rb +2 -0
  40. data/lib/active_support/core_ext/date/blank.rb +2 -0
  41. data/lib/active_support/core_ext/date/calculations.rb +2 -0
  42. data/lib/active_support/core_ext/date/conversions.rb +10 -9
  43. data/lib/active_support/core_ext/date/zones.rb +2 -0
  44. data/lib/active_support/core_ext/date_and_time/calculations.rb +42 -16
  45. data/lib/active_support/core_ext/date_and_time/compatibility.rb +3 -1
  46. data/lib/active_support/core_ext/date_and_time/zones.rb +2 -0
  47. data/lib/active_support/core_ext/date_time.rb +2 -0
  48. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -0
  49. data/lib/active_support/core_ext/date_time/blank.rb +2 -0
  50. data/lib/active_support/core_ext/date_time/calculations.rb +2 -0
  51. data/lib/active_support/core_ext/date_time/compatibility.rb +6 -4
  52. data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
  53. data/lib/active_support/core_ext/digest/uuid.rb +3 -1
  54. data/lib/active_support/core_ext/enumerable.rb +3 -1
  55. data/lib/active_support/core_ext/file.rb +2 -0
  56. data/lib/active_support/core_ext/file/atomic.rb +2 -0
  57. data/lib/active_support/core_ext/hash.rb +2 -0
  58. data/lib/active_support/core_ext/hash/compact.rb +2 -0
  59. data/lib/active_support/core_ext/hash/conversions.rb +2 -0
  60. data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
  61. data/lib/active_support/core_ext/hash/except.rb +2 -0
  62. data/lib/active_support/core_ext/hash/indifferent_access.rb +2 -0
  63. data/lib/active_support/core_ext/hash/keys.rb +2 -0
  64. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  65. data/lib/active_support/core_ext/hash/slice.rb +4 -4
  66. data/lib/active_support/core_ext/hash/transform_values.rb +2 -0
  67. data/lib/active_support/core_ext/integer.rb +2 -0
  68. data/lib/active_support/core_ext/integer/inflections.rb +2 -0
  69. data/lib/active_support/core_ext/integer/multiple.rb +2 -0
  70. data/lib/active_support/core_ext/integer/time.rb +7 -14
  71. data/lib/active_support/core_ext/kernel.rb +2 -0
  72. data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
  73. data/lib/active_support/core_ext/kernel/concern.rb +2 -0
  74. data/lib/active_support/core_ext/kernel/reporting.rb +2 -0
  75. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  76. data/lib/active_support/core_ext/load_error.rb +2 -7
  77. data/lib/active_support/core_ext/marshal.rb +2 -0
  78. data/lib/active_support/core_ext/module.rb +3 -0
  79. data/lib/active_support/core_ext/module/aliasing.rb +2 -0
  80. data/lib/active_support/core_ext/module/anonymous.rb +2 -0
  81. data/lib/active_support/core_ext/module/attr_internal.rb +2 -0
  82. data/lib/active_support/core_ext/module/attribute_accessors.rb +21 -24
  83. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +2 -0
  84. data/lib/active_support/core_ext/module/concerning.rb +2 -0
  85. data/lib/active_support/core_ext/module/delegation.rb +29 -24
  86. data/lib/active_support/core_ext/module/deprecation.rb +2 -0
  87. data/lib/active_support/core_ext/module/introspection.rb +2 -0
  88. data/lib/active_support/core_ext/module/reachable.rb +3 -0
  89. data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
  90. data/lib/active_support/core_ext/module/remove_method.rb +5 -23
  91. data/lib/active_support/core_ext/name_error.rb +2 -0
  92. data/lib/active_support/core_ext/numeric.rb +2 -0
  93. data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
  94. data/lib/active_support/core_ext/numeric/conversions.rb +9 -7
  95. data/lib/active_support/core_ext/numeric/inquiry.rb +2 -0
  96. data/lib/active_support/core_ext/numeric/time.rb +7 -15
  97. data/lib/active_support/core_ext/object.rb +2 -0
  98. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  99. data/lib/active_support/core_ext/object/blank.rb +2 -0
  100. data/lib/active_support/core_ext/object/conversions.rb +2 -0
  101. data/lib/active_support/core_ext/object/deep_dup.rb +2 -0
  102. data/lib/active_support/core_ext/object/duplicable.rb +10 -8
  103. data/lib/active_support/core_ext/object/inclusion.rb +2 -0
  104. data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
  105. data/lib/active_support/core_ext/object/json.rb +8 -0
  106. data/lib/active_support/core_ext/object/to_param.rb +2 -0
  107. data/lib/active_support/core_ext/object/to_query.rb +4 -5
  108. data/lib/active_support/core_ext/object/try.rb +2 -0
  109. data/lib/active_support/core_ext/object/with_options.rb +3 -1
  110. data/lib/active_support/core_ext/range.rb +3 -0
  111. data/lib/active_support/core_ext/range/conversions.rb +9 -1
  112. data/lib/active_support/core_ext/range/each.rb +5 -1
  113. data/lib/active_support/core_ext/range/include_range.rb +2 -0
  114. data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
  115. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  116. data/lib/active_support/core_ext/regexp.rb +2 -0
  117. data/lib/active_support/core_ext/securerandom.rb +2 -0
  118. data/lib/active_support/core_ext/string.rb +2 -0
  119. data/lib/active_support/core_ext/string/access.rb +2 -0
  120. data/lib/active_support/core_ext/string/behavior.rb +2 -0
  121. data/lib/active_support/core_ext/string/conversions.rb +2 -0
  122. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  123. data/lib/active_support/core_ext/string/filters.rb +2 -0
  124. data/lib/active_support/core_ext/string/indent.rb +2 -0
  125. data/lib/active_support/core_ext/string/inflections.rb +26 -12
  126. data/lib/active_support/core_ext/string/inquiry.rb +2 -0
  127. data/lib/active_support/core_ext/string/multibyte.rb +2 -0
  128. data/lib/active_support/core_ext/string/output_safety.rb +6 -7
  129. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
  130. data/lib/active_support/core_ext/string/strip.rb +2 -0
  131. data/lib/active_support/core_ext/string/zones.rb +2 -0
  132. data/lib/active_support/core_ext/time.rb +2 -0
  133. data/lib/active_support/core_ext/time/acts_like.rb +2 -0
  134. data/lib/active_support/core_ext/time/calculations.rb +23 -15
  135. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  136. data/lib/active_support/core_ext/time/conversions.rb +2 -0
  137. data/lib/active_support/core_ext/time/zones.rb +6 -4
  138. data/lib/active_support/core_ext/uri.rb +4 -1
  139. data/lib/active_support/current_attributes.rb +195 -0
  140. data/lib/active_support/dependencies.rb +15 -25
  141. data/lib/active_support/dependencies/autoload.rb +2 -0
  142. data/lib/active_support/dependencies/interlock.rb +2 -0
  143. data/lib/active_support/deprecation.rb +4 -2
  144. data/lib/active_support/deprecation/behaviors.rb +23 -8
  145. data/lib/active_support/deprecation/constant_accessor.rb +3 -1
  146. data/lib/active_support/deprecation/instance_delegator.rb +2 -0
  147. data/lib/active_support/deprecation/method_wrappers.rb +2 -7
  148. data/lib/active_support/deprecation/proxy_wrappers.rb +4 -1
  149. data/lib/active_support/deprecation/reporting.rb +4 -2
  150. data/lib/active_support/descendants_tracker.rb +2 -0
  151. data/lib/active_support/duration.rb +8 -14
  152. data/lib/active_support/duration/iso8601_parser.rb +4 -2
  153. data/lib/active_support/duration/iso8601_serializer.rb +4 -2
  154. data/lib/active_support/encrypted_configuration.rb +48 -0
  155. data/lib/active_support/encrypted_file.rb +99 -0
  156. data/lib/active_support/evented_file_update_checker.rb +2 -0
  157. data/lib/active_support/execution_wrapper.rb +2 -0
  158. data/lib/active_support/executor.rb +2 -0
  159. data/lib/active_support/file_update_checker.rb +2 -0
  160. data/lib/active_support/gem_version.rb +5 -3
  161. data/lib/active_support/gzip.rb +2 -0
  162. data/lib/active_support/hash_with_indifferent_access.rb +33 -1
  163. data/lib/active_support/i18n.rb +3 -1
  164. data/lib/active_support/i18n_railtie.rb +5 -11
  165. data/lib/active_support/inflections.rb +2 -0
  166. data/lib/active_support/inflector.rb +2 -0
  167. data/lib/active_support/inflector/inflections.rb +19 -3
  168. data/lib/active_support/inflector/methods.rb +40 -23
  169. data/lib/active_support/inflector/transliterate.rb +17 -8
  170. data/lib/active_support/json.rb +2 -0
  171. data/lib/active_support/json/decoding.rb +2 -0
  172. data/lib/active_support/json/encoding.rb +2 -0
  173. data/lib/active_support/key_generator.rb +3 -1
  174. data/lib/active_support/lazy_load_hooks.rb +2 -0
  175. data/lib/active_support/log_subscriber.rb +3 -2
  176. data/lib/active_support/log_subscriber/test_helper.rb +2 -0
  177. data/lib/active_support/logger.rb +2 -0
  178. data/lib/active_support/logger_silence.rb +3 -2
  179. data/lib/active_support/logger_thread_safe_level.rb +2 -0
  180. data/lib/active_support/message_encryptor.rb +94 -22
  181. data/lib/active_support/message_verifier.rb +78 -7
  182. data/lib/active_support/messages/metadata.rb +71 -0
  183. data/lib/active_support/messages/rotation_configuration.rb +22 -0
  184. data/lib/active_support/messages/rotator.rb +56 -0
  185. data/lib/active_support/multibyte.rb +2 -0
  186. data/lib/active_support/multibyte/chars.rb +2 -0
  187. data/lib/active_support/multibyte/unicode.rb +3 -1
  188. data/lib/active_support/notifications.rb +2 -0
  189. data/lib/active_support/notifications/fanout.rb +2 -0
  190. data/lib/active_support/notifications/instrumenter.rb +2 -0
  191. data/lib/active_support/number_helper.rb +2 -0
  192. data/lib/active_support/number_helper/number_converter.rb +2 -0
  193. data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -0
  194. data/lib/active_support/number_helper/number_to_delimited_converter.rb +2 -0
  195. data/lib/active_support/number_helper/number_to_human_converter.rb +2 -0
  196. data/lib/active_support/number_helper/number_to_human_size_converter.rb +2 -0
  197. data/lib/active_support/number_helper/number_to_percentage_converter.rb +2 -0
  198. data/lib/active_support/number_helper/number_to_phone_converter.rb +3 -1
  199. data/lib/active_support/number_helper/number_to_rounded_converter.rb +2 -20
  200. data/lib/active_support/number_helper/rounding_helper.rb +5 -3
  201. data/lib/active_support/option_merger.rb +2 -0
  202. data/lib/active_support/ordered_hash.rb +2 -0
  203. data/lib/active_support/ordered_options.rb +4 -2
  204. data/lib/active_support/per_thread_registry.rb +2 -0
  205. data/lib/active_support/proxy_object.rb +2 -0
  206. data/lib/active_support/rails.rb +2 -0
  207. data/lib/active_support/railtie.rb +27 -8
  208. data/lib/active_support/reloader.rb +7 -5
  209. data/lib/active_support/rescuable.rb +3 -2
  210. data/lib/active_support/security_utils.rb +15 -11
  211. data/lib/active_support/string_inquirer.rb +2 -0
  212. data/lib/active_support/subscriber.rb +2 -0
  213. data/lib/active_support/tagged_logging.rb +2 -0
  214. data/lib/active_support/test_case.rb +2 -1
  215. data/lib/active_support/testing/assertions.rb +6 -4
  216. data/lib/active_support/testing/autorun.rb +2 -0
  217. data/lib/active_support/testing/constant_lookup.rb +2 -0
  218. data/lib/active_support/testing/declarative.rb +2 -0
  219. data/lib/active_support/testing/deprecation.rb +2 -0
  220. data/lib/active_support/testing/file_fixtures.rb +2 -0
  221. data/lib/active_support/testing/isolation.rb +5 -5
  222. data/lib/active_support/testing/method_call_assertions.rb +2 -0
  223. data/lib/active_support/testing/setup_and_teardown.rb +2 -0
  224. data/lib/active_support/testing/stream.rb +2 -0
  225. data/lib/active_support/testing/tagged_logging.rb +2 -0
  226. data/lib/active_support/testing/time_helpers.rb +31 -2
  227. data/lib/active_support/time.rb +2 -0
  228. data/lib/active_support/time_with_zone.rb +38 -0
  229. data/lib/active_support/values/time_zone.rb +20 -12
  230. data/lib/active_support/version.rb +2 -0
  231. data/lib/active_support/xml_mini.rb +2 -0
  232. data/lib/active_support/xml_mini/jdom.rb +4 -2
  233. data/lib/active_support/xml_mini/libxml.rb +3 -1
  234. data/lib/active_support/xml_mini/libxmlsax.rb +4 -2
  235. data/lib/active_support/xml_mini/nokogiri.rb +3 -1
  236. data/lib/active_support/xml_mini/nokogirisax.rb +3 -1
  237. data/lib/active_support/xml_mini/rexml.rb +3 -1
  238. metadata +19 -15
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kernel
2
4
  # class_eval on an object acts like singleton_class.class_eval.
3
5
  def class_eval(*args, &block)
@@ -1,11 +1,6 @@
1
- class LoadError
2
- REGEXPS = [
3
- /^no such file to load -- (.+)$/i,
4
- /^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
5
- /^Missing API definition file in (.+)$/i,
6
- /^cannot load such file -- (.+)$/i,
7
- ]
1
+ # frozen_string_literal: true
8
2
 
3
+ class LoadError
9
4
  # Returns true if the given path name (except perhaps for the ".rb"
10
5
  # extension) is the missing file which caused the exception to be raised.
11
6
  def is_missing?(location)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  module MarshalWithAutoloading # :nodoc:
3
5
  def load(source, proc = nil)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/module/aliasing"
2
4
  require "active_support/core_ext/module/introspection"
3
5
  require "active_support/core_ext/module/anonymous"
@@ -8,4 +10,5 @@ require "active_support/core_ext/module/attr_internal"
8
10
  require "active_support/core_ext/module/concerning"
9
11
  require "active_support/core_ext/module/delegation"
10
12
  require "active_support/core_ext/module/deprecation"
13
+ require "active_support/core_ext/module/redefine_method"
11
14
  require "active_support/core_ext/module/remove_method"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Module
2
4
  # Allows you to make aliases for attributes, which includes
3
5
  # getter, setter, and a predicate.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Module
2
4
  # A module may or may not have a name.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Module
2
4
  # Declares an attribute reader backed by an internally-named instance variable.
3
5
  def attr_internal_reader(*attrs)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/array/extract_options"
2
4
  require "active_support/core_ext/regexp"
3
5
 
@@ -38,13 +40,10 @@ class Module
38
40
  #
39
41
  # Person.new.hair_colors # => NoMethodError
40
42
  #
41
- #
42
- # Also, you can pass a block to set up the attribute with a default value.
43
+ # You can set a default value for the attribute.
43
44
  #
44
45
  # module HairColors
45
- # mattr_reader :hair_colors do
46
- # [:brown, :black, :blonde, :red]
47
- # end
46
+ # mattr_reader :hair_colors, default: [:brown, :black, :blonde, :red]
48
47
  # end
49
48
  #
50
49
  # class Person
@@ -52,8 +51,7 @@ class Module
52
51
  # end
53
52
  #
54
53
  # Person.new.hair_colors # => [:brown, :black, :blonde, :red]
55
- def mattr_reader(*syms)
56
- options = syms.extract_options!
54
+ def mattr_reader(*syms, instance_reader: true, instance_accessor: true, default: nil)
57
55
  syms.each do |sym|
58
56
  raise NameError.new("invalid attribute name: #{sym}") unless /\A[_A-Za-z]\w*\z/.match?(sym)
59
57
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
@@ -64,14 +62,16 @@ class Module
64
62
  end
65
63
  EOS
66
64
 
67
- unless options[:instance_reader] == false || options[:instance_accessor] == false
65
+ if instance_reader && instance_accessor
68
66
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
69
67
  def #{sym}
70
68
  @@#{sym}
71
69
  end
72
70
  EOS
73
71
  end
74
- class_variable_set("@@#{sym}", yield) if block_given?
72
+
73
+ sym_default_value = (block_given? && default.nil?) ? yield : default
74
+ class_variable_set("@@#{sym}", sym_default_value) unless sym_default_value.nil?
75
75
  end
76
76
  end
77
77
  alias :cattr_reader :mattr_reader
@@ -107,12 +107,10 @@ class Module
107
107
  #
108
108
  # Person.new.hair_colors = [:blonde, :red] # => NoMethodError
109
109
  #
110
- # Also, you can pass a block to set up the attribute with a default value.
110
+ # You can set a default value for the attribute.
111
111
  #
112
112
  # module HairColors
113
- # mattr_writer :hair_colors do
114
- # [:brown, :black, :blonde, :red]
115
- # end
113
+ # mattr_writer :hair_colors, default: [:brown, :black, :blonde, :red]
116
114
  # end
117
115
  #
118
116
  # class Person
@@ -120,8 +118,7 @@ class Module
120
118
  # end
121
119
  #
122
120
  # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
123
- def mattr_writer(*syms)
124
- options = syms.extract_options!
121
+ def mattr_writer(*syms, instance_writer: true, instance_accessor: true, default: nil)
125
122
  syms.each do |sym|
126
123
  raise NameError.new("invalid attribute name: #{sym}") unless /\A[_A-Za-z]\w*\z/.match?(sym)
127
124
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
@@ -132,14 +129,16 @@ class Module
132
129
  end
133
130
  EOS
134
131
 
135
- unless options[:instance_writer] == false || options[:instance_accessor] == false
132
+ if instance_writer && instance_accessor
136
133
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
137
134
  def #{sym}=(obj)
138
135
  @@#{sym} = obj
139
136
  end
140
137
  EOS
141
138
  end
142
- send("#{sym}=", yield) if block_given?
139
+
140
+ sym_default_value = (block_given? && default.nil?) ? yield : default
141
+ send("#{sym}=", sym_default_value) unless sym_default_value.nil?
143
142
  end
144
143
  end
145
144
  alias :cattr_writer :mattr_writer
@@ -197,12 +196,10 @@ class Module
197
196
  # Person.new.hair_colors = [:brown] # => NoMethodError
198
197
  # Person.new.hair_colors # => NoMethodError
199
198
  #
200
- # Also you can pass a block to set up the attribute with a default value.
199
+ # You can set a default value for the attribute.
201
200
  #
202
201
  # module HairColors
203
- # mattr_accessor :hair_colors do
204
- # [:brown, :black, :blonde, :red]
205
- # end
202
+ # mattr_accessor :hair_colors, default: [:brown, :black, :blonde, :red]
206
203
  # end
207
204
  #
208
205
  # class Person
@@ -210,9 +207,9 @@ class Module
210
207
  # end
211
208
  #
212
209
  # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
213
- def mattr_accessor(*syms, &blk)
214
- mattr_reader(*syms, &blk)
215
- mattr_writer(*syms)
210
+ def mattr_accessor(*syms, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil, &blk)
211
+ mattr_reader(*syms, instance_reader: instance_reader, instance_accessor: instance_accessor, default: default, &blk)
212
+ mattr_writer(*syms, instance_writer: instance_writer, instance_accessor: instance_accessor, default: default)
216
213
  end
217
214
  alias :cattr_accessor :mattr_accessor
218
215
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/array/extract_options"
2
4
  require "active_support/core_ext/regexp"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/concern"
2
4
 
3
5
  class Module
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "set"
2
4
  require "active_support/core_ext/regexp"
3
5
 
@@ -174,7 +176,7 @@ class Module
174
176
  to = to.to_s
175
177
  to = "self.#{to}" if DELEGATION_RESERVED_METHOD_NAMES.include?(to)
176
178
 
177
- methods.each do |method|
179
+ methods.map do |method|
178
180
  # Attribute writer methods only accept one argument. Makes sure []=
179
181
  # methods still accept two arguments.
180
182
  definition = /[^\]]=$/.match?(method) ? "arg" : "*args, &block"
@@ -219,48 +221,43 @@ class Module
219
221
  # When building decorators, a common pattern may emerge:
220
222
  #
221
223
  # class Partition
222
- # def initialize(first_event)
223
- # @events = [ first_event ]
224
+ # def initialize(event)
225
+ # @event = event
224
226
  # end
225
227
  #
226
- # def people
227
- # if @events.first.detail.people.any?
228
- # @events.collect { |e| Array(e.detail.people) }.flatten.uniq
229
- # else
230
- # @events.collect(&:creator).uniq
231
- # end
228
+ # def person
229
+ # @event.detail.person || @event.creator
232
230
  # end
233
231
  #
234
232
  # private
235
233
  # def respond_to_missing?(name, include_private = false)
236
- # @events.respond_to?(name, include_private)
234
+ # @event.respond_to?(name, include_private)
237
235
  # end
238
236
  #
239
237
  # def method_missing(method, *args, &block)
240
- # @events.send(method, *args, &block)
238
+ # @event.send(method, *args, &block)
241
239
  # end
242
240
  # end
243
241
  #
244
- # With `Module#delegate_missing_to`, the above is condensed to:
242
+ # With <tt>Module#delegate_missing_to</tt>, the above is condensed to:
245
243
  #
246
244
  # class Partition
247
- # delegate_missing_to :@events
245
+ # delegate_missing_to :@event
248
246
  #
249
- # def initialize(first_event)
250
- # @events = [ first_event ]
247
+ # def initialize(event)
248
+ # @event = event
251
249
  # end
252
250
  #
253
- # def people
254
- # if @events.first.detail.people.any?
255
- # @events.collect { |e| Array(e.detail.people) }.flatten.uniq
256
- # else
257
- # @events.collect(&:creator).uniq
258
- # end
251
+ # def person
252
+ # @event.detail.person || @event.creator
259
253
  # end
260
254
  # end
261
255
  #
262
- # The target can be anything callable within the object. E.g. instance
263
- # variables, methods, constants and the likes.
256
+ # The target can be anything callable within the object, e.g. instance
257
+ # variables, methods, constants, etc.
258
+ #
259
+ # The delegated method must be public on the target, otherwise it will
260
+ # raise +NoMethodError+.
264
261
  def delegate_missing_to(target)
265
262
  target = target.to_s
266
263
  target = "self.#{target}" if DELEGATION_RESERVED_METHOD_NAMES.include?(target)
@@ -277,7 +274,15 @@ class Module
277
274
  if #{target}.respond_to?(method)
278
275
  #{target}.public_send(method, *args, &block)
279
276
  else
280
- super
277
+ begin
278
+ super
279
+ rescue NoMethodError
280
+ if #{target}.nil?
281
+ raise DelegationError, "\#{method} delegated to #{target}, but #{target} is nil"
282
+ else
283
+ raise
284
+ end
285
+ end
281
286
  end
282
287
  end
283
288
  RUBY
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Module
2
4
  # deprecate :foo
3
5
  # deprecate bar: 'message'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/inflector"
2
4
 
3
5
  class Module
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/module/anonymous"
2
4
  require "active_support/core_ext/string/inflections"
3
5
 
@@ -5,4 +7,5 @@ class Module
5
7
  def reachable? #:nodoc:
6
8
  !anonymous? && name.safe_constantize.equal?(self)
7
9
  end
10
+ deprecate :reachable?
8
11
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Module
4
+ if RUBY_VERSION >= "2.3"
5
+ # Marks the named method as intended to be redefined, if it exists.
6
+ # Suppresses the Ruby method redefinition warning. Prefer
7
+ # #redefine_method where possible.
8
+ def silence_redefinition_of_method(method)
9
+ if method_defined?(method) || private_method_defined?(method)
10
+ # This suppresses the "method redefined" warning; the self-alias
11
+ # looks odd, but means we don't need to generate a unique name
12
+ alias_method method, method
13
+ end
14
+ end
15
+ else
16
+ def silence_redefinition_of_method(method)
17
+ if method_defined?(method) || private_method_defined?(method)
18
+ alias_method :__rails_redefine, method
19
+ remove_method :__rails_redefine
20
+ end
21
+ end
22
+ end
23
+
24
+ # Replaces the existing method definition, if there is one, with the passed
25
+ # block as its body.
26
+ def redefine_method(method, &block)
27
+ visibility = method_visibility(method)
28
+ silence_redefinition_of_method(method)
29
+ define_method(method, &block)
30
+ send(visibility, method)
31
+ end
32
+
33
+ # Replaces the existing singleton method definition, if there is one, with
34
+ # the passed block as its body.
35
+ def redefine_singleton_method(method, &block)
36
+ singleton_class.redefine_method(method, &block)
37
+ end
38
+
39
+ def method_visibility(method) # :nodoc:
40
+ case
41
+ when private_method_defined?(method)
42
+ :private
43
+ when protected_method_defined?(method)
44
+ :protected
45
+ else
46
+ :public
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/module/redefine_method"
4
+
1
5
  class Module
2
6
  # Removes the named method, if it exists.
3
7
  def remove_possible_method(method)
@@ -8,28 +12,6 @@ class Module
8
12
 
9
13
  # Removes the named singleton method, if it exists.
10
14
  def remove_possible_singleton_method(method)
11
- singleton_class.instance_eval do
12
- remove_possible_method(method)
13
- end
14
- end
15
-
16
- # Replaces the existing method definition, if there is one, with the passed
17
- # block as its body.
18
- def redefine_method(method, &block)
19
- visibility = method_visibility(method)
20
- remove_possible_method(method)
21
- define_method(method, &block)
22
- send(visibility, method)
23
- end
24
-
25
- def method_visibility(method) # :nodoc:
26
- case
27
- when private_method_defined?(method)
28
- :private
29
- when protected_method_defined?(method)
30
- :protected
31
- else
32
- :public
33
- end
15
+ singleton_class.remove_possible_method(method)
34
16
  end
35
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class NameError
2
4
  # Extract the name of the missing constant from the exception message.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/numeric/bytes"
2
4
  require "active_support/core_ext/numeric/time"
3
5
  require "active_support/core_ext/numeric/inquiry"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Numeric
2
4
  KILOBYTE = 1024
3
5
  MEGABYTE = KILOBYTE * 1024
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/big_decimal/conversions"
2
4
  require "active_support/number_helper"
3
5
  require "active_support/core_ext/module/deprecation"
@@ -106,19 +108,19 @@ module ActiveSupport::NumericWithFormat
106
108
  when Integer, String
107
109
  super(format)
108
110
  when :phone
109
- return ActiveSupport::NumberHelper.number_to_phone(self, options || {})
111
+ ActiveSupport::NumberHelper.number_to_phone(self, options || {})
110
112
  when :currency
111
- return ActiveSupport::NumberHelper.number_to_currency(self, options || {})
113
+ ActiveSupport::NumberHelper.number_to_currency(self, options || {})
112
114
  when :percentage
113
- return ActiveSupport::NumberHelper.number_to_percentage(self, options || {})
115
+ ActiveSupport::NumberHelper.number_to_percentage(self, options || {})
114
116
  when :delimited
115
- return ActiveSupport::NumberHelper.number_to_delimited(self, options || {})
117
+ ActiveSupport::NumberHelper.number_to_delimited(self, options || {})
116
118
  when :rounded
117
- return ActiveSupport::NumberHelper.number_to_rounded(self, options || {})
119
+ ActiveSupport::NumberHelper.number_to_rounded(self, options || {})
118
120
  when :human
119
- return ActiveSupport::NumberHelper.number_to_human(self, options || {})
121
+ ActiveSupport::NumberHelper.number_to_human(self, options || {})
120
122
  when :human_size
121
- return ActiveSupport::NumberHelper.number_to_human_size(self, options || {})
123
+ ActiveSupport::NumberHelper.number_to_human_size(self, options || {})
122
124
  when Symbol
123
125
  super()
124
126
  else