activesupport 4.2.0 → 5.0.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +630 -220
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +2 -3
  5. data/lib/active_support/array_inquirer.rb +44 -0
  6. data/lib/active_support/backtrace_cleaner.rb +1 -1
  7. data/lib/active_support/benchmarkable.rb +1 -1
  8. data/lib/active_support/cache/file_store.rb +36 -22
  9. data/lib/active_support/cache/mem_cache_store.rb +63 -54
  10. data/lib/active_support/cache/memory_store.rb +16 -21
  11. data/lib/active_support/cache/null_store.rb +1 -4
  12. data/lib/active_support/cache/strategy/local_cache.rb +31 -20
  13. data/lib/active_support/cache.rb +73 -89
  14. data/lib/active_support/callbacks.rb +195 -155
  15. data/lib/active_support/concern.rb +2 -2
  16. data/lib/active_support/concurrency/latch.rb +7 -15
  17. data/lib/active_support/concurrency/share_lock.rb +186 -0
  18. data/lib/active_support/configurable.rb +1 -0
  19. data/lib/active_support/core_ext/array/access.rb +27 -1
  20. data/lib/active_support/core_ext/array/conversions.rb +6 -4
  21. data/lib/active_support/core_ext/array/grouping.rb +9 -18
  22. data/lib/active_support/core_ext/array/inquiry.rb +17 -0
  23. data/lib/active_support/core_ext/array/wrap.rb +5 -4
  24. data/lib/active_support/core_ext/array.rb +1 -0
  25. data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -10
  26. data/lib/active_support/core_ext/class/attribute.rb +10 -9
  27. data/lib/active_support/core_ext/class/subclasses.rb +3 -4
  28. data/lib/active_support/core_ext/class.rb +0 -1
  29. data/lib/active_support/core_ext/date/blank.rb +12 -0
  30. data/lib/active_support/core_ext/date/calculations.rb +1 -1
  31. data/lib/active_support/core_ext/date/conversions.rb +13 -6
  32. data/lib/active_support/core_ext/date.rb +1 -1
  33. data/lib/active_support/core_ext/date_and_time/calculations.rb +109 -25
  34. data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -0
  35. data/lib/active_support/core_ext/date_and_time/zones.rb +3 -4
  36. data/lib/active_support/core_ext/date_time/blank.rb +12 -0
  37. data/lib/active_support/core_ext/date_time/calculations.rb +36 -10
  38. data/lib/active_support/core_ext/date_time/compatibility.rb +5 -0
  39. data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
  40. data/lib/active_support/core_ext/date_time.rb +2 -1
  41. data/lib/active_support/core_ext/enumerable.rb +49 -5
  42. data/lib/active_support/core_ext/file/atomic.rb +30 -25
  43. data/lib/active_support/core_ext/hash/conversions.rb +23 -4
  44. data/lib/active_support/core_ext/hash/deep_merge.rb +1 -1
  45. data/lib/active_support/core_ext/hash/except.rb +9 -8
  46. data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -1
  47. data/lib/active_support/core_ext/hash/keys.rb +23 -19
  48. data/lib/active_support/core_ext/hash/slice.rb +1 -1
  49. data/lib/active_support/core_ext/hash/transform_values.rb +11 -5
  50. data/lib/active_support/core_ext/integer/time.rb +1 -16
  51. data/lib/active_support/core_ext/kernel/concern.rb +2 -0
  52. data/lib/active_support/core_ext/kernel/debugger.rb +3 -10
  53. data/lib/active_support/core_ext/kernel/reporting.rb +2 -83
  54. data/lib/active_support/core_ext/kernel.rb +0 -1
  55. data/lib/active_support/core_ext/load_error.rb +4 -2
  56. data/lib/active_support/core_ext/marshal.rb +12 -11
  57. data/lib/active_support/core_ext/module/aliasing.rb +6 -1
  58. data/lib/active_support/core_ext/module/anonymous.rb +10 -1
  59. data/lib/active_support/core_ext/module/attr_internal.rb +2 -5
  60. data/lib/active_support/core_ext/module/attribute_accessors.rb +15 -15
  61. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +141 -0
  62. data/lib/active_support/core_ext/module/concerning.rb +4 -4
  63. data/lib/active_support/core_ext/module/delegation.rb +35 -25
  64. data/lib/active_support/core_ext/module/deprecation.rb +2 -2
  65. data/lib/active_support/core_ext/module/introspection.rb +4 -0
  66. data/lib/active_support/core_ext/module/method_transplanting.rb +3 -11
  67. data/lib/active_support/core_ext/module/qualified_const.rb +30 -12
  68. data/lib/active_support/core_ext/module/remove_method.rb +23 -0
  69. data/lib/active_support/core_ext/module.rb +1 -0
  70. data/lib/active_support/core_ext/name_error.rb +15 -2
  71. data/lib/active_support/core_ext/numeric/bytes.rb +20 -0
  72. data/lib/active_support/core_ext/numeric/conversions.rb +74 -64
  73. data/lib/active_support/core_ext/numeric/inquiry.rb +26 -0
  74. data/lib/active_support/core_ext/numeric/time.rb +24 -19
  75. data/lib/active_support/core_ext/numeric.rb +1 -0
  76. data/lib/active_support/core_ext/object/blank.rb +17 -5
  77. data/lib/active_support/core_ext/object/deep_dup.rb +10 -3
  78. data/lib/active_support/core_ext/object/duplicable.rb +8 -13
  79. data/lib/active_support/core_ext/object/inclusion.rb +2 -2
  80. data/lib/active_support/core_ext/object/instance_variables.rb +1 -1
  81. data/lib/active_support/core_ext/object/json.rb +15 -7
  82. data/lib/active_support/core_ext/object/to_query.rb +1 -1
  83. data/lib/active_support/core_ext/object/try.rb +68 -22
  84. data/lib/active_support/core_ext/object/with_options.rb +1 -1
  85. data/lib/active_support/core_ext/object.rb +0 -1
  86. data/lib/active_support/core_ext/range/conversions.rb +18 -6
  87. data/lib/active_support/core_ext/range/each.rb +16 -18
  88. data/lib/active_support/core_ext/range/include_range.rb +20 -20
  89. data/lib/active_support/core_ext/securerandom.rb +23 -0
  90. data/lib/active_support/core_ext/string/access.rb +1 -1
  91. data/lib/active_support/core_ext/string/behavior.rb +1 -1
  92. data/lib/active_support/core_ext/string/conversions.rb +4 -3
  93. data/lib/active_support/core_ext/string/filters.rb +5 -5
  94. data/lib/active_support/core_ext/string/inflections.rb +32 -5
  95. data/lib/active_support/core_ext/string/multibyte.rb +11 -7
  96. data/lib/active_support/core_ext/string/output_safety.rb +18 -16
  97. data/lib/active_support/core_ext/string/strip.rb +3 -6
  98. data/lib/active_support/core_ext/struct.rb +3 -6
  99. data/lib/active_support/core_ext/time/calculations.rb +36 -11
  100. data/lib/active_support/core_ext/time/compatibility.rb +5 -0
  101. data/lib/active_support/core_ext/time/conversions.rb +4 -2
  102. data/lib/active_support/core_ext/time/marshal.rb +2 -29
  103. data/lib/active_support/core_ext/time/zones.rb +36 -4
  104. data/lib/active_support/core_ext/time.rb +1 -1
  105. data/lib/active_support/core_ext/uri.rb +1 -3
  106. data/lib/active_support/core_ext.rb +2 -1
  107. data/lib/active_support/dependencies/interlock.rb +51 -0
  108. data/lib/active_support/dependencies.rb +87 -95
  109. data/lib/active_support/deprecation/behaviors.rb +16 -2
  110. data/lib/active_support/deprecation/method_wrappers.rb +42 -16
  111. data/lib/active_support/deprecation/proxy_wrappers.rb +47 -24
  112. data/lib/active_support/deprecation/reporting.rb +23 -5
  113. data/lib/active_support/deprecation.rb +1 -1
  114. data/lib/active_support/duration/iso8601_parser.rb +122 -0
  115. data/lib/active_support/duration/iso8601_serializer.rb +51 -0
  116. data/lib/active_support/duration.rb +55 -10
  117. data/lib/active_support/evented_file_update_checker.rb +194 -0
  118. data/lib/active_support/execution_wrapper.rb +117 -0
  119. data/lib/active_support/executor.rb +6 -0
  120. data/lib/active_support/file_update_checker.rb +23 -3
  121. data/lib/active_support/gem_version.rb +4 -4
  122. data/lib/active_support/hash_with_indifferent_access.rb +46 -13
  123. data/lib/active_support/i18n_railtie.rb +25 -4
  124. data/lib/active_support/inflector/inflections.rb +36 -5
  125. data/lib/active_support/inflector/methods.rb +97 -90
  126. data/lib/active_support/inflector/transliterate.rb +36 -21
  127. data/lib/active_support/json/decoding.rb +11 -10
  128. data/lib/active_support/json/encoding.rb +4 -49
  129. data/lib/active_support/key_generator.rb +7 -9
  130. data/lib/active_support/locale/en.yml +2 -0
  131. data/lib/active_support/log_subscriber/test_helper.rb +3 -3
  132. data/lib/active_support/log_subscriber.rb +1 -1
  133. data/lib/active_support/logger.rb +50 -1
  134. data/lib/active_support/logger_silence.rb +8 -4
  135. data/lib/active_support/logger_thread_safe_level.rb +31 -0
  136. data/lib/active_support/message_encryptor.rb +4 -4
  137. data/lib/active_support/message_verifier.rb +70 -8
  138. data/lib/active_support/multibyte/chars.rb +13 -4
  139. data/lib/active_support/multibyte/unicode.rb +44 -21
  140. data/lib/active_support/notifications/fanout.rb +6 -6
  141. data/lib/active_support/notifications/instrumenter.rb +20 -2
  142. data/lib/active_support/notifications.rb +2 -2
  143. data/lib/active_support/number_helper/number_to_currency_converter.rb +7 -9
  144. data/lib/active_support/number_helper/number_to_delimited_converter.rb +8 -3
  145. data/lib/active_support/number_helper/number_to_human_converter.rb +6 -4
  146. data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -2
  147. data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
  148. data/lib/active_support/number_helper/number_to_phone_converter.rb +11 -2
  149. data/lib/active_support/number_helper/number_to_rounded_converter.rb +30 -25
  150. data/lib/active_support/number_helper.rb +90 -67
  151. data/lib/active_support/ordered_hash.rb +1 -1
  152. data/lib/active_support/ordered_options.rb +15 -1
  153. data/lib/active_support/per_thread_registry.rb +8 -3
  154. data/lib/active_support/rails.rb +2 -2
  155. data/lib/active_support/railtie.rb +6 -1
  156. data/lib/active_support/reloader.rb +129 -0
  157. data/lib/active_support/rescuable.rb +93 -47
  158. data/lib/active_support/security_utils.rb +7 -0
  159. data/lib/active_support/string_inquirer.rb +1 -1
  160. data/lib/active_support/subscriber.rb +5 -10
  161. data/lib/active_support/tagged_logging.rb +3 -1
  162. data/lib/active_support/test_case.rb +15 -29
  163. data/lib/active_support/testing/assertions.rb +15 -13
  164. data/lib/active_support/testing/autorun.rb +8 -1
  165. data/lib/active_support/testing/deprecation.rb +9 -8
  166. data/lib/active_support/testing/file_fixtures.rb +34 -0
  167. data/lib/active_support/testing/isolation.rb +22 -8
  168. data/lib/active_support/testing/method_call_assertions.rb +41 -0
  169. data/lib/active_support/testing/stream.rb +42 -0
  170. data/lib/active_support/testing/time_helpers.rb +13 -10
  171. data/lib/active_support/time_with_zone.rb +135 -46
  172. data/lib/active_support/values/time_zone.rb +95 -47
  173. data/lib/active_support/values/unicode_tables.dat +0 -0
  174. data/lib/active_support/xml_mini/jdom.rb +7 -6
  175. data/lib/active_support/xml_mini/libxml.rb +2 -2
  176. data/lib/active_support/xml_mini/nokogiri.rb +2 -2
  177. data/lib/active_support/xml_mini/rexml.rb +7 -8
  178. data/lib/active_support/xml_mini.rb +22 -14
  179. data/lib/active_support.rb +20 -6
  180. metadata +33 -35
  181. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -14
  182. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  183. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
  184. data/lib/active_support/core_ext/object/itself.rb +0 -15
  185. data/lib/active_support/core_ext/thread.rb +0 -86
@@ -15,7 +15,7 @@ module ActiveSupport
15
15
 
16
16
  extend self
17
17
 
18
- # Formats a +number+ into a US phone number (e.g., (555)
18
+ # Formats a +number+ into a phone number (US by default e.g., (555)
19
19
  # 123-9876). You can customize the format in the +options+ hash.
20
20
  #
21
21
  # ==== Options
@@ -27,19 +27,26 @@ module ActiveSupport
27
27
  # end of the generated number.
28
28
  # * <tt>:country_code</tt> - Sets the country code for the phone
29
29
  # number.
30
+ # * <tt>:pattern</tt> - Specifies how the number is divided into three
31
+ # groups with the custom regexp to override the default format.
30
32
  # ==== Examples
31
33
  #
32
- # number_to_phone(5551234) # => 555-1234
33
- # number_to_phone('5551234') # => 555-1234
34
- # number_to_phone(1235551234) # => 123-555-1234
35
- # number_to_phone(1235551234, area_code: true) # => (123) 555-1234
36
- # number_to_phone(1235551234, delimiter: ' ') # => 123 555 1234
37
- # number_to_phone(1235551234, area_code: true, extension: 555) # => (123) 555-1234 x 555
38
- # number_to_phone(1235551234, country_code: 1) # => +1-123-555-1234
39
- # number_to_phone('123a456') # => 123a456
34
+ # number_to_phone(5551234) # => "555-1234"
35
+ # number_to_phone('5551234') # => "555-1234"
36
+ # number_to_phone(1235551234) # => "123-555-1234"
37
+ # number_to_phone(1235551234, area_code: true) # => "(123) 555-1234"
38
+ # number_to_phone(1235551234, delimiter: ' ') # => "123 555 1234"
39
+ # number_to_phone(1235551234, area_code: true, extension: 555) # => "(123) 555-1234 x 555"
40
+ # number_to_phone(1235551234, country_code: 1) # => "+1-123-555-1234"
41
+ # number_to_phone('123a456') # => "123a456"
40
42
  #
41
43
  # number_to_phone(1235551234, country_code: 1, extension: 1343, delimiter: '.')
42
- # # => +1.123.555.1234 x 1343
44
+ # # => "+1.123.555.1234 x 1343"
45
+ #
46
+ # number_to_phone(75561234567, pattern: /(\d{1,4})(\d{4})(\d{4})$/, area_code: true)
47
+ # # => "(755) 6123-4567"
48
+ # number_to_phone(13312345678, pattern: /(\d{3})(\d{4})(\d{4})$/))
49
+ # # => "133-1234-5678"
43
50
  def number_to_phone(number, options = {})
44
51
  NumberToPhoneConverter.convert(number, options)
45
52
  end
@@ -47,6 +54,14 @@ module ActiveSupport
47
54
  # Formats a +number+ into a currency string (e.g., $13.65). You
48
55
  # can customize the format in the +options+ hash.
49
56
  #
57
+ # The currency unit and number formatting of the current locale will be used
58
+ # unless otherwise specified in the provided options. No currency conversion
59
+ # is performed. If the user is given a way to change their locale, they will
60
+ # also be able to change the relative value of the currency displayed with
61
+ # this helper. If your application will ever support multiple locales, you
62
+ # may want to specify a constant <tt>:locale</tt> option or consider
63
+ # using a library capable of currency conversion.
64
+ #
50
65
  # ==== Options
51
66
  #
52
67
  # * <tt>:locale</tt> - Sets the locale to be used for formatting
@@ -70,18 +85,18 @@ module ActiveSupport
70
85
  #
71
86
  # ==== Examples
72
87
  #
73
- # number_to_currency(1234567890.50) # => $1,234,567,890.50
74
- # number_to_currency(1234567890.506) # => $1,234,567,890.51
75
- # number_to_currency(1234567890.506, precision: 3) # => $1,234,567,890.506
76
- # number_to_currency(1234567890.506, locale: :fr) # => 1 234 567 890,51 €
77
- # number_to_currency('123a456') # => $123a456
88
+ # number_to_currency(1234567890.50) # => "$1,234,567,890.50"
89
+ # number_to_currency(1234567890.506) # => "$1,234,567,890.51"
90
+ # number_to_currency(1234567890.506, precision: 3) # => "$1,234,567,890.506"
91
+ # number_to_currency(1234567890.506, locale: :fr) # => "1 234 567 890,51 €"
92
+ # number_to_currency('123a456') # => "$123a456"
78
93
  #
79
94
  # number_to_currency(-1234567890.50, negative_format: '(%u%n)')
80
- # # => ($1,234,567,890.50)
95
+ # # => "($1,234,567,890.50)"
81
96
  # number_to_currency(1234567890.50, unit: '&pound;', separator: ',', delimiter: '')
82
- # # => &pound;1234567890,50
97
+ # # => "&pound;1234567890,50"
83
98
  # number_to_currency(1234567890.50, unit: '&pound;', separator: ',', delimiter: '', format: '%n %u')
84
- # # => 1234567890,50 &pound;
99
+ # # => "1234567890,50 &pound;"
85
100
  def number_to_currency(number, options = {})
86
101
  NumberToCurrencyConverter.convert(number, options)
87
102
  end
@@ -94,9 +109,9 @@ module ActiveSupport
94
109
  # * <tt>:locale</tt> - Sets the locale to be used for formatting
95
110
  # (defaults to current locale).
96
111
  # * <tt>:precision</tt> - Sets the precision of the number
97
- # (defaults to 3).
98
- # * <tt>:significant</tt> - If +true+, precision will be the #
99
- # of significant_digits. If +false+, the # of fractional
112
+ # (defaults to 3). Keeps the number's precision if nil.
113
+ # * <tt>:significant</tt> - If +true+, precision will be the number
114
+ # of significant_digits. If +false+, the number of fractional
100
115
  # digits (defaults to +false+).
101
116
  # * <tt>:separator</tt> - Sets the separator between the
102
117
  # fractional and integer digits (defaults to ".").
@@ -110,14 +125,15 @@ module ActiveSupport
110
125
  #
111
126
  # ==== Examples
112
127
  #
113
- # number_to_percentage(100) # => 100.000%
114
- # number_to_percentage('98') # => 98.000%
115
- # number_to_percentage(100, precision: 0) # => 100%
116
- # number_to_percentage(1000, delimiter: '.', separator: ',') # => 1.000,000%
117
- # number_to_percentage(302.24398923423, precision: 5) # => 302.24399%
118
- # number_to_percentage(1000, locale: :fr) # => 1 000,000%
119
- # number_to_percentage('98a') # => 98a%
120
- # number_to_percentage(100, format: '%n %') # => 100 %
128
+ # number_to_percentage(100) # => "100.000%"
129
+ # number_to_percentage('98') # => "98.000%"
130
+ # number_to_percentage(100, precision: 0) # => "100%"
131
+ # number_to_percentage(1000, delimiter: '.', separator: ',') # => "1.000,000%"
132
+ # number_to_percentage(302.24398923423, precision: 5) # => "302.24399%"
133
+ # number_to_percentage(1000, locale: :fr) # => "1000,000%"
134
+ # number_to_percentage(1000, precision: nil) # => "1000%"
135
+ # number_to_percentage('98a') # => "98a%"
136
+ # number_to_percentage(100, format: '%n %') # => "100.000 %"
121
137
  def number_to_percentage(number, options = {})
122
138
  NumberToPercentageConverter.convert(number, options)
123
139
  end
@@ -134,19 +150,25 @@ module ActiveSupport
134
150
  # to ",").
135
151
  # * <tt>:separator</tt> - Sets the separator between the
136
152
  # fractional and integer digits (defaults to ".").
153
+ # * <tt>:delimiter_pattern</tt> - Sets a custom regular expression used for
154
+ # deriving the placement of delimiter. Helpful when using currency formats
155
+ # like INR.
137
156
  #
138
157
  # ==== Examples
139
158
  #
140
- # number_to_delimited(12345678) # => 12,345,678
141
- # number_to_delimited('123456') # => 123,456
142
- # number_to_delimited(12345678.05) # => 12,345,678.05
143
- # number_to_delimited(12345678, delimiter: '.') # => 12.345.678
144
- # number_to_delimited(12345678, delimiter: ',') # => 12,345,678
145
- # number_to_delimited(12345678.05, separator: ' ') # => 12,345,678 05
146
- # number_to_delimited(12345678.05, locale: :fr) # => 12 345 678,05
147
- # number_to_delimited('112a') # => 112a
159
+ # number_to_delimited(12345678) # => "12,345,678"
160
+ # number_to_delimited('123456') # => "123,456"
161
+ # number_to_delimited(12345678.05) # => "12,345,678.05"
162
+ # number_to_delimited(12345678, delimiter: '.') # => "12.345.678"
163
+ # number_to_delimited(12345678, delimiter: ',') # => "12,345,678"
164
+ # number_to_delimited(12345678.05, separator: ' ') # => "12,345,678 05"
165
+ # number_to_delimited(12345678.05, locale: :fr) # => "12 345 678,05"
166
+ # number_to_delimited('112a') # => "112a"
148
167
  # number_to_delimited(98765432.98, delimiter: ' ', separator: ',')
149
- # # => 98 765 432,98
168
+ # # => "98 765 432,98"
169
+ # number_to_delimited("123456.78",
170
+ # delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/)
171
+ # # => "1,23,456.78"
150
172
  def number_to_delimited(number, options = {})
151
173
  NumberToDelimitedConverter.convert(number, options)
152
174
  end
@@ -161,9 +183,9 @@ module ActiveSupport
161
183
  # * <tt>:locale</tt> - Sets the locale to be used for formatting
162
184
  # (defaults to current locale).
163
185
  # * <tt>:precision</tt> - Sets the precision of the number
164
- # (defaults to 3).
165
- # * <tt>:significant</tt> - If +true+, precision will be the #
166
- # of significant_digits. If +false+, the # of fractional
186
+ # (defaults to 3). Keeps the number's precision if nil.
187
+ # * <tt>:significant</tt> - If +true+, precision will be the number
188
+ # of significant_digits. If +false+, the number of fractional
167
189
  # digits (defaults to +false+).
168
190
  # * <tt>:separator</tt> - Sets the separator between the
169
191
  # fractional and integer digits (defaults to ".").
@@ -175,21 +197,22 @@ module ActiveSupport
175
197
  #
176
198
  # ==== Examples
177
199
  #
178
- # number_to_rounded(111.2345) # => 111.235
179
- # number_to_rounded(111.2345, precision: 2) # => 111.23
180
- # number_to_rounded(13, precision: 5) # => 13.00000
181
- # number_to_rounded(389.32314, precision: 0) # => 389
182
- # number_to_rounded(111.2345, significant: true) # => 111
183
- # number_to_rounded(111.2345, precision: 1, significant: true) # => 100
184
- # number_to_rounded(13, precision: 5, significant: true) # => 13.000
185
- # number_to_rounded(111.234, locale: :fr) # => 111,234
200
+ # number_to_rounded(111.2345) # => "111.235"
201
+ # number_to_rounded(111.2345, precision: 2) # => "111.23"
202
+ # number_to_rounded(13, precision: 5) # => "13.00000"
203
+ # number_to_rounded(389.32314, precision: 0) # => "389"
204
+ # number_to_rounded(111.2345, significant: true) # => "111"
205
+ # number_to_rounded(111.2345, precision: 1, significant: true) # => "100"
206
+ # number_to_rounded(13, precision: 5, significant: true) # => "13.000"
207
+ # number_to_rounded(13, precision: nil) # => "13"
208
+ # number_to_rounded(111.234, locale: :fr) # => "111,234"
186
209
  #
187
210
  # number_to_rounded(13, precision: 5, significant: true, strip_insignificant_zeros: true)
188
- # # => 13
211
+ # # => "13"
189
212
  #
190
- # number_to_rounded(389.32314, precision: 4, significant: true) # => 389.3
213
+ # number_to_rounded(389.32314, precision: 4, significant: true) # => "389.3"
191
214
  # number_to_rounded(1111.2345, precision: 2, separator: ',', delimiter: '.')
192
- # # => 1.111,23
215
+ # # => "1.111,23"
193
216
  def number_to_rounded(number, options = {})
194
217
  NumberToRoundedConverter.convert(number, options)
195
218
  end
@@ -208,8 +231,8 @@ module ActiveSupport
208
231
  # (defaults to current locale).
209
232
  # * <tt>:precision</tt> - Sets the precision of the number
210
233
  # (defaults to 3).
211
- # * <tt>:significant</tt> - If +true+, precision will be the #
212
- # of significant_digits. If +false+, the # of fractional
234
+ # * <tt>:significant</tt> - If +true+, precision will be the number
235
+ # of significant_digits. If +false+, the number of fractional
213
236
  # digits (defaults to +true+)
214
237
  # * <tt>:separator</tt> - Sets the separator between the
215
238
  # fractional and integer digits (defaults to ".").
@@ -218,20 +241,20 @@ module ActiveSupport
218
241
  # * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
219
242
  # insignificant zeros after the decimal separator (defaults to
220
243
  # +true+)
221
- # * <tt>:prefix</tt> - If +:si+ formats the number using the SI
222
- # prefix (defaults to :binary)
223
244
  #
224
245
  # ==== Examples
225
246
  #
226
- # number_to_human_size(123) # => 123 Bytes
227
- # number_to_human_size(1234) # => 1.21 KB
228
- # number_to_human_size(12345) # => 12.1 KB
229
- # number_to_human_size(1234567) # => 1.18 MB
230
- # number_to_human_size(1234567890) # => 1.15 GB
231
- # number_to_human_size(1234567890123) # => 1.12 TB
232
- # number_to_human_size(1234567, precision: 2) # => 1.2 MB
233
- # number_to_human_size(483989, precision: 2) # => 470 KB
234
- # number_to_human_size(1234567, precision: 2, separator: ',') # => 1,2 MB
247
+ # number_to_human_size(123) # => "123 Bytes"
248
+ # number_to_human_size(1234) # => "1.21 KB"
249
+ # number_to_human_size(12345) # => "12.1 KB"
250
+ # number_to_human_size(1234567) # => "1.18 MB"
251
+ # number_to_human_size(1234567890) # => "1.15 GB"
252
+ # number_to_human_size(1234567890123) # => "1.12 TB"
253
+ # number_to_human_size(1234567890123456) # => "1.1 PB"
254
+ # number_to_human_size(1234567890123456789) # => "1.07 EB"
255
+ # number_to_human_size(1234567, precision: 2) # => "1.2 MB"
256
+ # number_to_human_size(483989, precision: 2) # => "470 KB"
257
+ # number_to_human_size(1234567, precision: 2, separator: ',') # => "1,2 MB"
235
258
  # number_to_human_size(1234567890123, precision: 5) # => "1.1228 TB"
236
259
  # number_to_human_size(524288000, precision: 5) # => "500 MB"
237
260
  def number_to_human_size(number, options = {})
@@ -258,8 +281,8 @@ module ActiveSupport
258
281
  # (defaults to current locale).
259
282
  # * <tt>:precision</tt> - Sets the precision of the number
260
283
  # (defaults to 3).
261
- # * <tt>:significant</tt> - If +true+, precision will be the #
262
- # of significant_digits. If +false+, the # of fractional
284
+ # * <tt>:significant</tt> - If +true+, precision will be the number
285
+ # of significant_digits. If +false+, the number of fractional
263
286
  # digits (defaults to +true+)
264
287
  # * <tt>:separator</tt> - Sets the separator between the
265
288
  # fractional and integer digits (defaults to ".").
@@ -5,7 +5,7 @@ YAML.add_builtin_type("omap") do |type, val|
5
5
  end
6
6
 
7
7
  module ActiveSupport
8
- # <tt>ActiveSupport::OrderedHash</tt> implements a hash that preserves
8
+ # DEPRECATED: <tt>ActiveSupport::OrderedHash</tt> implements a hash that preserves
9
9
  # insertion order.
10
10
  #
11
11
  # oh = ActiveSupport::OrderedHash.new
@@ -6,6 +6,7 @@ module ActiveSupport
6
6
  # h[:girl] = 'Mary'
7
7
  # h[:boy] # => 'John'
8
8
  # h[:girl] # => 'Mary'
9
+ # h[:dog] # => nil
9
10
  #
10
11
  # Using +OrderedOptions+, the above code could be reduced to:
11
12
  #
@@ -14,6 +15,13 @@ module ActiveSupport
14
15
  # h.girl = 'Mary'
15
16
  # h.boy # => 'John'
16
17
  # h.girl # => 'Mary'
18
+ # h.dog # => nil
19
+ #
20
+ # To raise an exception when the value is blank, append a
21
+ # bang to the key name, like:
22
+ #
23
+ # h.dog! # => raises KeyError: key not found: :dog
24
+ #
17
25
  class OrderedOptions < Hash
18
26
  alias_method :_get, :[] # preserve the original #[] method
19
27
  protected :_get # make it protected
@@ -31,7 +39,13 @@ module ActiveSupport
31
39
  if name_string.chomp!('=')
32
40
  self[name_string] = args.first
33
41
  else
34
- self[name]
42
+ bangs = name_string.chomp!('!')
43
+
44
+ if bangs
45
+ fetch(name_string.to_sym).presence || raise(KeyError.new("#{name_string} is blank."))
46
+ else
47
+ self[name_string]
48
+ end
35
49
  end
36
50
  end
37
51
 
@@ -1,4 +1,9 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+
1
3
  module ActiveSupport
4
+ # NOTE: This approach has been deprecated for end-user code in favor of thread_mattr_accessor and friends.
5
+ # Please use that approach instead.
6
+ #
2
7
  # This module is used to encapsulate access to thread local variables.
3
8
  #
4
9
  # Instead of polluting the thread locals namespace:
@@ -43,9 +48,9 @@ module ActiveSupport
43
48
  protected
44
49
  def method_missing(name, *args, &block) # :nodoc:
45
50
  # Caches the method definition as a singleton method of the receiver.
46
- define_singleton_method(name) do |*a, &b|
47
- instance.public_send(name, *a, &b)
48
- end
51
+ #
52
+ # By letting #delegate handle it, we avoid an enclosure that'll capture args.
53
+ singleton_class.delegate name, to: :instance
49
54
 
50
55
  send(name, *args, &block)
51
56
  end
@@ -1,8 +1,8 @@
1
1
  # This is private interface.
2
2
  #
3
3
  # Rails components cherry pick from Active Support as needed, but there are a
4
- # few features that are used for sure some way or another and it is not worth
5
- # to put individual requires absolutely everywhere. Think blank? for example.
4
+ # few features that are used for sure in some way or another and it is not worth
5
+ # putting individual requires absolutely everywhere. Think blank? for example.
6
6
  #
7
7
  # This file is loaded by every Rails component except Active Support itself,
8
8
  # but it does not belong to the Rails public interface. It is internal to
@@ -16,12 +16,17 @@ module ActiveSupport
16
16
  # Sets the default value for Time.zone
17
17
  # If assigned value cannot be matched to a TimeZone, an exception will be raised.
18
18
  initializer "active_support.initialize_time_zone" do |app|
19
+ begin
20
+ TZInfo::DataSource.get
21
+ rescue TZInfo::DataSourceNotFound => e
22
+ raise e.exception "tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install"
23
+ end
19
24
  require 'active_support/core_ext/time/zones'
20
25
  zone_default = Time.find_zone!(app.config.time_zone)
21
26
 
22
27
  unless zone_default
23
28
  raise 'Value assigned to config.time_zone not recognized. ' \
24
- 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
29
+ 'Run "rake time:zones:all" for a time zone names list.'
25
30
  end
26
31
 
27
32
  Time.zone_default = zone_default
@@ -0,0 +1,129 @@
1
+ require 'active_support/execution_wrapper'
2
+
3
+ module ActiveSupport
4
+ #--
5
+ # This class defines several callbacks:
6
+ #
7
+ # to_prepare -- Run once at application startup, and also from
8
+ # +to_run+.
9
+ #
10
+ # to_run -- Run before a work run that is reloading. If
11
+ # +reload_classes_only_on_change+ is true (the default), the class
12
+ # unload will have already occurred.
13
+ #
14
+ # to_complete -- Run after a work run that has reloaded. If
15
+ # +reload_classes_only_on_change+ is false, the class unload will
16
+ # have occurred after the work run, but before this callback.
17
+ #
18
+ # before_class_unload -- Run immediately before the classes are
19
+ # unloaded.
20
+ #
21
+ # after_class_unload -- Run immediately after the classes are
22
+ # unloaded.
23
+ #
24
+ class Reloader < ExecutionWrapper
25
+ define_callbacks :prepare
26
+
27
+ define_callbacks :class_unload
28
+
29
+ def self.to_prepare(*args, &block)
30
+ set_callback(:prepare, *args, &block)
31
+ end
32
+
33
+ def self.before_class_unload(*args, &block)
34
+ set_callback(:class_unload, *args, &block)
35
+ end
36
+
37
+ def self.after_class_unload(*args, &block)
38
+ set_callback(:class_unload, :after, *args, &block)
39
+ end
40
+
41
+ to_run(:after) { self.class.prepare! }
42
+
43
+ # Initiate a manual reload
44
+ def self.reload!
45
+ executor.wrap do
46
+ new.tap do |instance|
47
+ begin
48
+ instance.run!
49
+ ensure
50
+ instance.complete!
51
+ end
52
+ end
53
+ end
54
+ prepare!
55
+ end
56
+
57
+ def self.run! # :nodoc:
58
+ if check!
59
+ super
60
+ else
61
+ Null
62
+ end
63
+ end
64
+
65
+ # Run the supplied block as a work unit, reloading code as needed
66
+ def self.wrap
67
+ executor.wrap do
68
+ super
69
+ end
70
+ end
71
+
72
+ class_attribute :executor
73
+ class_attribute :check
74
+
75
+ self.executor = Executor
76
+ self.check = lambda { false }
77
+
78
+ def self.check! # :nodoc:
79
+ @should_reload ||= check.call
80
+ end
81
+
82
+ def self.reloaded! # :nodoc:
83
+ @should_reload = false
84
+ end
85
+
86
+ def self.prepare! # :nodoc:
87
+ new.run_callbacks(:prepare)
88
+ end
89
+
90
+ def initialize
91
+ super
92
+ @locked = false
93
+ end
94
+
95
+ # Acquire the ActiveSupport::Dependencies::Interlock unload lock,
96
+ # ensuring it will be released automatically
97
+ def require_unload_lock!
98
+ unless @locked
99
+ ActiveSupport::Dependencies.interlock.start_unloading
100
+ @locked = true
101
+ end
102
+ end
103
+
104
+ # Release the unload lock if it has been previously obtained
105
+ def release_unload_lock!
106
+ if @locked
107
+ @locked = false
108
+ ActiveSupport::Dependencies.interlock.done_unloading
109
+ end
110
+ end
111
+
112
+ def run! # :nodoc:
113
+ super
114
+ release_unload_lock!
115
+ end
116
+
117
+ def class_unload!(&block) # :nodoc:
118
+ require_unload_lock!
119
+ run_callbacks(:class_unload, &block)
120
+ end
121
+
122
+ def complete! # :nodoc:
123
+ super
124
+ self.class.reloaded!
125
+ ensure
126
+ release_unload_lock!
127
+ end
128
+ end
129
+ end