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,13 +1,13 @@
1
- require 'active_support/core_ext/hash/deep_merge'
2
- require 'active_support/core_ext/hash/except'
3
- require 'active_support/core_ext/hash/slice'
1
+ require "active_support/core_ext/hash/deep_merge"
2
+ require "active_support/core_ext/hash/except"
3
+ require "active_support/core_ext/hash/slice"
4
4
  begin
5
- require 'i18n'
5
+ require "i18n"
6
6
  rescue LoadError => e
7
7
  $stderr.puts "The i18n gem is not available. Please add it to your Gemfile and run bundle install"
8
8
  raise e
9
9
  end
10
- require 'active_support/lazy_load_hooks'
10
+ require "active_support/lazy_load_hooks"
11
11
 
12
12
  ActiveSupport.run_load_hooks(:i18n)
13
13
  I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
@@ -2,6 +2,8 @@ require "active_support"
2
2
  require "active_support/file_update_checker"
3
3
  require "active_support/core_ext/array/wrap"
4
4
 
5
+ # :enddoc:
6
+
5
7
  module I18n
6
8
  class Railtie < Rails::Railtie
7
9
  config.i18n = ActiveSupport::OrderedOptions.new
@@ -21,8 +23,6 @@ module I18n
21
23
  I18n::Railtie.initialize_i18n(app)
22
24
  end
23
25
 
24
- protected
25
-
26
26
  @i18n_inited = false
27
27
 
28
28
  # Setup i18n configuration.
@@ -83,14 +83,15 @@ module I18n
83
83
  def self.init_fallbacks(fallbacks)
84
84
  include_fallbacks_module
85
85
 
86
- args = case fallbacks
87
- when ActiveSupport::OrderedOptions
88
- [*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
89
- when Hash, Array
90
- Array.wrap(fallbacks)
91
- else # TrueClass
92
- []
93
- end
86
+ args = \
87
+ case fallbacks
88
+ when ActiveSupport::OrderedOptions
89
+ [*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
90
+ when Hash, Array
91
+ Array.wrap(fallbacks)
92
+ else # TrueClass
93
+ []
94
+ end
94
95
 
95
96
  I18n.fallbacks = I18n::Locale::Fallbacks.new(*args)
96
97
  end
@@ -1,4 +1,4 @@
1
- require 'active_support/inflector/inflections'
1
+ require "active_support/inflector/inflections"
2
2
 
3
3
  #--
4
4
  # Defines the standard inflection rules. These are the starting point for
@@ -8,8 +8,8 @@ require 'active_support/inflector/inflections'
8
8
  #++
9
9
  module ActiveSupport
10
10
  Inflector.inflections(:en) do |inflect|
11
- inflect.plural(/$/, 's')
12
- inflect.plural(/s$/i, 's')
11
+ inflect.plural(/$/, "s")
12
+ inflect.plural(/s$/i, "s")
13
13
  inflect.plural(/^(ax|test)is$/i, '\1es')
14
14
  inflect.plural(/(octop|vir)us$/i, '\1i')
15
15
  inflect.plural(/(octop|vir)i$/i, '\1i')
@@ -18,7 +18,7 @@ module ActiveSupport
18
18
  inflect.plural(/(buffal|tomat)o$/i, '\1oes')
19
19
  inflect.plural(/([ti])um$/i, '\1a')
20
20
  inflect.plural(/([ti])a$/i, '\1a')
21
- inflect.plural(/sis$/i, 'ses')
21
+ inflect.plural(/sis$/i, "ses")
22
22
  inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
23
23
  inflect.plural(/(hive)$/i, '\1s')
24
24
  inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
@@ -30,7 +30,7 @@ module ActiveSupport
30
30
  inflect.plural(/^(oxen)$/i, '\1')
31
31
  inflect.plural(/(quiz)$/i, '\1zes')
32
32
 
33
- inflect.singular(/s$/i, '')
33
+ inflect.singular(/s$/i, "")
34
34
  inflect.singular(/(ss)$/i, '\1')
35
35
  inflect.singular(/(n)ews$/i, '\1ews')
36
36
  inflect.singular(/([ti])a$/i, '\1um')
@@ -58,12 +58,12 @@ module ActiveSupport
58
58
  inflect.singular(/(quiz)zes$/i, '\1')
59
59
  inflect.singular(/(database)s$/i, '\1')
60
60
 
61
- inflect.irregular('person', 'people')
62
- inflect.irregular('man', 'men')
63
- inflect.irregular('child', 'children')
64
- inflect.irregular('sex', 'sexes')
65
- inflect.irregular('move', 'moves')
66
- inflect.irregular('zombie', 'zombies')
61
+ inflect.irregular("person", "people")
62
+ inflect.irregular("man", "men")
63
+ inflect.irregular("child", "children")
64
+ inflect.irregular("sex", "sexes")
65
+ inflect.irregular("move", "moves")
66
+ inflect.irregular("zombie", "zombies")
67
67
 
68
68
  inflect.uncountable(%w(equipment information rice money species series fish sheep jeans police))
69
69
  end
@@ -1,7 +1,7 @@
1
1
  # in case active_support/inflector is required without the rest of active_support
2
- require 'active_support/inflector/inflections'
3
- require 'active_support/inflector/transliterate'
4
- require 'active_support/inflector/methods'
2
+ require "active_support/inflector/inflections"
3
+ require "active_support/inflector/transliterate"
4
+ require "active_support/inflector/methods"
5
5
 
6
- require 'active_support/inflections'
7
- require 'active_support/core_ext/string/inflections'
6
+ require "active_support/inflections"
7
+ require "active_support/core_ext/string/inflections"
@@ -1,6 +1,7 @@
1
- require 'concurrent/map'
2
- require 'active_support/core_ext/array/prepend_and_append'
3
- require 'active_support/i18n'
1
+ require "concurrent/map"
2
+ require "active_support/core_ext/array/prepend_and_append"
3
+ require "active_support/core_ext/regexp"
4
+ require "active_support/i18n"
4
5
 
5
6
  module ActiveSupport
6
7
  module Inflector
@@ -43,13 +44,14 @@ module ActiveSupport
43
44
  end
44
45
 
45
46
  def add(words)
46
- self.concat(words.flatten.map(&:downcase))
47
- @regex_array += self.map {|word| to_regex(word) }
47
+ words = words.flatten.map(&:downcase)
48
+ concat(words)
49
+ @regex_array += words.map { |word| to_regex(word) }
48
50
  self
49
51
  end
50
52
 
51
53
  def uncountable?(str)
52
- @regex_array.any? { |regex| regex === str }
54
+ @regex_array.any? { |regex| regex.match? str }
53
55
  end
54
56
 
55
57
  private
@@ -215,10 +217,10 @@ module ActiveSupport
215
217
  # clear :plurals
216
218
  def clear(scope = :all)
217
219
  case scope
218
- when :all
219
- @plurals, @singulars, @uncountables, @humans = [], [], Uncountables.new, []
220
+ when :all
221
+ @plurals, @singulars, @uncountables, @humans = [], [], Uncountables.new, []
220
222
  else
221
- instance_variable_set "@#{scope}", []
223
+ instance_variable_set "@#{scope}", []
222
224
  end
223
225
  end
224
226
  end
@@ -1,4 +1,5 @@
1
- require 'active_support/inflections'
1
+ require "active_support/inflections"
2
+ require "active_support/core_ext/regexp"
2
3
 
3
4
  module ActiveSupport
4
5
  # The Inflector transforms words from singular to plural, class names to table
@@ -71,7 +72,7 @@ module ActiveSupport
71
72
  string = string.sub(/^(?:#{inflections.acronym_regex}(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
72
73
  end
73
74
  string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }
74
- string.gsub!('/'.freeze, '::'.freeze)
75
+ string.gsub!("/".freeze, "::".freeze)
75
76
  string
76
77
  end
77
78
 
@@ -87,8 +88,8 @@ module ActiveSupport
87
88
  #
88
89
  # camelize(underscore('SSLError')) # => "SslError"
89
90
  def underscore(camel_cased_word)
90
- return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
91
- word = camel_cased_word.to_s.gsub('::'.freeze, '/'.freeze)
91
+ return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
92
+ word = camel_cased_word.to_s.gsub("::".freeze, "/".freeze)
92
93
  word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'.freeze }#{$2.downcase}" }
93
94
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
94
95
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
@@ -125,9 +126,9 @@ module ActiveSupport
125
126
 
126
127
  inflections.humans.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
127
128
 
128
- result.sub!(/\A_+/, ''.freeze)
129
- result.sub!(/_id\z/, ''.freeze)
130
- result.tr!('_'.freeze, ' '.freeze)
129
+ result.sub!(/\A_+/, "".freeze)
130
+ result.sub!(/_id\z/, "".freeze)
131
+ result.tr!("_".freeze, " ".freeze)
131
132
 
132
133
  result.gsub!(/([a-z\d]*)/i) do |match|
133
134
  "#{inflections.acronyms[match] || match.downcase}"
@@ -146,7 +147,7 @@ module ActiveSupport
146
147
  # upcase_first('w') # => "W"
147
148
  # upcase_first('') # => ""
148
149
  def upcase_first(string)
149
- string.length > 0 ? string[0].upcase.concat(string[1..-1]) : ''
150
+ string.length > 0 ? string[0].upcase.concat(string[1..-1]) : ""
150
151
  end
151
152
 
152
153
  # Capitalizes all the words and replaces some characters in the string to
@@ -185,28 +186,28 @@ module ActiveSupport
185
186
  # classify('calculus') # => "Calculus"
186
187
  def classify(table_name)
187
188
  # strip out any leading schema name
188
- camelize(singularize(table_name.to_s.sub(/.*\./, ''.freeze)))
189
+ camelize(singularize(table_name.to_s.sub(/.*\./, "".freeze)))
189
190
  end
190
191
 
191
192
  # Replaces underscores with dashes in the string.
192
193
  #
193
194
  # dasherize('puni_puni') # => "puni-puni"
194
195
  def dasherize(underscored_word)
195
- underscored_word.tr('_'.freeze, '-'.freeze)
196
+ underscored_word.tr("_".freeze, "-".freeze)
196
197
  end
197
198
 
198
199
  # Removes the module part from the expression in the string.
199
200
  #
200
- # demodulize('ActiveRecord::CoreExtensions::String::Inflections') # => "Inflections"
201
- # demodulize('Inflections') # => "Inflections"
202
- # demodulize('::Inflections') # => "Inflections"
203
- # demodulize('') # => ""
201
+ # demodulize('ActiveSupport::Inflector::Inflections') # => "Inflections"
202
+ # demodulize('Inflections') # => "Inflections"
203
+ # demodulize('::Inflections') # => "Inflections"
204
+ # demodulize('') # => ""
204
205
  #
205
206
  # See also #deconstantize.
206
207
  def demodulize(path)
207
208
  path = path.to_s
208
- if i = path.rindex('::')
209
- path[(i+2)..-1]
209
+ if i = path.rindex("::")
210
+ path[(i + 2)..-1]
210
211
  else
211
212
  path
212
213
  end
@@ -222,7 +223,7 @@ module ActiveSupport
222
223
  #
223
224
  # See also #demodulize.
224
225
  def deconstantize(path)
225
- path.to_s[0, path.rindex('::') || 0] # implementation based on the one in facets' Module#spacename
226
+ path.to_s[0, path.rindex("::") || 0] # implementation based on the one in facets' Module#spacename
226
227
  end
227
228
 
228
229
  # Creates a foreign key name from a class name.
@@ -238,8 +239,8 @@ module ActiveSupport
238
239
 
239
240
  # Tries to find a constant with the name specified in the argument string.
240
241
  #
241
- # 'Module'.constantize # => Module
242
- # 'Foo::Bar'.constantize # => Foo::Bar
242
+ # constantize('Module') # => Module
243
+ # constantize('Foo::Bar') # => Foo::Bar
243
244
  #
244
245
  # The name is assumed to be the one of a top-level constant, no matter
245
246
  # whether it starts with "::" or not. No lexical context is taken into
@@ -248,14 +249,14 @@ module ActiveSupport
248
249
  # C = 'outside'
249
250
  # module M
250
251
  # C = 'inside'
251
- # C # => 'inside'
252
- # 'C'.constantize # => 'outside', same as ::C
252
+ # C # => 'inside'
253
+ # constantize('C') # => 'outside', same as ::C
253
254
  # end
254
255
  #
255
256
  # NameError is raised when the name is not in CamelCase or the constant is
256
257
  # unknown.
257
258
  def constantize(camel_cased_word)
258
- names = camel_cased_word.split('::'.freeze)
259
+ names = camel_cased_word.split("::".freeze)
259
260
 
260
261
  # Trigger a built-in NameError exception including the ill-formed constant in the message.
261
262
  Object.const_get(camel_cased_word) if names.empty?
@@ -313,7 +314,7 @@ module ActiveSupport
313
314
  raise if e.name && !(camel_cased_word.to_s.split("::").include?(e.name.to_s) ||
314
315
  e.name.to_s == camel_cased_word.to_s)
315
316
  rescue ArgumentError => e
316
- raise unless e.message =~ /not missing constant #{const_regexp(camel_cased_word)}\!$/
317
+ raise unless /not missing constant #{const_regexp(camel_cased_word)}!$/.match?(e.message)
317
318
  end
318
319
 
319
320
  # Returns the suffix that should be added to a number to denote the position
@@ -332,9 +333,9 @@ module ActiveSupport
332
333
  "th"
333
334
  else
334
335
  case abs_number % 10
335
- when 1; "st"
336
- when 2; "nd"
337
- when 3; "rd"
336
+ when 1; "st"
337
+ when 2; "nd"
338
+ when 3; "rd"
338
339
  else "th"
339
340
  end
340
341
  end
@@ -355,36 +356,36 @@ module ActiveSupport
355
356
 
356
357
  private
357
358
 
358
- # Mounts a regular expression, returned as a string to ease interpolation,
359
- # that will match part by part the given constant.
360
- #
361
- # const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"
362
- # const_regexp("::") # => "::"
363
- def const_regexp(camel_cased_word) #:nodoc:
364
- parts = camel_cased_word.split("::".freeze)
359
+ # Mounts a regular expression, returned as a string to ease interpolation,
360
+ # that will match part by part the given constant.
361
+ #
362
+ # const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"
363
+ # const_regexp("::") # => "::"
364
+ def const_regexp(camel_cased_word)
365
+ parts = camel_cased_word.split("::".freeze)
365
366
 
366
- return Regexp.escape(camel_cased_word) if parts.blank?
367
+ return Regexp.escape(camel_cased_word) if parts.blank?
367
368
 
368
- last = parts.pop
369
+ last = parts.pop
369
370
 
370
- parts.reverse.inject(last) do |acc, part|
371
- part.empty? ? acc : "#{part}(::#{acc})?"
371
+ parts.reverse.inject(last) do |acc, part|
372
+ part.empty? ? acc : "#{part}(::#{acc})?"
373
+ end
372
374
  end
373
- end
374
375
 
375
- # Applies inflection rules for +singularize+ and +pluralize+.
376
- #
377
- # apply_inflections('post', inflections.plurals) # => "posts"
378
- # apply_inflections('posts', inflections.singulars) # => "post"
379
- def apply_inflections(word, rules)
380
- result = word.to_s.dup
376
+ # Applies inflection rules for +singularize+ and +pluralize+.
377
+ #
378
+ # apply_inflections('post', inflections.plurals) # => "posts"
379
+ # apply_inflections('posts', inflections.singulars) # => "post"
380
+ def apply_inflections(word, rules)
381
+ result = word.to_s.dup
381
382
 
382
- if word.empty? || inflections.uncountables.uncountable?(result)
383
- result
384
- else
385
- rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
386
- result
383
+ if word.empty? || inflections.uncountables.uncountable?(result)
384
+ result
385
+ else
386
+ rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
387
+ result
388
+ end
387
389
  end
388
- end
389
390
  end
390
391
  end
@@ -1,9 +1,8 @@
1
- require 'active_support/core_ext/string/multibyte'
2
- require 'active_support/i18n'
1
+ require "active_support/core_ext/string/multibyte"
2
+ require "active_support/i18n"
3
3
 
4
4
  module ActiveSupport
5
5
  module Inflector
6
-
7
6
  # Replaces non-ASCII characters with an ASCII approximation, or if none
8
7
  # exists, a replacement character which defaults to "?".
9
8
  #
@@ -58,9 +57,11 @@ module ActiveSupport
58
57
  # transliterate('Jürgen')
59
58
  # # => "Juergen"
60
59
  def transliterate(string, replacement = "?".freeze)
60
+ raise ArgumentError, "Can only transliterate strings. Received #{string.class.name}" unless string.is_a?(String)
61
+
61
62
  I18n.transliterate(ActiveSupport::Multibyte::Unicode.normalize(
62
63
  ActiveSupport::Multibyte::Unicode.tidy_bytes(string), :c),
63
- :replacement => replacement)
64
+ replacement: replacement)
64
65
  end
65
66
 
66
67
  # Replaces special characters in a string so that it may be used as part of
@@ -79,11 +80,7 @@ module ActiveSupport
79
80
  # parameterize("Donald E. Knuth", preserve_case: true) # => "Donald-E-Knuth"
80
81
  # parameterize("^trés|Jolie-- ", preserve_case: true) # => "tres-Jolie"
81
82
  #
82
- def parameterize(string, sep = :unused, separator: '-', preserve_case: false)
83
- unless sep == :unused
84
- ActiveSupport::Deprecation.warn("Passing the separator argument as a positional parameter is deprecated and will soon be removed. Use `separator: '#{sep}'` instead.")
85
- separator = sep
86
- end
83
+ def parameterize(string, separator: "-", preserve_case: false)
87
84
  # Replace accented chars with their ASCII equivalents.
88
85
  parameterized_string = transliterate(string)
89
86
 
@@ -102,9 +99,9 @@ module ActiveSupport
102
99
  # No more than one of the separator in a row.
103
100
  parameterized_string.gsub!(re_duplicate_separator, separator)
104
101
  # Remove leading/trailing separator.
105
- parameterized_string.gsub!(re_leading_trailing_separator, ''.freeze)
102
+ parameterized_string.gsub!(re_leading_trailing_separator, "".freeze)
106
103
  end
107
-
104
+
108
105
  parameterized_string.downcase! unless preserve_case
109
106
  parameterized_string
110
107
  end
@@ -1,2 +1,2 @@
1
- require 'active_support/json/decoding'
2
- require 'active_support/json/encoding'
1
+ require "active_support/json/decoding"
2
+ require "active_support/json/encoding"
@@ -1,6 +1,6 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
- require 'active_support/core_ext/module/delegation'
3
- require 'json'
1
+ require "active_support/core_ext/module/attribute_accessors"
2
+ require "active_support/core_ext/module/delegation"
3
+ require "json"
4
4
 
5
5
  module ActiveSupport
6
6
  # Look for and parse json strings that look like ISO 8601 times.
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/object/json'
2
- require 'active_support/core_ext/module/delegation'
1
+ require "active_support/core_ext/object/json"
2
+ require "active_support/core_ext/module/delegation"
3
3
 
4
4
  module ActiveSupport
5
5
  class << self
@@ -7,7 +7,7 @@ module ActiveSupport
7
7
  :time_precision, :time_precision=,
8
8
  :escape_html_entities_in_json, :escape_html_entities_in_json=,
9
9
  :json_encoder, :json_encoder=,
10
- :to => :'ActiveSupport::JSON::Encoding'
10
+ to: :'ActiveSupport::JSON::Encoding'
11
11
  end
12
12
 
13
13
  module JSON
@@ -40,9 +40,9 @@ module ActiveSupport
40
40
  ESCAPED_CHARS = {
41
41
  "\u2028" => '\u2028',
42
42
  "\u2029" => '\u2029',
43
- '>' => '\u003e',
44
- '<' => '\u003c',
45
- '&' => '\u0026',
43
+ ">" => '\u003e',
44
+ "<" => '\u003c',
45
+ "&" => '\u0026',
46
46
  }
47
47
 
48
48
  ESCAPE_REGEX_WITH_HTML_ENTITIES = /[\u2028\u2029><&]/u
@@ -68,7 +68,8 @@ module ActiveSupport
68
68
  :ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, :EscapedString
69
69
 
70
70
  # Convert an object into a "JSON-ready" representation composed of
71
- # primitives like Hash, Array, String, Numeric, and true/false/nil.
71
+ # primitives like Hash, Array, String, Numeric,
72
+ # and +true+/+false+/+nil+.
72
73
  # Recursively calls #as_json to the object to recursively build a
73
74
  # fully JSON-ready object.
74
75
  #