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,3 +1,5 @@
1
+ require "active_support/core_ext/regexp"
2
+
1
3
  class Object
2
4
  # An object is blank if it's false, empty, or a whitespace string.
3
5
  # For example, +false+, '', ' ', +nil+, [], and {} are all blank.
@@ -115,7 +117,7 @@ class String
115
117
  # The regexp that matches blank strings is expensive. For the case of empty
116
118
  # strings we can speed up this method (~3.5x) with an empty? call. The
117
119
  # penalty for the rest of strings is marginal.
118
- empty? || BLANK_RE === self
120
+ empty? || BLANK_RE.match?(self)
119
121
  end
120
122
  end
121
123
 
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/object/to_param'
2
- require 'active_support/core_ext/object/to_query'
3
- require 'active_support/core_ext/array/conversions'
4
- require 'active_support/core_ext/hash/conversions'
1
+ require "active_support/core_ext/object/to_param"
2
+ require "active_support/core_ext/object/to_query"
3
+ require "active_support/core_ext/array/conversions"
4
+ require "active_support/core_ext/hash/conversions"
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/object/duplicable'
1
+ require "active_support/core_ext/object/duplicable"
2
2
 
3
3
  class Object
4
4
  # Returns a deep copy of object if it's duplicable. If it's
@@ -74,7 +74,7 @@ end
74
74
  class Symbol
75
75
  begin
76
76
  :symbol.dup # Ruby 2.4.x.
77
- 'symbol_from_string'.to_sym.dup # Some symbols can't `dup` in Ruby 2.4.0.
77
+ "symbol_from_string".to_sym.dup # Some symbols can't `dup` in Ruby 2.4.0.
78
78
  rescue TypeError
79
79
 
80
80
  # Symbols are not duplicable:
@@ -102,12 +102,12 @@ class Numeric
102
102
  end
103
103
  end
104
104
 
105
- require 'bigdecimal'
105
+ require "bigdecimal"
106
106
  class BigDecimal
107
107
  # BigDecimals are duplicable:
108
108
  #
109
- # BigDecimal("1.2").duplicable? # => true
110
- # BigDecimal("1.2").dup # => #<BigDecimal:...,'0.12E1',18(18)>
109
+ # BigDecimal.new("1.2").duplicable? # => true
110
+ # BigDecimal.new("1.2").dup # => #<BigDecimal:...,'0.12E1',18(18)>
111
111
  def duplicable?
112
112
  true
113
113
  end
@@ -122,3 +122,23 @@ class Method
122
122
  false
123
123
  end
124
124
  end
125
+
126
+ class Complex
127
+ # Complexes are not duplicable:
128
+ #
129
+ # Complex(1).duplicable? # => false
130
+ # Complex(1).dup # => TypeError: can't copy Complex
131
+ def duplicable?
132
+ false
133
+ end
134
+ end
135
+
136
+ class Rational
137
+ # Rationals are not duplicable:
138
+ #
139
+ # Rational(1).duplicable? # => false
140
+ # Rational(1).dup # => TypeError: can't copy Rational
141
+ def duplicable?
142
+ false
143
+ end
144
+ end
@@ -22,6 +22,6 @@ class Object
22
22
  #
23
23
  # @return [Object]
24
24
  def presence_in(another_object)
25
- self.in?(another_object) ? self : nil
25
+ in?(another_object) ? self : nil
26
26
  end
27
27
  end
@@ -1,14 +1,16 @@
1
1
  # Hack to load json gem first so we can overwrite its to_json.
2
- require 'json'
3
- require 'bigdecimal'
4
- require 'active_support/core_ext/big_decimal/conversions' # for #to_s
5
- require 'active_support/core_ext/hash/except'
6
- require 'active_support/core_ext/hash/slice'
7
- require 'active_support/core_ext/object/instance_variables'
8
- require 'time'
9
- require 'active_support/core_ext/time/conversions'
10
- require 'active_support/core_ext/date_time/conversions'
11
- require 'active_support/core_ext/date/conversions'
2
+ require "json"
3
+ require "bigdecimal"
4
+ require "uri/generic"
5
+ require "pathname"
6
+ require "active_support/core_ext/big_decimal/conversions" # for #to_s
7
+ require "active_support/core_ext/hash/except"
8
+ require "active_support/core_ext/hash/slice"
9
+ require "active_support/core_ext/object/instance_variables"
10
+ require "time"
11
+ require "active_support/core_ext/time/conversions"
12
+ require "active_support/core_ext/date_time/conversions"
13
+ require "active_support/core_ext/date/conversions"
12
14
 
13
15
  # The JSON gem adds a few modules to Ruby core classes containing :to_json definition, overwriting
14
16
  # their default behavior. That said, we need to define the basic to_json method in all of them,
@@ -187,14 +189,26 @@ class DateTime
187
189
  if ActiveSupport::JSON::Encoding.use_standard_json_time_format
188
190
  xmlschema(ActiveSupport::JSON::Encoding.time_precision)
189
191
  else
190
- strftime('%Y/%m/%d %H:%M:%S %z')
192
+ strftime("%Y/%m/%d %H:%M:%S %z")
191
193
  end
192
194
  end
193
195
  end
194
196
 
197
+ class URI::Generic #:nodoc:
198
+ def as_json(options = nil)
199
+ to_s
200
+ end
201
+ end
202
+
203
+ class Pathname #:nodoc:
204
+ def as_json(options = nil)
205
+ to_s
206
+ end
207
+ end
208
+
195
209
  class Process::Status #:nodoc:
196
210
  def as_json(options = nil)
197
- { :exitstatus => exitstatus, :pid => pid }
211
+ { exitstatus: exitstatus, pid: pid }
198
212
  end
199
213
  end
200
214
 
@@ -1 +1 @@
1
- require 'active_support/core_ext/object/to_query'
1
+ require "active_support/core_ext/object/to_query"
@@ -1,4 +1,4 @@
1
- require 'cgi'
1
+ require "cgi"
2
2
 
3
3
  class Object
4
4
  # Alias of <tt>to_s</tt>.
@@ -38,7 +38,7 @@ class Array
38
38
  # Calls <tt>to_param</tt> on all its elements and joins the result with
39
39
  # slashes. This is used by <tt>url_for</tt> in Action Pack.
40
40
  def to_param
41
- collect(&:to_param).join '/'
41
+ collect(&:to_param).join "/"
42
42
  end
43
43
 
44
44
  # Converts an array into a string suitable for use as a URL query string,
@@ -51,7 +51,7 @@ class Array
51
51
  if empty?
52
52
  nil.to_query(prefix)
53
53
  else
54
- collect { |value| value.to_query(prefix) }.join '&'
54
+ collect { |value| value.to_query(prefix) }.join "&"
55
55
  end
56
56
  end
57
57
  end
@@ -77,7 +77,7 @@ class Hash
77
77
  unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
78
78
  value.to_query(namespace ? "#{namespace}[#{key}]" : key)
79
79
  end
80
- end.compact.sort! * '&'
80
+ end.compact.sort! * "&"
81
81
  end
82
82
 
83
83
  alias_method :to_param, :to_query
@@ -1,4 +1,4 @@
1
- require 'delegate'
1
+ require "delegate"
2
2
 
3
3
  module ActiveSupport
4
4
  module Tryable #:nodoc:
@@ -1,4 +1,4 @@
1
- require 'active_support/option_merger'
1
+ require "active_support/option_merger"
2
2
 
3
3
  class Object
4
4
  # An elegant way to factor duplication out of options passed to a series of
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/range/conversions'
2
- require 'active_support/core_ext/range/include_range'
3
- require 'active_support/core_ext/range/overlaps'
4
- require 'active_support/core_ext/range/each'
1
+ require "active_support/core_ext/range/conversions"
2
+ require "active_support/core_ext/range/include_range"
3
+ require "active_support/core_ext/range/overlaps"
4
+ require "active_support/core_ext/range/each"
@@ -1,6 +1,6 @@
1
1
  module ActiveSupport::RangeWithFormat
2
2
  RANGE_FORMATS = {
3
- :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
3
+ db: Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
4
4
  }
5
5
 
6
6
  # Convert range to a formatted string. See RANGE_FORMATS for predefined formats.
@@ -2,4 +2,8 @@ class Regexp #:nodoc:
2
2
  def multiline?
3
3
  options & MULTILINE == MULTILINE
4
4
  end
5
+
6
+ def match?(string, pos = 0)
7
+ !!match(string, pos)
8
+ end unless //.respond_to?(:match?)
5
9
  end
@@ -1,12 +1,12 @@
1
- require 'securerandom'
1
+ require "securerandom"
2
2
 
3
3
  module SecureRandom
4
- BASE58_ALPHABET = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a - ['0', 'O', 'I', 'l']
4
+ BASE58_ALPHABET = ("0".."9").to_a + ("A".."Z").to_a + ("a".."z").to_a - ["0", "O", "I", "l"]
5
5
  # SecureRandom.base58 generates a random base58 string.
6
6
  #
7
7
  # The argument _n_ specifies the length, of the random string to be generated.
8
8
  #
9
- # If _n_ is not specified or is nil, 16 is assumed. It may be larger in the future.
9
+ # If _n_ is not specified or is +nil+, 16 is assumed. It may be larger in the future.
10
10
  #
11
11
  # The result may contain alphanumeric characters except 0, O, I and l
12
12
  #
@@ -1,13 +1,13 @@
1
- require 'active_support/core_ext/string/conversions'
2
- require 'active_support/core_ext/string/filters'
3
- require 'active_support/core_ext/string/multibyte'
4
- require 'active_support/core_ext/string/starts_ends_with'
5
- require 'active_support/core_ext/string/inflections'
6
- require 'active_support/core_ext/string/access'
7
- require 'active_support/core_ext/string/behavior'
8
- require 'active_support/core_ext/string/output_safety'
9
- require 'active_support/core_ext/string/exclude'
10
- require 'active_support/core_ext/string/strip'
11
- require 'active_support/core_ext/string/inquiry'
12
- require 'active_support/core_ext/string/indent'
13
- require 'active_support/core_ext/string/zones'
1
+ require "active_support/core_ext/string/conversions"
2
+ require "active_support/core_ext/string/filters"
3
+ require "active_support/core_ext/string/multibyte"
4
+ require "active_support/core_ext/string/starts_ends_with"
5
+ require "active_support/core_ext/string/inflections"
6
+ require "active_support/core_ext/string/access"
7
+ require "active_support/core_ext/string/behavior"
8
+ require "active_support/core_ext/string/output_safety"
9
+ require "active_support/core_ext/string/exclude"
10
+ require "active_support/core_ext/string/strip"
11
+ require "active_support/core_ext/string/inquiry"
12
+ require "active_support/core_ext/string/indent"
13
+ require "active_support/core_ext/string/zones"
@@ -3,7 +3,7 @@ class String
3
3
  # position. The first character of the string is at position 0, the next at
4
4
  # position 1, and so on. If a range is supplied, a substring containing
5
5
  # characters at offsets given by the range is returned. In both cases, if an
6
- # offset is negative, it is counted from the end of the string. Returns nil
6
+ # offset is negative, it is counted from the end of the string. Returns +nil+
7
7
  # if the initial offset falls outside the string. Returns an empty string if
8
8
  # the beginning of the range is greater than the end of the string.
9
9
  #
@@ -17,7 +17,7 @@ class String
17
17
  #
18
18
  # If a Regexp is given, the matching portion of the string is returned.
19
19
  # If a String is given, that given string is returned if it occurs in
20
- # the string. In both cases, nil is returned if there is no match.
20
+ # the string. In both cases, +nil+ is returned if there is no match.
21
21
  #
22
22
  # str = "hello"
23
23
  # str.at(/lo/) # => "lo"
@@ -74,9 +74,9 @@ class String
74
74
  # str.first(6) # => "hello"
75
75
  def first(limit = 1)
76
76
  if limit == 0
77
- ''
77
+ ""
78
78
  elsif limit >= size
79
- self.dup
79
+ dup
80
80
  else
81
81
  to(limit - 1)
82
82
  end
@@ -94,9 +94,9 @@ class String
94
94
  # str.last(6) # => "hello"
95
95
  def last(limit = 1)
96
96
  if limit == 0
97
- ''
97
+ ""
98
98
  elsif limit >= size
99
- self.dup
99
+ dup
100
100
  else
101
101
  from(-limit)
102
102
  end
@@ -1,5 +1,5 @@
1
- require 'date'
2
- require 'active_support/core_ext/time/calculations'
1
+ require "date"
2
+ require "active_support/core_ext/time/calculations"
3
3
 
4
4
  class String
5
5
  # Converts a string to a Time value.
@@ -17,7 +17,7 @@ class String
17
17
  # str.squish! # => "foo bar boo"
18
18
  # str # => "foo bar boo"
19
19
  def squish!
20
- gsub!(/[[:space:]]+/, ' ')
20
+ gsub!(/[[:space:]]+/, " ")
21
21
  strip!
22
22
  self
23
23
  end
@@ -64,7 +64,7 @@ class String
64
64
  def truncate(truncate_at, options = {})
65
65
  return dup unless length > truncate_at
66
66
 
67
- omission = options[:omission] || '...'
67
+ omission = options[:omission] || "..."
68
68
  length_with_room_for_omission = truncate_at - omission.length
69
69
  stop = \
70
70
  if options[:separator]
@@ -94,7 +94,7 @@ class String
94
94
  sep = options[:separator] || /\s+/
95
95
  sep = Regexp.escape(sep.to_s) unless Regexp === sep
96
96
  if self =~ /\A((?>.+?#{sep}){#{words_count - 1}}.+?)#{sep}.*/m
97
- $1 + (options[:omission] || '...')
97
+ $1 + (options[:omission] || "...")
98
98
  else
99
99
  dup
100
100
  end
@@ -2,8 +2,8 @@ class String
2
2
  # Same as +indent+, except it indents the receiver in-place.
3
3
  #
4
4
  # Returns the indented string, or +nil+ if there was nothing to indent.
5
- def indent!(amount, indent_string=nil, indent_empty_lines=false)
6
- indent_string = indent_string || self[/^[ \t]/] || ' '
5
+ def indent!(amount, indent_string = nil, indent_empty_lines = false)
6
+ indent_string = indent_string || self[/^[ \t]/] || " "
7
7
  re = indent_empty_lines ? /^/ : /^(?!$)/
8
8
  gsub!(re, indent_string * amount)
9
9
  end
@@ -37,7 +37,7 @@ class String
37
37
  # "foo\n\nbar".indent(2) # => " foo\n\n bar"
38
38
  # "foo\n\nbar".indent(2, nil, true) # => " foo\n \n bar"
39
39
  #
40
- def indent(amount, indent_string=nil, indent_empty_lines=false)
41
- dup.tap {|_| _.indent!(amount, indent_string, indent_empty_lines)}
40
+ def indent(amount, indent_string = nil, indent_empty_lines = false)
41
+ dup.tap { |_| _.indent!(amount, indent_string, indent_empty_lines) }
42
42
  end
43
43
  end
@@ -1,5 +1,5 @@
1
- require 'active_support/inflector/methods'
2
- require 'active_support/inflector/transliterate'
1
+ require "active_support/inflector/methods"
2
+ require "active_support/inflector/transliterate"
3
3
 
4
4
  # String inflections define new methods on the String class to transform names for different purposes.
5
5
  # For instance, you can figure out the name of a table from the name of a class.
@@ -31,7 +31,7 @@ class String
31
31
  def pluralize(count = nil, locale = :en)
32
32
  locale = count if count.is_a?(Symbol)
33
33
  if count == 1
34
- self.dup
34
+ dup
35
35
  else
36
36
  ActiveSupport::Inflector.pluralize(self, locale)
37
37
  end
@@ -67,7 +67,7 @@ class String
67
67
  end
68
68
 
69
69
  # +safe_constantize+ tries to find a declared constant with the name specified
70
- # in the string. It returns nil when the name is not in CamelCase
70
+ # in the string. It returns +nil+ when the name is not in CamelCase
71
71
  # or is not initialized. See ActiveSupport::Inflector.safe_constantize
72
72
  #
73
73
  # 'Module'.safe_constantize # => Module
@@ -128,10 +128,10 @@ class String
128
128
 
129
129
  # Removes the module part from the constant expression in the string.
130
130
  #
131
- # 'ActiveRecord::CoreExtensions::String::Inflections'.demodulize # => "Inflections"
132
- # 'Inflections'.demodulize # => "Inflections"
133
- # '::Inflections'.demodulize # => "Inflections"
134
- # ''.demodulize # => ''
131
+ # 'ActiveSupport::Inflector::Inflections'.demodulize # => "Inflections"
132
+ # 'Inflections'.demodulize # => "Inflections"
133
+ # '::Inflections'.demodulize # => "Inflections"
134
+ # ''.demodulize # => ''
135
135
  #
136
136
  # See also +deconstantize+.
137
137
  def demodulize
@@ -164,7 +164,7 @@ class String
164
164
  #
165
165
  # <%= link_to(@person.name, person_path) %>
166
166
  # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
167
- #
167
+ #
168
168
  # To preserve the case of the characters in a string, use the `preserve_case` argument.
169
169
  #
170
170
  # class Person
@@ -178,11 +178,7 @@ class String
178
178
  #
179
179
  # <%= link_to(@person.name, person_path) %>
180
180
  # # => <a href="/person/1-Donald-E-Knuth">Donald E. Knuth</a>
181
- def parameterize(sep = :unused, separator: '-', preserve_case: false)
182
- unless sep == :unused
183
- ActiveSupport::Deprecation.warn("Passing the separator argument as a positional parameter is deprecated and will soon be removed. Use `separator: '#{sep}'` instead.")
184
- separator = sep
185
- end
181
+ def parameterize(separator: "-", preserve_case: false)
186
182
  ActiveSupport::Inflector.parameterize(self, separator: separator, preserve_case: preserve_case)
187
183
  end
188
184
 
@@ -1,4 +1,4 @@
1
- require 'active_support/string_inquirer'
1
+ require "active_support/string_inquirer"
2
2
 
3
3
  class String
4
4
  # Wraps the current string in the <tt>ActiveSupport::StringInquirer</tt> class,
@@ -1,4 +1,4 @@
1
- require 'active_support/multibyte'
1
+ require "active_support/multibyte"
2
2
 
3
3
  class String
4
4
  # == Multibyte proxy
@@ -1,10 +1,11 @@
1
- require 'erb'
2
- require 'active_support/core_ext/kernel/singleton_class'
1
+ require "erb"
2
+ require "active_support/core_ext/kernel/singleton_class"
3
+ require "active_support/multibyte/unicode"
3
4
 
4
5
  class ERB
5
6
  module Util
6
- HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#39;' }
7
- JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003e', '<' => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
7
+ HTML_ESCAPE = { "&" => "&amp;", ">" => "&gt;", "<" => "&lt;", '"' => "&quot;", "'" => "&#39;" }
8
+ JSON_ESCAPE = { "&" => '\u0026', ">" => '\u003e', "<" => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
8
9
  HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+)|(#[xX][\dA-Fa-f]+));)/
9
10
  JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
10
11
 
@@ -144,25 +145,23 @@ module ActiveSupport #:nodoc:
144
145
  # Raised when <tt>ActiveSupport::SafeBuffer#safe_concat</tt> is called on unsafe buffers.
145
146
  class SafeConcatError < StandardError
146
147
  def initialize
147
- super 'Could not concatenate to the buffer because it is not html safe.'
148
+ super "Could not concatenate to the buffer because it is not html safe."
148
149
  end
149
150
  end
150
151
 
151
152
  def [](*args)
152
153
  if args.size < 2
153
154
  super
154
- else
155
- if html_safe?
156
- new_safe_buffer = super
157
-
158
- if new_safe_buffer
159
- new_safe_buffer.instance_variable_set :@html_safe, true
160
- end
155
+ elsif html_safe?
156
+ new_safe_buffer = super
161
157
 
162
- new_safe_buffer
163
- else
164
- to_str[*args]
158
+ if new_safe_buffer
159
+ new_safe_buffer.instance_variable_set :@html_safe, true
165
160
  end
161
+
162
+ new_safe_buffer
163
+ else
164
+ to_str[*args]
166
165
  end
167
166
  end
168
167
 
@@ -171,7 +170,7 @@ module ActiveSupport #:nodoc:
171
170
  original_concat(value)
172
171
  end
173
172
 
174
- def initialize(str = '')
173
+ def initialize(str = "")
175
174
  @html_safe = true
176
175
  super
177
176
  end
@@ -201,7 +200,7 @@ module ActiveSupport #:nodoc:
201
200
  def %(args)
202
201
  case args
203
202
  when Hash
204
- escaped_args = Hash[args.map { |k,arg| [k, html_escape_interpolated_argument(arg)] }]
203
+ escaped_args = Hash[args.map { |k, arg| [k, html_escape_interpolated_argument(arg)] }]
205
204
  else
206
205
  escaped_args = Array(args).map { |arg| html_escape_interpolated_argument(arg) }
207
206
  end
@@ -242,9 +241,9 @@ module ActiveSupport #:nodoc:
242
241
 
243
242
  private
244
243
 
245
- def html_escape_interpolated_argument(arg)
246
- (!html_safe? || arg.html_safe?) ? arg : CGI.escapeHTML(arg.to_s)
247
- end
244
+ def html_escape_interpolated_argument(arg)
245
+ (!html_safe? || arg.html_safe?) ? arg : CGI.escapeHTML(arg.to_s)
246
+ end
248
247
  end
249
248
  end
250
249