activesupport 5.0.7.2 → 5.1.7

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 (211) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +464 -694
  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 +41 -48
  12. data/lib/active_support/cache/file_store.rb +11 -20
  13. data/lib/active_support/cache/mem_cache_store.rb +30 -40
  14. data/lib/active_support/cache/memory_store.rb +13 -13
  15. data/lib/active_support/cache/null_store.rb +4 -4
  16. data/lib/active_support/cache/strategy/local_cache.rb +13 -22
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +4 -5
  18. data/lib/active_support/callbacks.rb +649 -584
  19. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
  20. data/lib/active_support/concurrency/share_lock.rb +20 -21
  21. data/lib/active_support/configurable.rb +5 -5
  22. data/lib/active_support/core_ext.rb +1 -2
  23. data/lib/active_support/core_ext/array.rb +7 -7
  24. data/lib/active_support/core_ext/array/access.rb +1 -1
  25. data/lib/active_support/core_ext/array/conversions.rb +15 -15
  26. data/lib/active_support/core_ext/array/grouping.rb +1 -1
  27. data/lib/active_support/core_ext/array/inquiry.rb +1 -1
  28. data/lib/active_support/core_ext/array/prepend_and_append.rb +1 -1
  29. data/lib/active_support/core_ext/benchmark.rb +1 -1
  30. data/lib/active_support/core_ext/big_decimal.rb +1 -1
  31. data/lib/active_support/core_ext/big_decimal/conversions.rb +4 -6
  32. data/lib/active_support/core_ext/class.rb +2 -2
  33. data/lib/active_support/core_ext/class/attribute.rb +5 -5
  34. data/lib/active_support/core_ext/class/attribute_accessors.rb +1 -1
  35. data/lib/active_support/core_ext/class/subclasses.rb +18 -4
  36. data/lib/active_support/core_ext/date.rb +5 -5
  37. data/lib/active_support/core_ext/date/acts_like.rb +1 -1
  38. data/lib/active_support/core_ext/date/blank.rb +1 -1
  39. data/lib/active_support/core_ext/date/calculations.rb +8 -8
  40. data/lib/active_support/core_ext/date/conversions.rb +12 -12
  41. data/lib/active_support/core_ext/date/zones.rb +2 -2
  42. data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -22
  43. data/lib/active_support/core_ext/date_and_time/compatibility.rb +1 -1
  44. data/lib/active_support/core_ext/date_and_time/zones.rb +7 -8
  45. data/lib/active_support/core_ext/date_time.rb +5 -5
  46. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -2
  47. data/lib/active_support/core_ext/date_time/blank.rb +1 -1
  48. data/lib/active_support/core_ext/date_time/calculations.rb +20 -10
  49. data/lib/active_support/core_ext/date_time/compatibility.rb +2 -2
  50. data/lib/active_support/core_ext/date_time/conversions.rb +12 -12
  51. data/lib/active_support/core_ext/digest/uuid.rb +4 -4
  52. data/lib/active_support/core_ext/enumerable.rb +23 -12
  53. data/lib/active_support/core_ext/file.rb +1 -1
  54. data/lib/active_support/core_ext/file/atomic.rb +4 -4
  55. data/lib/active_support/core_ext/hash.rb +9 -9
  56. data/lib/active_support/core_ext/hash/compact.rb +12 -9
  57. data/lib/active_support/core_ext/hash/conversions.rb +36 -37
  58. data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -2
  59. data/lib/active_support/core_ext/hash/keys.rb +6 -6
  60. data/lib/active_support/core_ext/hash/reverse_merge.rb +1 -1
  61. data/lib/active_support/core_ext/hash/slice.rb +4 -4
  62. data/lib/active_support/core_ext/hash/transform_values.rb +1 -0
  63. data/lib/active_support/core_ext/integer.rb +3 -3
  64. data/lib/active_support/core_ext/integer/inflections.rb +1 -1
  65. data/lib/active_support/core_ext/integer/time.rb +2 -2
  66. data/lib/active_support/core_ext/kernel.rb +4 -4
  67. data/lib/active_support/core_ext/kernel/concern.rb +1 -1
  68. data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
  69. data/lib/active_support/core_ext/load_error.rb +1 -18
  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 +85 -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 +34 -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 +8 -5
  92. data/lib/active_support/core_ext/object/try.rb +1 -1
  93. data/lib/active_support/core_ext/object/with_options.rb +12 -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 +46 -29
  112. data/lib/active_support/core_ext/time/conversions.rb +15 -12
  113. data/lib/active_support/core_ext/time/zones.rb +3 -3
  114. data/lib/active_support/core_ext/uri.rb +2 -2
  115. data/lib/active_support/dependencies.rb +45 -46
  116. data/lib/active_support/dependencies/interlock.rb +1 -1
  117. data/lib/active_support/deprecation.rb +9 -8
  118. data/lib/active_support/deprecation/behaviors.rb +3 -3
  119. data/lib/active_support/deprecation/constant_accessor.rb +50 -0
  120. data/lib/active_support/deprecation/instance_delegator.rb +2 -2
  121. data/lib/active_support/deprecation/method_wrappers.rb +10 -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 +221 -28
  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 -55
  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 +2 -2
  132. data/lib/active_support/gzip.rb +4 -4
  133. data/lib/active_support/hash_with_indifferent_access.rb +40 -28
  134. data/lib/active_support/i18n.rb +5 -5
  135. data/lib/active_support/i18n_railtie.rb +14 -9
  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 +52 -51
  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 +2 -2
  146. data/lib/active_support/log_subscriber.rb +9 -7
  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 +77 -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 +7 -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 +5 -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 +8 -10
  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 +12 -32
  168. data/lib/active_support/number_helper/rounding_helper.rb +64 -0
  169. data/lib/active_support/option_merger.rb +1 -1
  170. data/lib/active_support/ordered_hash.rb +3 -3
  171. data/lib/active_support/ordered_options.rb +6 -4
  172. data/lib/active_support/per_thread_registry.rb +5 -5
  173. data/lib/active_support/rails.rb +12 -6
  174. data/lib/active_support/railtie.rb +3 -3
  175. data/lib/active_support/reloader.rb +1 -1
  176. data/lib/active_support/rescuable.rb +6 -6
  177. data/lib/active_support/security_utils.rb +1 -1
  178. data/lib/active_support/string_inquirer.rb +8 -2
  179. data/lib/active_support/subscriber.rb +9 -5
  180. data/lib/active_support/tagged_logging.rb +4 -4
  181. data/lib/active_support/test_case.rb +12 -29
  182. data/lib/active_support/testing/assertions.rb +100 -2
  183. data/lib/active_support/testing/autorun.rb +2 -2
  184. data/lib/active_support/testing/constant_lookup.rb +0 -1
  185. data/lib/active_support/testing/declarative.rb +1 -1
  186. data/lib/active_support/testing/deprecation.rb +3 -2
  187. data/lib/active_support/testing/isolation.rb +15 -22
  188. data/lib/active_support/testing/method_call_assertions.rb +1 -1
  189. data/lib/active_support/testing/setup_and_teardown.rb +2 -2
  190. data/lib/active_support/testing/stream.rb +28 -28
  191. data/lib/active_support/testing/tagged_logging.rb +1 -1
  192. data/lib/active_support/testing/time_helpers.rb +45 -11
  193. data/lib/active_support/time.rb +12 -12
  194. data/lib/active_support/time_with_zone.rb +16 -14
  195. data/lib/active_support/values/time_zone.rb +100 -31
  196. data/lib/active_support/values/unicode_tables.dat +0 -0
  197. data/lib/active_support/version.rb +1 -1
  198. data/lib/active_support/xml_mini.rb +34 -36
  199. data/lib/active_support/xml_mini/jdom.rb +112 -112
  200. data/lib/active_support/xml_mini/libxml.rb +12 -11
  201. data/lib/active_support/xml_mini/libxmlsax.rb +13 -14
  202. data/lib/active_support/xml_mini/nokogiri.rb +10 -10
  203. data/lib/active_support/xml_mini/nokogirisax.rb +12 -13
  204. data/lib/active_support/xml_mini/rexml.rb +9 -9
  205. metadata +8 -9
  206. data/lib/active_support/concurrency/latch.rb +0 -26
  207. data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
  208. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
  209. data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
  210. data/lib/active_support/core_ext/struct.rb +0 -3
  211. data/lib/active_support/core_ext/time/marshal.rb +0 -3
@@ -1,7 +1,7 @@
1
1
  module ActiveSupport #:nodoc:
2
2
  module Multibyte
3
- autoload :Chars, 'active_support/multibyte/chars'
4
- autoload :Unicode, 'active_support/multibyte/unicode'
3
+ autoload :Chars, "active_support/multibyte/chars"
4
+ autoload :Unicode, "active_support/multibyte/unicode"
5
5
 
6
6
  # The proxy class returned when calling mb_chars. You can use this accessor
7
7
  # to configure your own proxy class so you can support other encodings. See
@@ -1,7 +1,8 @@
1
- require 'active_support/json'
2
- require 'active_support/core_ext/string/access'
3
- require 'active_support/core_ext/string/behavior'
4
- require 'active_support/core_ext/module/delegation'
1
+ require "active_support/json"
2
+ require "active_support/core_ext/string/access"
3
+ require "active_support/core_ext/string/behavior"
4
+ require "active_support/core_ext/module/delegation"
5
+ require "active_support/core_ext/regexp"
5
6
 
6
7
  module ActiveSupport #:nodoc:
7
8
  module Multibyte #:nodoc:
@@ -15,7 +16,8 @@ module ActiveSupport #:nodoc:
15
16
  # through the +mb_chars+ method. Methods which would normally return a
16
17
  # String object now return a Chars object so methods can be chained.
17
18
  #
18
- # 'The Perfect String '.mb_chars.downcase.strip.normalize # => "the perfect string"
19
+ # 'The Perfect String '.mb_chars.downcase.strip.normalize
20
+ # # => #<ActiveSupport::Multibyte::Chars:0x007fdc434ccc10 @wrapped_string="the perfect string">
19
21
  #
20
22
  # Chars objects are perfectly interchangeable with String objects as long as
21
23
  # no explicit class checks are made. If certain methods do explicitly check
@@ -45,7 +47,7 @@ module ActiveSupport #:nodoc:
45
47
  alias to_s wrapped_string
46
48
  alias to_str wrapped_string
47
49
 
48
- delegate :<=>, :=~, :acts_like_string?, :to => :wrapped_string
50
+ delegate :<=>, :=~, :acts_like_string?, to: :wrapped_string
49
51
 
50
52
  # Creates a new Chars instance by wrapping _string_.
51
53
  def initialize(string)
@@ -56,7 +58,7 @@ module ActiveSupport #:nodoc:
56
58
  # Forward all undefined methods to the wrapped string.
57
59
  def method_missing(method, *args, &block)
58
60
  result = @wrapped_string.__send__(method, *args, &block)
59
- if method.to_s =~ /!$/
61
+ if /!$/.match?(method)
60
62
  self if result
61
63
  else
62
64
  result.kind_of?(String) ? chars(result) : result
@@ -86,7 +88,7 @@ module ActiveSupport #:nodoc:
86
88
  end
87
89
 
88
90
  # Works like <tt>String#slice!</tt>, but returns an instance of
89
- # Chars, or nil if the string was not modified. The string will not be
91
+ # Chars, or +nil+ if the string was not modified. The string will not be
90
92
  # modified if the range given is out of bounds
91
93
  #
92
94
  # string = 'Welcome'
@@ -105,7 +107,7 @@ module ActiveSupport #:nodoc:
105
107
  #
106
108
  # 'Café'.mb_chars.reverse.to_s # => 'éfaC'
107
109
  def reverse
108
- chars(Unicode.unpack_graphemes(@wrapped_string).reverse.flatten.pack('U*'))
110
+ chars(Unicode.unpack_graphemes(@wrapped_string).reverse.flatten.pack("U*"))
109
111
  end
110
112
 
111
113
  # Limits the byte size of the string to a number of bytes without breaking
@@ -133,7 +135,7 @@ module ActiveSupport #:nodoc:
133
135
 
134
136
  # Converts characters in the string to the opposite case.
135
137
  #
136
- # 'El Cañón".mb_chars.swapcase.to_s # => "eL cAÑÓN"
138
+ # 'El Cañón'.mb_chars.swapcase.to_s # => "eL cAÑÓN"
137
139
  def swapcase
138
140
  chars Unicode.swapcase(@wrapped_string)
139
141
  end
@@ -142,15 +144,15 @@ module ActiveSupport #:nodoc:
142
144
  #
143
145
  # 'über'.mb_chars.capitalize.to_s # => "Über"
144
146
  def capitalize
145
- (slice(0) || chars('')).upcase + (slice(1..-1) || chars('')).downcase
147
+ (slice(0) || chars("")).upcase + (slice(1..-1) || chars("")).downcase
146
148
  end
147
149
 
148
150
  # Capitalizes the first letter of every word, when possible.
149
151
  #
150
- # "ÉL QUE SE ENTERÓ".mb_chars.titleize # => "Él Que Se Enteró"
151
- # "日本語".mb_chars.titleize # => "日本語"
152
+ # "ÉL QUE SE ENTERÓ".mb_chars.titleize.to_s # => "Él Que Se Enteró"
153
+ # "日本語".mb_chars.titleize.to_s # => "日本語"
152
154
  def titleize
153
- chars(downcase.to_s.gsub(/\b('?\S)/u) { Unicode.upcase($1)})
155
+ chars(downcase.to_s.gsub(/\b('?\S)/u) { Unicode.upcase($1) })
154
156
  end
155
157
  alias_method :titlecase, :titleize
156
158
 
@@ -170,7 +172,7 @@ module ActiveSupport #:nodoc:
170
172
  # 'é'.length # => 2
171
173
  # 'é'.mb_chars.decompose.to_s.length # => 3
172
174
  def decompose
173
- chars(Unicode.decompose(:canonical, @wrapped_string.codepoints.to_a).pack('U*'))
175
+ chars(Unicode.decompose(:canonical, @wrapped_string.codepoints.to_a).pack("U*"))
174
176
  end
175
177
 
176
178
  # Performs composition on all the characters.
@@ -178,7 +180,7 @@ module ActiveSupport #:nodoc:
178
180
  # 'é'.length # => 3
179
181
  # 'é'.mb_chars.compose.to_s.length # => 2
180
182
  def compose
181
- chars(Unicode.compose(@wrapped_string.codepoints.to_a).pack('U*'))
183
+ chars(Unicode.compose(@wrapped_string.codepoints.to_a).pack("U*"))
182
184
  end
183
185
 
184
186
  # Returns the number of grapheme clusters in the string.
@@ -209,21 +211,21 @@ module ActiveSupport #:nodoc:
209
211
  end
210
212
  end
211
213
 
212
- protected
214
+ private
213
215
 
214
- def translate_offset(byte_offset) #:nodoc:
216
+ def translate_offset(byte_offset)
215
217
  return nil if byte_offset.nil?
216
- return 0 if @wrapped_string == ''
218
+ return 0 if @wrapped_string == ""
217
219
 
218
220
  begin
219
- @wrapped_string.byteslice(0...byte_offset).unpack('U*').length
221
+ @wrapped_string.byteslice(0...byte_offset).unpack("U*").length
220
222
  rescue ArgumentError
221
223
  byte_offset -= 1
222
224
  retry
223
225
  end
224
226
  end
225
227
 
226
- def chars(string) #:nodoc:
228
+ def chars(string)
227
229
  self.class.new(string)
228
230
  end
229
231
  end
@@ -1,7 +1,6 @@
1
1
  module ActiveSupport
2
2
  module Multibyte
3
3
  module Unicode
4
-
5
4
  extend self
6
5
 
7
6
  # A list of all available normalization forms.
@@ -10,7 +9,7 @@ module ActiveSupport
10
9
  NORMALIZATION_FORMS = [:c, :kc, :d, :kd]
11
10
 
12
11
  # The Unicode version that is supported by the implementation
13
- UNICODE_VERSION = '8.0.0'
12
+ UNICODE_VERSION = "9.0.0"
14
13
 
15
14
  # The default normalization used for operations that require
16
15
  # normalization. It can be set to any of the normalizations
@@ -31,36 +30,6 @@ module ActiveSupport
31
30
  HANGUL_NCOUNT = HANGUL_VCOUNT * HANGUL_TCOUNT
32
31
  HANGUL_SCOUNT = 11172
33
32
  HANGUL_SLAST = HANGUL_SBASE + HANGUL_SCOUNT
34
- HANGUL_JAMO_FIRST = 0x1100
35
- HANGUL_JAMO_LAST = 0x11FF
36
-
37
- # All the unicode whitespace
38
- WHITESPACE = [
39
- (0x0009..0x000D).to_a, # White_Space # Cc [5] <control-0009>..<control-000D>
40
- 0x0020, # White_Space # Zs SPACE
41
- 0x0085, # White_Space # Cc <control-0085>
42
- 0x00A0, # White_Space # Zs NO-BREAK SPACE
43
- 0x1680, # White_Space # Zs OGHAM SPACE MARK
44
- (0x2000..0x200A).to_a, # White_Space # Zs [11] EN QUAD..HAIR SPACE
45
- 0x2028, # White_Space # Zl LINE SEPARATOR
46
- 0x2029, # White_Space # Zp PARAGRAPH SEPARATOR
47
- 0x202F, # White_Space # Zs NARROW NO-BREAK SPACE
48
- 0x205F, # White_Space # Zs MEDIUM MATHEMATICAL SPACE
49
- 0x3000, # White_Space # Zs IDEOGRAPHIC SPACE
50
- ].flatten.freeze
51
-
52
- # BOM (byte order mark) can also be seen as whitespace, it's a
53
- # non-rendering character used to distinguish between little and big
54
- # endian. This is not an issue in utf-8, so it must be ignored.
55
- LEADERS_AND_TRAILERS = WHITESPACE + [65279] # ZERO-WIDTH NO-BREAK SPACE aka BOM
56
-
57
- # Returns a regular expression pattern that matches the passed Unicode
58
- # codepoints.
59
- def self.codepoints_to_pattern(array_of_codepoints) #:nodoc:
60
- array_of_codepoints.collect{ |e| [e].pack 'U*'.freeze }.join('|'.freeze)
61
- end
62
- TRAILERS_PAT = /(#{codepoints_to_pattern(LEADERS_AND_TRAILERS)})+\Z/u
63
- LEADERS_PAT = /\A(#{codepoints_to_pattern(LEADERS_AND_TRAILERS)})+/u
64
33
 
65
34
  # Detect whether the codepoint is in a certain character class. Returns
66
35
  # +true+ when it's in the specified character class and +false+ otherwise.
@@ -83,35 +52,35 @@ module ActiveSupport
83
52
  pos = 0
84
53
  marker = 0
85
54
  eoc = codepoints.length
86
- while(pos < eoc)
55
+ while (pos < eoc)
87
56
  pos += 1
88
- previous = codepoints[pos-1]
57
+ previous = codepoints[pos - 1]
89
58
  current = codepoints[pos]
90
59
 
60
+ # See http://unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules
91
61
  should_break =
62
+ if pos == eoc
63
+ true
92
64
  # GB3. CR X LF
93
- if previous == database.boundary[:cr] and current == database.boundary[:lf]
65
+ elsif previous == database.boundary[:cr] && current == database.boundary[:lf]
94
66
  false
95
67
  # GB4. (Control|CR|LF) ÷
96
- elsif previous and in_char_class?(previous, [:control,:cr,:lf])
68
+ elsif previous && in_char_class?(previous, [:control, :cr, :lf])
97
69
  true
98
70
  # GB5. ÷ (Control|CR|LF)
99
- elsif in_char_class?(current, [:control,:cr,:lf])
71
+ elsif in_char_class?(current, [:control, :cr, :lf])
100
72
  true
101
73
  # GB6. L X (L|V|LV|LVT)
102
- elsif database.boundary[:l] === previous and in_char_class?(current, [:l,:v,:lv,:lvt])
74
+ elsif database.boundary[:l] === previous && in_char_class?(current, [:l, :v, :lv, :lvt])
103
75
  false
104
76
  # GB7. (LV|V) X (V|T)
105
- elsif in_char_class?(previous, [:lv,:v]) and in_char_class?(current, [:v,:t])
77
+ elsif in_char_class?(previous, [:lv, :v]) && in_char_class?(current, [:v, :t])
106
78
  false
107
79
  # GB8. (LVT|T) X (T)
108
- elsif in_char_class?(previous, [:lvt,:t]) and database.boundary[:t] === current
80
+ elsif in_char_class?(previous, [:lvt, :t]) && database.boundary[:t] === current
109
81
  false
110
- # GB8a. Regional_Indicator X Regional_Indicator
111
- elsif database.boundary[:regional_indicator] === previous and database.boundary[:regional_indicator] === current
112
- false
113
- # GB9. X Extend
114
- elsif database.boundary[:extend] === current
82
+ # GB9. X (Extend | ZWJ)
83
+ elsif in_char_class?(current, [:extend, :zwj])
115
84
  false
116
85
  # GB9a. X SpacingMark
117
86
  elsif database.boundary[:spacingmark] === current
@@ -119,13 +88,23 @@ module ActiveSupport
119
88
  # GB9b. Prepend X
120
89
  elsif database.boundary[:prepend] === previous
121
90
  false
122
- # GB10. Any ÷ Any
91
+ # GB10. (E_Base | EBG) Extend* X E_Modifier
92
+ elsif (marker...pos).any? { |i| in_char_class?(codepoints[i], [:e_base, :e_base_gaz]) && codepoints[i + 1...pos].all? { |c| database.boundary[:extend] === c } } && database.boundary[:e_modifier] === current
93
+ false
94
+ # GB11. ZWJ X (Glue_After_Zwj | EBG)
95
+ elsif database.boundary[:zwj] === previous && in_char_class?(current, [:glue_after_zwj, :e_base_gaz])
96
+ false
97
+ # GB12. ^ (RI RI)* RI X RI
98
+ # GB13. [^RI] (RI RI)* RI X RI
99
+ elsif codepoints[marker..pos].all? { |c| database.boundary[:regional_indicator] === c } && codepoints[marker..pos].count { |c| database.boundary[:regional_indicator] === c }.even?
100
+ false
101
+ # GB999. Any ÷ Any
123
102
  else
124
103
  true
125
104
  end
126
105
 
127
106
  if should_break
128
- unpacked << codepoints[marker..pos-1]
107
+ unpacked << codepoints[marker..pos - 1]
129
108
  marker = pos
130
109
  end
131
110
  end
@@ -136,17 +115,17 @@ module ActiveSupport
136
115
  #
137
116
  # Unicode.pack_graphemes(Unicode.unpack_graphemes('क्षि')) # => 'क्षि'
138
117
  def pack_graphemes(unpacked)
139
- unpacked.flatten.pack('U*')
118
+ unpacked.flatten.pack("U*")
140
119
  end
141
120
 
142
121
  # Re-order codepoints so the string becomes canonical.
143
122
  def reorder_characters(codepoints)
144
- length = codepoints.length- 1
123
+ length = codepoints.length - 1
145
124
  pos = 0
146
125
  while pos < length do
147
- cp1, cp2 = database.codepoints[codepoints[pos]], database.codepoints[codepoints[pos+1]]
126
+ cp1, cp2 = database.codepoints[codepoints[pos]], database.codepoints[codepoints[pos + 1]]
148
127
  if (cp1.combining_class > cp2.combining_class) && (cp2.combining_class > 0)
149
- codepoints[pos..pos+1] = cp2.code, cp1.code
128
+ codepoints[pos..pos + 1] = cp2.code, cp1.code
150
129
  pos += (pos > 0 ? -1 : 1)
151
130
  else
152
131
  pos += 1
@@ -159,7 +138,7 @@ module ActiveSupport
159
138
  def decompose(type, codepoints)
160
139
  codepoints.inject([]) do |decomposed, cp|
161
140
  # if it's a hangul syllable starter character
162
- if HANGUL_SBASE <= cp and cp < HANGUL_SLAST
141
+ if HANGUL_SBASE <= cp && cp < HANGUL_SLAST
163
142
  sindex = cp - HANGUL_SBASE
164
143
  ncp = [] # new codepoints
165
144
  ncp << HANGUL_LBASE + sindex / HANGUL_NCOUNT
@@ -168,7 +147,7 @@ module ActiveSupport
168
147
  ncp << (HANGUL_TBASE + tindex) unless tindex == 0
169
148
  decomposed.concat ncp
170
149
  # if the codepoint is decomposable in with the current decomposition type
171
- elsif (ncp = database.codepoints[cp].decomp_mapping) and (!database.codepoints[cp].decomp_type || type == :compatibility)
150
+ elsif (ncp = database.codepoints[cp].decomp_mapping) && (!database.codepoints[cp].decomp_type || type == :compatibility)
172
151
  decomposed.concat decompose(type, ncp.dup)
173
152
  else
174
153
  decomposed << cp
@@ -187,11 +166,11 @@ module ActiveSupport
187
166
  pos += 1
188
167
  lindex = starter_char - HANGUL_LBASE
189
168
  # -- Hangul
190
- if 0 <= lindex and lindex < HANGUL_LCOUNT
191
- vindex = codepoints[starter_pos+1] - HANGUL_VBASE rescue vindex = -1
192
- if 0 <= vindex and vindex < HANGUL_VCOUNT
193
- tindex = codepoints[starter_pos+2] - HANGUL_TBASE rescue tindex = -1
194
- if 0 <= tindex and tindex < HANGUL_TCOUNT
169
+ if 0 <= lindex && lindex < HANGUL_LCOUNT
170
+ vindex = codepoints[starter_pos + 1] - HANGUL_VBASE rescue vindex = -1
171
+ if 0 <= vindex && vindex < HANGUL_VCOUNT
172
+ tindex = codepoints[starter_pos + 2] - HANGUL_TBASE rescue tindex = -1
173
+ if 0 <= tindex && tindex < HANGUL_TCOUNT
195
174
  j = starter_pos + 2
196
175
  eoa -= 2
197
176
  else
@@ -259,7 +238,7 @@ module ActiveSupport
259
238
  reader = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_16LE)
260
239
 
261
240
  source = string.dup
262
- out = ''.force_encoding(Encoding::UTF_16LE)
241
+ out = "".force_encoding(Encoding::UTF_16LE)
263
242
 
264
243
  loop do
265
244
  reader.primitive_convert(source, out)
@@ -282,22 +261,22 @@ module ActiveSupport
282
261
  # * <tt>form</tt> - The form you want to normalize in. Should be one of
283
262
  # the following: <tt>:c</tt>, <tt>:kc</tt>, <tt>:d</tt>, or <tt>:kd</tt>.
284
263
  # Default is ActiveSupport::Multibyte::Unicode.default_normalization_form.
285
- def normalize(string, form=nil)
264
+ def normalize(string, form = nil)
286
265
  form ||= @default_normalization_form
287
266
  # See http://www.unicode.org/reports/tr15, Table 1
288
267
  codepoints = string.codepoints.to_a
289
268
  case form
290
- when :d
291
- reorder_characters(decompose(:canonical, codepoints))
292
- when :c
293
- compose(reorder_characters(decompose(:canonical, codepoints)))
294
- when :kd
295
- reorder_characters(decompose(:compatibility, codepoints))
296
- when :kc
297
- compose(reorder_characters(decompose(:compatibility, codepoints)))
269
+ when :d
270
+ reorder_characters(decompose(:canonical, codepoints))
271
+ when :c
272
+ compose(reorder_characters(decompose(:canonical, codepoints)))
273
+ when :kd
274
+ reorder_characters(decompose(:compatibility, codepoints))
275
+ when :kc
276
+ compose(reorder_characters(decompose(:compatibility, codepoints)))
298
277
  else
299
- raise ArgumentError, "#{form} is not a valid normalization variant", caller
300
- end.pack('U*'.freeze)
278
+ raise ArgumentError, "#{form} is not a valid normalization variant", caller
279
+ end.pack("U*".freeze)
301
280
  end
302
281
 
303
282
  def downcase(string)
@@ -356,7 +335,7 @@ module ActiveSupport
356
335
  # UnicodeDatabase.
357
336
  def load
358
337
  begin
359
- @codepoints, @composition_exclusion, @composition_map, @boundary, @cp1252 = File.open(self.class.filename, 'rb') { |f| Marshal.load f.read }
338
+ @codepoints, @composition_exclusion, @composition_map, @boundary, @cp1252 = File.open(self.class.filename, "rb") { |f| Marshal.load f.read }
360
339
  rescue => e
361
340
  raise IOError.new("Couldn't load the Unicode tables for UTF8Handler (#{e.message}), ActiveSupport::Multibyte is unusable")
362
341
  end
@@ -378,7 +357,7 @@ module ActiveSupport
378
357
 
379
358
  # Returns the directory in which the data files are stored.
380
359
  def self.dirname
381
- File.dirname(__FILE__) + '/../values/'
360
+ File.dirname(__FILE__) + "/../values/"
382
361
  end
383
362
 
384
363
  # Returns the filename for the data file for this version.
@@ -389,25 +368,25 @@ module ActiveSupport
389
368
 
390
369
  private
391
370
 
392
- def apply_mapping(string, mapping) #:nodoc:
393
- database.codepoints
394
- string.each_codepoint.map do |codepoint|
395
- cp = database.codepoints[codepoint]
396
- if cp and (ncp = cp.send(mapping)) and ncp > 0
397
- ncp
398
- else
399
- codepoint
400
- end
401
- end.pack('U*')
402
- end
371
+ def apply_mapping(string, mapping)
372
+ database.codepoints
373
+ string.each_codepoint.map do |codepoint|
374
+ cp = database.codepoints[codepoint]
375
+ if cp && (ncp = cp.send(mapping)) && ncp > 0
376
+ ncp
377
+ else
378
+ codepoint
379
+ end
380
+ end.pack("U*")
381
+ end
403
382
 
404
- def recode_windows1252_chars(string)
405
- string.encode(Encoding::UTF_8, Encoding::Windows_1252, invalid: :replace, undef: :replace)
406
- end
383
+ def recode_windows1252_chars(string)
384
+ string.encode(Encoding::UTF_8, Encoding::Windows_1252, invalid: :replace, undef: :replace)
385
+ end
407
386
 
408
- def database
409
- @database ||= UnicodeDatabase.new
410
- end
387
+ def database
388
+ @database ||= UnicodeDatabase.new
389
+ end
411
390
  end
412
391
  end
413
392
  end
@@ -1,6 +1,6 @@
1
- require 'active_support/notifications/instrumenter'
2
- require 'active_support/notifications/fanout'
3
- require 'active_support/per_thread_registry'
1
+ require "active_support/notifications/instrumenter"
2
+ require "active_support/notifications/fanout"
3
+ require "active_support/per_thread_registry"
4
4
 
5
5
  module ActiveSupport
6
6
  # = Notifications
@@ -13,7 +13,7 @@ module ActiveSupport
13
13
  # To instrument an event you just need to do:
14
14
  #
15
15
  # ActiveSupport::Notifications.instrument('render', extra: :information) do
16
- # render text: 'Foo'
16
+ # render plain: 'Foo'
17
17
  # end
18
18
  #
19
19
  # That first executes the block and then notifies all subscribers once done.
@@ -48,7 +48,7 @@ module ActiveSupport
48
48
  # The block is saved and will be called whenever someone instruments "render":
49
49
  #
50
50
  # ActiveSupport::Notifications.instrument('render', extra: :information) do
51
- # render text: 'Foo'
51
+ # render plain: 'Foo'
52
52
  # end
53
53
  #
54
54
  # event = events.first
@@ -64,6 +64,8 @@ module ActiveSupport
64
64
  # If an exception happens during that particular instrumentation the payload will
65
65
  # have a key <tt>:exception</tt> with an array of two elements as value: a string with
66
66
  # the name of the exception class, and the exception message.
67
+ # The <tt>:exception_object</tt> key of the payload will have the exception
68
+ # itself as the value.
67
69
  #
68
70
  # As the previous example depicts, the class <tt>ActiveSupport::Notifications::Event</tt>
69
71
  # is able to take the arguments as they come and provide an object-oriented