omg-activesupport 8.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (289) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +86 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +40 -0
  5. data/lib/active_support/actionable_error.rb +50 -0
  6. data/lib/active_support/all.rb +5 -0
  7. data/lib/active_support/array_inquirer.rb +50 -0
  8. data/lib/active_support/backtrace_cleaner.rb +163 -0
  9. data/lib/active_support/benchmark.rb +21 -0
  10. data/lib/active_support/benchmarkable.rb +53 -0
  11. data/lib/active_support/broadcast_logger.rb +251 -0
  12. data/lib/active_support/builder.rb +8 -0
  13. data/lib/active_support/cache/coder.rb +153 -0
  14. data/lib/active_support/cache/entry.rb +134 -0
  15. data/lib/active_support/cache/file_store.rb +244 -0
  16. data/lib/active_support/cache/mem_cache_store.rb +290 -0
  17. data/lib/active_support/cache/memory_store.rb +262 -0
  18. data/lib/active_support/cache/null_store.rb +62 -0
  19. data/lib/active_support/cache/redis_cache_store.rb +492 -0
  20. data/lib/active_support/cache/serializer_with_fallback.rb +152 -0
  21. data/lib/active_support/cache/strategy/local_cache.rb +201 -0
  22. data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
  23. data/lib/active_support/cache.rb +1104 -0
  24. data/lib/active_support/callbacks.rb +944 -0
  25. data/lib/active_support/class_attribute.rb +26 -0
  26. data/lib/active_support/code_generator.rb +79 -0
  27. data/lib/active_support/concern.rb +217 -0
  28. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +72 -0
  29. data/lib/active_support/concurrency/null_lock.rb +13 -0
  30. data/lib/active_support/concurrency/share_lock.rb +225 -0
  31. data/lib/active_support/configurable.rb +159 -0
  32. data/lib/active_support/configuration_file.rb +60 -0
  33. data/lib/active_support/core_ext/array/access.rb +100 -0
  34. data/lib/active_support/core_ext/array/conversions.rb +213 -0
  35. data/lib/active_support/core_ext/array/extract.rb +21 -0
  36. data/lib/active_support/core_ext/array/extract_options.rb +31 -0
  37. data/lib/active_support/core_ext/array/grouping.rb +109 -0
  38. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  39. data/lib/active_support/core_ext/array/wrap.rb +48 -0
  40. data/lib/active_support/core_ext/array.rb +9 -0
  41. data/lib/active_support/core_ext/benchmark.rb +13 -0
  42. data/lib/active_support/core_ext/big_decimal/conversions.rb +14 -0
  43. data/lib/active_support/core_ext/big_decimal.rb +3 -0
  44. data/lib/active_support/core_ext/class/attribute.rb +122 -0
  45. data/lib/active_support/core_ext/class/attribute_accessors.rb +6 -0
  46. data/lib/active_support/core_ext/class/subclasses.rb +24 -0
  47. data/lib/active_support/core_ext/class.rb +4 -0
  48. data/lib/active_support/core_ext/date/acts_like.rb +10 -0
  49. data/lib/active_support/core_ext/date/blank.rb +18 -0
  50. data/lib/active_support/core_ext/date/calculations.rb +161 -0
  51. data/lib/active_support/core_ext/date/conversions.rb +98 -0
  52. data/lib/active_support/core_ext/date/zones.rb +8 -0
  53. data/lib/active_support/core_ext/date.rb +7 -0
  54. data/lib/active_support/core_ext/date_and_time/calculations.rb +374 -0
  55. data/lib/active_support/core_ext/date_and_time/compatibility.rb +58 -0
  56. data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
  57. data/lib/active_support/core_ext/date_time/acts_like.rb +16 -0
  58. data/lib/active_support/core_ext/date_time/blank.rb +18 -0
  59. data/lib/active_support/core_ext/date_time/calculations.rb +215 -0
  60. data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
  61. data/lib/active_support/core_ext/date_time/conversions.rb +106 -0
  62. data/lib/active_support/core_ext/date_time.rb +7 -0
  63. data/lib/active_support/core_ext/digest/uuid.rb +76 -0
  64. data/lib/active_support/core_ext/digest.rb +3 -0
  65. data/lib/active_support/core_ext/enumerable.rb +267 -0
  66. data/lib/active_support/core_ext/erb/util.rb +201 -0
  67. data/lib/active_support/core_ext/file/atomic.rb +72 -0
  68. data/lib/active_support/core_ext/file.rb +3 -0
  69. data/lib/active_support/core_ext/hash/conversions.rb +262 -0
  70. data/lib/active_support/core_ext/hash/deep_merge.rb +42 -0
  71. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  72. data/lib/active_support/core_ext/hash/except.rb +12 -0
  73. data/lib/active_support/core_ext/hash/indifferent_access.rb +24 -0
  74. data/lib/active_support/core_ext/hash/keys.rb +143 -0
  75. data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
  76. data/lib/active_support/core_ext/hash/slice.rb +27 -0
  77. data/lib/active_support/core_ext/hash.rb +10 -0
  78. data/lib/active_support/core_ext/integer/inflections.rb +31 -0
  79. data/lib/active_support/core_ext/integer/multiple.rb +12 -0
  80. data/lib/active_support/core_ext/integer/time.rb +22 -0
  81. data/lib/active_support/core_ext/integer.rb +5 -0
  82. data/lib/active_support/core_ext/kernel/concern.rb +14 -0
  83. data/lib/active_support/core_ext/kernel/reporting.rb +45 -0
  84. data/lib/active_support/core_ext/kernel/singleton_class.rb +8 -0
  85. data/lib/active_support/core_ext/kernel.rb +5 -0
  86. data/lib/active_support/core_ext/load_error.rb +9 -0
  87. data/lib/active_support/core_ext/module/aliasing.rb +31 -0
  88. data/lib/active_support/core_ext/module/anonymous.rb +30 -0
  89. data/lib/active_support/core_ext/module/attr_internal.rb +49 -0
  90. data/lib/active_support/core_ext/module/attribute_accessors.rb +214 -0
  91. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +175 -0
  92. data/lib/active_support/core_ext/module/concerning.rb +140 -0
  93. data/lib/active_support/core_ext/module/delegation.rb +225 -0
  94. data/lib/active_support/core_ext/module/deprecation.rb +25 -0
  95. data/lib/active_support/core_ext/module/introspection.rb +62 -0
  96. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  97. data/lib/active_support/core_ext/module/remove_method.rb +17 -0
  98. data/lib/active_support/core_ext/module.rb +13 -0
  99. data/lib/active_support/core_ext/name_error.rb +59 -0
  100. data/lib/active_support/core_ext/numeric/bytes.rb +75 -0
  101. data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
  102. data/lib/active_support/core_ext/numeric/time.rb +66 -0
  103. data/lib/active_support/core_ext/numeric.rb +5 -0
  104. data/lib/active_support/core_ext/object/acts_like.rb +45 -0
  105. data/lib/active_support/core_ext/object/blank.rb +199 -0
  106. data/lib/active_support/core_ext/object/conversions.rb +6 -0
  107. data/lib/active_support/core_ext/object/deep_dup.rb +71 -0
  108. data/lib/active_support/core_ext/object/duplicable.rb +69 -0
  109. data/lib/active_support/core_ext/object/inclusion.rb +37 -0
  110. data/lib/active_support/core_ext/object/instance_variables.rb +32 -0
  111. data/lib/active_support/core_ext/object/json.rb +260 -0
  112. data/lib/active_support/core_ext/object/to_param.rb +3 -0
  113. data/lib/active_support/core_ext/object/to_query.rb +87 -0
  114. data/lib/active_support/core_ext/object/try.rb +158 -0
  115. data/lib/active_support/core_ext/object/with.rb +46 -0
  116. data/lib/active_support/core_ext/object/with_options.rb +101 -0
  117. data/lib/active_support/core_ext/object.rb +17 -0
  118. data/lib/active_support/core_ext/pathname/blank.rb +20 -0
  119. data/lib/active_support/core_ext/pathname/existence.rb +23 -0
  120. data/lib/active_support/core_ext/pathname.rb +4 -0
  121. data/lib/active_support/core_ext/range/compare_range.rb +57 -0
  122. data/lib/active_support/core_ext/range/conversions.rb +62 -0
  123. data/lib/active_support/core_ext/range/each.rb +24 -0
  124. data/lib/active_support/core_ext/range/overlap.rb +40 -0
  125. data/lib/active_support/core_ext/range.rb +6 -0
  126. data/lib/active_support/core_ext/regexp.rb +14 -0
  127. data/lib/active_support/core_ext/securerandom.rb +41 -0
  128. data/lib/active_support/core_ext/string/access.rb +95 -0
  129. data/lib/active_support/core_ext/string/behavior.rb +8 -0
  130. data/lib/active_support/core_ext/string/conversions.rb +60 -0
  131. data/lib/active_support/core_ext/string/exclude.rb +13 -0
  132. data/lib/active_support/core_ext/string/filters.rb +151 -0
  133. data/lib/active_support/core_ext/string/indent.rb +45 -0
  134. data/lib/active_support/core_ext/string/inflections.rb +300 -0
  135. data/lib/active_support/core_ext/string/inquiry.rb +16 -0
  136. data/lib/active_support/core_ext/string/multibyte.rb +58 -0
  137. data/lib/active_support/core_ext/string/output_safety.rb +228 -0
  138. data/lib/active_support/core_ext/string/starts_ends_with.rb +6 -0
  139. data/lib/active_support/core_ext/string/strip.rb +27 -0
  140. data/lib/active_support/core_ext/string/zones.rb +16 -0
  141. data/lib/active_support/core_ext/string.rb +15 -0
  142. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
  143. data/lib/active_support/core_ext/symbol.rb +3 -0
  144. data/lib/active_support/core_ext/thread/backtrace/location.rb +12 -0
  145. data/lib/active_support/core_ext/time/acts_like.rb +10 -0
  146. data/lib/active_support/core_ext/time/calculations.rb +386 -0
  147. data/lib/active_support/core_ext/time/compatibility.rb +32 -0
  148. data/lib/active_support/core_ext/time/conversions.rb +75 -0
  149. data/lib/active_support/core_ext/time/zones.rb +97 -0
  150. data/lib/active_support/core_ext/time.rb +7 -0
  151. data/lib/active_support/core_ext.rb +5 -0
  152. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  153. data/lib/active_support/current_attributes.rb +233 -0
  154. data/lib/active_support/deep_mergeable.rb +53 -0
  155. data/lib/active_support/delegation.rb +202 -0
  156. data/lib/active_support/dependencies/autoload.rb +72 -0
  157. data/lib/active_support/dependencies/interlock.rb +49 -0
  158. data/lib/active_support/dependencies/require_dependency.rb +28 -0
  159. data/lib/active_support/dependencies.rb +98 -0
  160. data/lib/active_support/deprecation/behaviors.rb +148 -0
  161. data/lib/active_support/deprecation/constant_accessor.rb +74 -0
  162. data/lib/active_support/deprecation/deprecators.rb +104 -0
  163. data/lib/active_support/deprecation/disallowed.rb +54 -0
  164. data/lib/active_support/deprecation/method_wrappers.rb +68 -0
  165. data/lib/active_support/deprecation/proxy_wrappers.rb +189 -0
  166. data/lib/active_support/deprecation/reporting.rb +179 -0
  167. data/lib/active_support/deprecation.rb +81 -0
  168. data/lib/active_support/deprecator.rb +7 -0
  169. data/lib/active_support/descendants_tracker.rb +112 -0
  170. data/lib/active_support/digest.rb +22 -0
  171. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  172. data/lib/active_support/duration/iso8601_serializer.rb +64 -0
  173. data/lib/active_support/duration.rb +520 -0
  174. data/lib/active_support/encrypted_configuration.rb +126 -0
  175. data/lib/active_support/encrypted_file.rb +133 -0
  176. data/lib/active_support/environment_inquirer.rb +40 -0
  177. data/lib/active_support/error_reporter/test_helper.rb +15 -0
  178. data/lib/active_support/error_reporter.rb +265 -0
  179. data/lib/active_support/evented_file_update_checker.rb +182 -0
  180. data/lib/active_support/execution_context/test_helper.rb +13 -0
  181. data/lib/active_support/execution_context.rb +53 -0
  182. data/lib/active_support/execution_wrapper.rb +150 -0
  183. data/lib/active_support/executor/test_helper.rb +7 -0
  184. data/lib/active_support/executor.rb +8 -0
  185. data/lib/active_support/file_update_checker.rb +164 -0
  186. data/lib/active_support/fork_tracker.rb +43 -0
  187. data/lib/active_support/gem_version.rb +17 -0
  188. data/lib/active_support/gzip.rb +40 -0
  189. data/lib/active_support/hash_with_indifferent_access.rb +445 -0
  190. data/lib/active_support/html_safe_translation.rb +56 -0
  191. data/lib/active_support/i18n.rb +17 -0
  192. data/lib/active_support/i18n_railtie.rb +138 -0
  193. data/lib/active_support/inflections.rb +72 -0
  194. data/lib/active_support/inflector/inflections.rb +273 -0
  195. data/lib/active_support/inflector/methods.rb +387 -0
  196. data/lib/active_support/inflector/transliterate.rb +149 -0
  197. data/lib/active_support/inflector.rb +9 -0
  198. data/lib/active_support/isolated_execution_state.rb +75 -0
  199. data/lib/active_support/json/decoding.rb +76 -0
  200. data/lib/active_support/json/encoding.rb +120 -0
  201. data/lib/active_support/json.rb +4 -0
  202. data/lib/active_support/key_generator.rb +66 -0
  203. data/lib/active_support/lazy_load_hooks.rb +107 -0
  204. data/lib/active_support/locale/en.rb +33 -0
  205. data/lib/active_support/locale/en.yml +141 -0
  206. data/lib/active_support/log_subscriber/test_helper.rb +106 -0
  207. data/lib/active_support/log_subscriber.rb +192 -0
  208. data/lib/active_support/logger.rb +55 -0
  209. data/lib/active_support/logger_silence.rb +21 -0
  210. data/lib/active_support/logger_thread_safe_level.rb +47 -0
  211. data/lib/active_support/message_encryptor.rb +374 -0
  212. data/lib/active_support/message_encryptors.rb +141 -0
  213. data/lib/active_support/message_pack/cache_serializer.rb +23 -0
  214. data/lib/active_support/message_pack/extensions.rb +305 -0
  215. data/lib/active_support/message_pack/serializer.rb +63 -0
  216. data/lib/active_support/message_pack.rb +50 -0
  217. data/lib/active_support/message_verifier.rb +368 -0
  218. data/lib/active_support/message_verifiers.rb +135 -0
  219. data/lib/active_support/messages/codec.rb +65 -0
  220. data/lib/active_support/messages/metadata.rb +146 -0
  221. data/lib/active_support/messages/rotation_configuration.rb +23 -0
  222. data/lib/active_support/messages/rotation_coordinator.rb +93 -0
  223. data/lib/active_support/messages/rotator.rb +59 -0
  224. data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
  225. data/lib/active_support/multibyte/chars.rb +178 -0
  226. data/lib/active_support/multibyte/unicode.rb +42 -0
  227. data/lib/active_support/multibyte.rb +23 -0
  228. data/lib/active_support/notifications/fanout.rb +446 -0
  229. data/lib/active_support/notifications/instrumenter.rb +240 -0
  230. data/lib/active_support/notifications.rb +281 -0
  231. data/lib/active_support/number_helper/number_converter.rb +190 -0
  232. data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
  233. data/lib/active_support/number_helper/number_to_delimited_converter.rb +30 -0
  234. data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
  235. data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
  236. data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
  237. data/lib/active_support/number_helper/number_to_phone_converter.rb +60 -0
  238. data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
  239. data/lib/active_support/number_helper/rounding_helper.rb +46 -0
  240. data/lib/active_support/number_helper.rb +479 -0
  241. data/lib/active_support/option_merger.rb +38 -0
  242. data/lib/active_support/ordered_hash.rb +50 -0
  243. data/lib/active_support/ordered_options.rb +147 -0
  244. data/lib/active_support/parameter_filter.rb +157 -0
  245. data/lib/active_support/proxy_object.rb +20 -0
  246. data/lib/active_support/rails.rb +26 -0
  247. data/lib/active_support/railtie.rb +161 -0
  248. data/lib/active_support/reloader.rb +138 -0
  249. data/lib/active_support/rescuable.rb +176 -0
  250. data/lib/active_support/secure_compare_rotator.rb +58 -0
  251. data/lib/active_support/security_utils.rb +38 -0
  252. data/lib/active_support/string_inquirer.rb +35 -0
  253. data/lib/active_support/subscriber.rb +146 -0
  254. data/lib/active_support/syntax_error_proxy.rb +60 -0
  255. data/lib/active_support/tagged_logging.rb +152 -0
  256. data/lib/active_support/test_case.rb +304 -0
  257. data/lib/active_support/testing/assertions.rb +332 -0
  258. data/lib/active_support/testing/autorun.rb +5 -0
  259. data/lib/active_support/testing/constant_lookup.rb +51 -0
  260. data/lib/active_support/testing/constant_stubbing.rb +54 -0
  261. data/lib/active_support/testing/declarative.rb +28 -0
  262. data/lib/active_support/testing/deprecation.rb +82 -0
  263. data/lib/active_support/testing/error_reporter_assertions.rb +107 -0
  264. data/lib/active_support/testing/file_fixtures.rb +38 -0
  265. data/lib/active_support/testing/isolation.rb +121 -0
  266. data/lib/active_support/testing/method_call_assertions.rb +69 -0
  267. data/lib/active_support/testing/parallelization/server.rb +85 -0
  268. data/lib/active_support/testing/parallelization/worker.rb +103 -0
  269. data/lib/active_support/testing/parallelization.rb +55 -0
  270. data/lib/active_support/testing/parallelize_executor.rb +81 -0
  271. data/lib/active_support/testing/setup_and_teardown.rb +57 -0
  272. data/lib/active_support/testing/stream.rb +41 -0
  273. data/lib/active_support/testing/strict_warnings.rb +43 -0
  274. data/lib/active_support/testing/tagged_logging.rb +27 -0
  275. data/lib/active_support/testing/tests_without_assertions.rb +19 -0
  276. data/lib/active_support/testing/time_helpers.rb +269 -0
  277. data/lib/active_support/time.rb +20 -0
  278. data/lib/active_support/time_with_zone.rb +609 -0
  279. data/lib/active_support/values/time_zone.rb +614 -0
  280. data/lib/active_support/version.rb +10 -0
  281. data/lib/active_support/xml_mini/jdom.rb +175 -0
  282. data/lib/active_support/xml_mini/libxml.rb +80 -0
  283. data/lib/active_support/xml_mini/libxmlsax.rb +83 -0
  284. data/lib/active_support/xml_mini/nokogiri.rb +83 -0
  285. data/lib/active_support/xml_mini/nokogirisax.rb +86 -0
  286. data/lib/active_support/xml_mini/rexml.rb +137 -0
  287. data/lib/active_support/xml_mini.rb +211 -0
  288. data/lib/active_support.rb +144 -0
  289. metadata +526 -0
@@ -0,0 +1,300 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/inflector/methods"
4
+ require "active_support/inflector/transliterate"
5
+
6
+ # String inflections define new methods on the String class to transform names for different purposes.
7
+ # For instance, you can figure out the name of a table from the name of a class.
8
+ #
9
+ # 'ScaleScore'.tableize # => "scale_scores"
10
+ #
11
+ class String
12
+ # Returns the plural form of the word in the string.
13
+ #
14
+ # If the optional parameter +count+ is specified,
15
+ # the singular form will be returned if <tt>count == 1</tt>.
16
+ # For any other value of +count+ the plural will be returned.
17
+ #
18
+ # If the optional parameter +locale+ is specified,
19
+ # the word will be pluralized as a word of that language.
20
+ # By default, this parameter is set to <tt>:en</tt>.
21
+ # You must define your own inflection rules for languages other than English.
22
+ #
23
+ # 'post'.pluralize # => "posts"
24
+ # 'octopus'.pluralize # => "octopi"
25
+ # 'sheep'.pluralize # => "sheep"
26
+ # 'words'.pluralize # => "words"
27
+ # 'the blue mailman'.pluralize # => "the blue mailmen"
28
+ # 'CamelOctopus'.pluralize # => "CamelOctopi"
29
+ # 'apple'.pluralize(1) # => "apple"
30
+ # 'apple'.pluralize(2) # => "apples"
31
+ # 'ley'.pluralize(:es) # => "leyes"
32
+ # 'ley'.pluralize(1, :es) # => "ley"
33
+ #
34
+ # See ActiveSupport::Inflector.pluralize.
35
+ def pluralize(count = nil, locale = :en)
36
+ locale = count if count.is_a?(Symbol)
37
+ if count == 1
38
+ dup
39
+ else
40
+ ActiveSupport::Inflector.pluralize(self, locale)
41
+ end
42
+ end
43
+
44
+ # The reverse of +pluralize+, returns the singular form of a word in a string.
45
+ #
46
+ # If the optional parameter +locale+ is specified,
47
+ # the word will be singularized as a word of that language.
48
+ # By default, this parameter is set to <tt>:en</tt>.
49
+ # You must define your own inflection rules for languages other than English.
50
+ #
51
+ # 'posts'.singularize # => "post"
52
+ # 'octopi'.singularize # => "octopus"
53
+ # 'sheep'.singularize # => "sheep"
54
+ # 'word'.singularize # => "word"
55
+ # 'the blue mailmen'.singularize # => "the blue mailman"
56
+ # 'CamelOctopi'.singularize # => "CamelOctopus"
57
+ # 'leyes'.singularize(:es) # => "ley"
58
+ #
59
+ # See ActiveSupport::Inflector.singularize.
60
+ def singularize(locale = :en)
61
+ ActiveSupport::Inflector.singularize(self, locale)
62
+ end
63
+
64
+ # +constantize+ tries to find a declared constant with the name specified
65
+ # in the string. It raises a NameError when the name is not in CamelCase
66
+ # or is not initialized.
67
+ #
68
+ # 'Module'.constantize # => Module
69
+ # 'Class'.constantize # => Class
70
+ # 'blargle'.constantize # => NameError: wrong constant name blargle
71
+ #
72
+ # See ActiveSupport::Inflector.constantize.
73
+ def constantize
74
+ ActiveSupport::Inflector.constantize(self)
75
+ end
76
+
77
+ # +safe_constantize+ tries to find a declared constant with the name specified
78
+ # in the string. It returns +nil+ when the name is not in CamelCase
79
+ # or is not initialized.
80
+ #
81
+ # 'Module'.safe_constantize # => Module
82
+ # 'Class'.safe_constantize # => Class
83
+ # 'blargle'.safe_constantize # => nil
84
+ #
85
+ # See ActiveSupport::Inflector.safe_constantize.
86
+ def safe_constantize
87
+ ActiveSupport::Inflector.safe_constantize(self)
88
+ end
89
+
90
+ # By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize
91
+ # is set to <tt>:lower</tt> then camelize produces lowerCamelCase.
92
+ #
93
+ # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
94
+ #
95
+ # 'active_record'.camelize # => "ActiveRecord"
96
+ # 'active_record'.camelize(:lower) # => "activeRecord"
97
+ # 'active_record/errors'.camelize # => "ActiveRecord::Errors"
98
+ # 'active_record/errors'.camelize(:lower) # => "activeRecord::Errors"
99
+ #
100
+ # See ActiveSupport::Inflector.camelize.
101
+ def camelize(first_letter = :upper)
102
+ case first_letter
103
+ when :upper
104
+ ActiveSupport::Inflector.camelize(self, true)
105
+ when :lower
106
+ ActiveSupport::Inflector.camelize(self, false)
107
+ else
108
+ raise ArgumentError, "Invalid option, use either :upper or :lower."
109
+ end
110
+ end
111
+ alias_method :camelcase, :camelize
112
+
113
+ # Capitalizes all the words and replaces some characters in the string to create
114
+ # a nicer looking title. +titleize+ is meant for creating pretty output. It is not
115
+ # used in the \Rails internals.
116
+ #
117
+ # The trailing '_id','Id'.. can be kept and capitalized by setting the
118
+ # optional parameter +keep_id_suffix+ to true.
119
+ # By default, this parameter is false.
120
+ #
121
+ # 'man from the boondocks'.titleize # => "Man From The Boondocks"
122
+ # 'x-men: the last stand'.titleize # => "X Men: The Last Stand"
123
+ # 'string_ending_with_id'.titleize(keep_id_suffix: true) # => "String Ending With Id"
124
+ #
125
+ # See ActiveSupport::Inflector.titleize.
126
+ def titleize(keep_id_suffix: false)
127
+ ActiveSupport::Inflector.titleize(self, keep_id_suffix: keep_id_suffix)
128
+ end
129
+ alias_method :titlecase, :titleize
130
+
131
+ # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
132
+ #
133
+ # +underscore+ will also change '::' to '/' to convert namespaces to paths.
134
+ #
135
+ # 'ActiveModel'.underscore # => "active_model"
136
+ # 'ActiveModel::Errors'.underscore # => "active_model/errors"
137
+ #
138
+ # See ActiveSupport::Inflector.underscore.
139
+ def underscore
140
+ ActiveSupport::Inflector.underscore(self)
141
+ end
142
+
143
+ # Replaces underscores with dashes in the string.
144
+ #
145
+ # 'puni_puni'.dasherize # => "puni-puni"
146
+ #
147
+ # See ActiveSupport::Inflector.dasherize.
148
+ def dasherize
149
+ ActiveSupport::Inflector.dasherize(self)
150
+ end
151
+
152
+ # Removes the module part from the constant expression in the string.
153
+ #
154
+ # 'ActiveSupport::Inflector::Inflections'.demodulize # => "Inflections"
155
+ # 'Inflections'.demodulize # => "Inflections"
156
+ # '::Inflections'.demodulize # => "Inflections"
157
+ # ''.demodulize # => ''
158
+ #
159
+ # See ActiveSupport::Inflector.demodulize.
160
+ #
161
+ # See also +deconstantize+.
162
+ def demodulize
163
+ ActiveSupport::Inflector.demodulize(self)
164
+ end
165
+
166
+ # Removes the rightmost segment from the constant expression in the string.
167
+ #
168
+ # 'Net::HTTP'.deconstantize # => "Net"
169
+ # '::Net::HTTP'.deconstantize # => "::Net"
170
+ # 'String'.deconstantize # => ""
171
+ # '::String'.deconstantize # => ""
172
+ # ''.deconstantize # => ""
173
+ #
174
+ # See ActiveSupport::Inflector.deconstantize.
175
+ #
176
+ # See also +demodulize+.
177
+ def deconstantize
178
+ ActiveSupport::Inflector.deconstantize(self)
179
+ end
180
+
181
+ # Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
182
+ #
183
+ # If the optional parameter +locale+ is specified,
184
+ # the word will be parameterized as a word of that language.
185
+ # By default, this parameter is set to <tt>nil</tt> and it will use
186
+ # the configured <tt>I18n.locale</tt>.
187
+ #
188
+ # class Person
189
+ # def to_param
190
+ # "#{id}-#{name.parameterize}"
191
+ # end
192
+ # end
193
+ #
194
+ # @person = Person.find(1)
195
+ # # => #<Person id: 1, name: "Donald E. Knuth">
196
+ #
197
+ # <%= link_to(@person.name, person_path) %>
198
+ # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
199
+ #
200
+ # To preserve the case of the characters in a string, use the +preserve_case+ argument.
201
+ #
202
+ # class Person
203
+ # def to_param
204
+ # "#{id}-#{name.parameterize(preserve_case: true)}"
205
+ # end
206
+ # end
207
+ #
208
+ # @person = Person.find(1)
209
+ # # => #<Person id: 1, name: "Donald E. Knuth">
210
+ #
211
+ # <%= link_to(@person.name, person_path) %>
212
+ # # => <a href="/person/1-Donald-E-Knuth">Donald E. Knuth</a>
213
+ #
214
+ # See ActiveSupport::Inflector.parameterize.
215
+ def parameterize(separator: "-", preserve_case: false, locale: nil)
216
+ ActiveSupport::Inflector.parameterize(self, separator: separator, preserve_case: preserve_case, locale: locale)
217
+ end
218
+
219
+ # Creates the name of a table like \Rails does for models to table names. This method
220
+ # uses the +pluralize+ method on the last word in the string.
221
+ #
222
+ # 'RawScaledScorer'.tableize # => "raw_scaled_scorers"
223
+ # 'ham_and_egg'.tableize # => "ham_and_eggs"
224
+ # 'fancyCategory'.tableize # => "fancy_categories"
225
+ #
226
+ # See ActiveSupport::Inflector.tableize.
227
+ def tableize
228
+ ActiveSupport::Inflector.tableize(self)
229
+ end
230
+
231
+ # Creates a class name from a plural table name like \Rails does for table names to models.
232
+ # Note that this returns a string and not a class. (To convert to an actual class
233
+ # follow +classify+ with +constantize+.)
234
+ #
235
+ # 'ham_and_eggs'.classify # => "HamAndEgg"
236
+ # 'posts'.classify # => "Post"
237
+ #
238
+ # See ActiveSupport::Inflector.classify.
239
+ def classify
240
+ ActiveSupport::Inflector.classify(self)
241
+ end
242
+
243
+ # Capitalizes the first word, turns underscores into spaces, and (by default) strips a
244
+ # trailing '_id' if present.
245
+ # Like +titleize+, this is meant for creating pretty output.
246
+ #
247
+ # The capitalization of the first word can be turned off by setting the
248
+ # optional parameter +capitalize+ to false.
249
+ # By default, this parameter is true.
250
+ #
251
+ # The trailing '_id' can be kept and capitalized by setting the
252
+ # optional parameter +keep_id_suffix+ to true.
253
+ # By default, this parameter is false.
254
+ #
255
+ # 'employee_salary'.humanize # => "Employee salary"
256
+ # 'author_id'.humanize # => "Author"
257
+ # 'author_id'.humanize(capitalize: false) # => "author"
258
+ # '_id'.humanize # => "Id"
259
+ # 'author_id'.humanize(keep_id_suffix: true) # => "Author id"
260
+ #
261
+ # See ActiveSupport::Inflector.humanize.
262
+ def humanize(capitalize: true, keep_id_suffix: false)
263
+ ActiveSupport::Inflector.humanize(self, capitalize: capitalize, keep_id_suffix: keep_id_suffix)
264
+ end
265
+
266
+ # Converts the first character to uppercase.
267
+ #
268
+ # 'what a Lovely Day'.upcase_first # => "What a Lovely Day"
269
+ # 'w'.upcase_first # => "W"
270
+ # ''.upcase_first # => ""
271
+ #
272
+ # See ActiveSupport::Inflector.upcase_first.
273
+ def upcase_first
274
+ ActiveSupport::Inflector.upcase_first(self)
275
+ end
276
+
277
+ # Converts the first character to lowercase.
278
+ #
279
+ # 'If they enjoyed The Matrix'.downcase_first # => "if they enjoyed The Matrix"
280
+ # 'I'.downcase_first # => "i"
281
+ # ''.downcase_first # => ""
282
+ #
283
+ # See ActiveSupport::Inflector.downcase_first.
284
+ def downcase_first
285
+ ActiveSupport::Inflector.downcase_first(self)
286
+ end
287
+
288
+ # Creates a foreign key name from a class name.
289
+ # +separate_class_name_and_id_with_underscore+ sets whether
290
+ # the method should put '_' between the name and 'id'.
291
+ #
292
+ # 'Message'.foreign_key # => "message_id"
293
+ # 'Message'.foreign_key(false) # => "messageid"
294
+ # 'Admin::Post'.foreign_key # => "post_id"
295
+ #
296
+ # See ActiveSupport::Inflector.foreign_key.
297
+ def foreign_key(separate_class_name_and_id_with_underscore = true)
298
+ ActiveSupport::Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
299
+ end
300
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/string_inquirer"
4
+ require "active_support/environment_inquirer"
5
+
6
+ class String
7
+ # Wraps the current string in the ActiveSupport::StringInquirer class,
8
+ # which gives you a prettier way to test for equality.
9
+ #
10
+ # env = 'production'.inquiry
11
+ # env.production? # => true
12
+ # env.development? # => false
13
+ def inquiry
14
+ ActiveSupport::StringInquirer.new(self)
15
+ end
16
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/multibyte"
4
+
5
+ class String
6
+ # == Multibyte proxy
7
+ #
8
+ # +mb_chars+ is a multibyte safe proxy for string methods.
9
+ #
10
+ # It creates and returns an instance of the ActiveSupport::Multibyte::Chars class which
11
+ # encapsulates the original string. A Unicode safe version of all the String methods are defined on this proxy
12
+ # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsulated string.
13
+ #
14
+ # >> "lj".mb_chars.upcase.to_s
15
+ # => "LJ"
16
+ #
17
+ # NOTE: Ruby 2.4 and later support native Unicode case mappings:
18
+ #
19
+ # >> "lj".upcase
20
+ # => "LJ"
21
+ #
22
+ # == Method chaining
23
+ #
24
+ # All the methods on the Chars proxy which normally return a string will return a Chars object. This allows
25
+ # method chaining on the result of any of these methods.
26
+ #
27
+ # name.mb_chars.reverse.length # => 12
28
+ #
29
+ # == Interoperability and configuration
30
+ #
31
+ # The Chars object tries to be as interchangeable with String objects as possible: sorting and comparing between
32
+ # String and Char work like expected. The bang! methods change the internal string representation in the Chars
33
+ # object. Interoperability problems can be resolved easily with a +to_s+ call.
34
+ #
35
+ # For more information about the methods defined on the Chars proxy see ActiveSupport::Multibyte::Chars. For
36
+ # information about how to change the default Multibyte behavior see ActiveSupport::Multibyte.
37
+ def mb_chars
38
+ ActiveSupport::Multibyte.proxy_class.new(self)
39
+ end
40
+
41
+ # Returns +true+ if string has utf_8 encoding.
42
+ #
43
+ # utf_8_str = "some string".encode "UTF-8"
44
+ # iso_str = "some string".encode "ISO-8859-1"
45
+ #
46
+ # utf_8_str.is_utf8? # => true
47
+ # iso_str.is_utf8? # => false
48
+ def is_utf8?
49
+ case encoding
50
+ when Encoding::UTF_8, Encoding::US_ASCII
51
+ valid_encoding?
52
+ when Encoding::ASCII_8BIT
53
+ dup.force_encoding(Encoding::UTF_8).valid_encoding?
54
+ else
55
+ false
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,228 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/erb/util"
4
+ require "active_support/multibyte/unicode"
5
+
6
+ class Object
7
+ def html_safe?
8
+ false
9
+ end
10
+ end
11
+
12
+ class Numeric
13
+ def html_safe?
14
+ true
15
+ end
16
+ end
17
+
18
+ module ActiveSupport # :nodoc:
19
+ class SafeBuffer < String
20
+ UNSAFE_STRING_METHODS = %w(
21
+ capitalize chomp chop delete delete_prefix delete_suffix
22
+ downcase lstrip next reverse rstrip scrub squeeze strip
23
+ succ swapcase tr tr_s unicode_normalize upcase
24
+ )
25
+
26
+ UNSAFE_STRING_METHODS_WITH_BACKREF = %w(gsub sub)
27
+
28
+ alias_method :original_concat, :concat
29
+ private :original_concat
30
+
31
+ # Raised when ActiveSupport::SafeBuffer#safe_concat is called on unsafe buffers.
32
+ class SafeConcatError < StandardError
33
+ def initialize
34
+ super "Could not concatenate to the buffer because it is not HTML safe."
35
+ end
36
+ end
37
+
38
+ def [](*args)
39
+ if html_safe?
40
+ new_string = super
41
+
42
+ return unless new_string
43
+
44
+ string_into_safe_buffer(new_string, true)
45
+ else
46
+ to_str[*args]
47
+ end
48
+ end
49
+ alias_method :slice, :[]
50
+
51
+ def slice!(*args)
52
+ new_string = super
53
+
54
+ return new_string if !html_safe? || new_string.nil?
55
+
56
+ string_into_safe_buffer(new_string, true)
57
+ end
58
+
59
+ def chr
60
+ return super unless html_safe?
61
+
62
+ string_into_safe_buffer(super, true)
63
+ end
64
+
65
+ def safe_concat(value)
66
+ raise SafeConcatError unless html_safe?
67
+ original_concat(value)
68
+ end
69
+
70
+ def initialize(str = "")
71
+ @html_safe = true
72
+ super
73
+ end
74
+
75
+ def initialize_copy(other)
76
+ super
77
+ @html_safe = other.html_safe?
78
+ end
79
+
80
+ def concat(value)
81
+ unless value.nil?
82
+ super(implicit_html_escape_interpolated_argument(value))
83
+ end
84
+ self
85
+ end
86
+ alias << concat
87
+
88
+ def bytesplice(*args, value)
89
+ super(*args, implicit_html_escape_interpolated_argument(value))
90
+ end
91
+
92
+ def insert(index, value)
93
+ super(index, implicit_html_escape_interpolated_argument(value))
94
+ end
95
+
96
+ def prepend(value)
97
+ super(implicit_html_escape_interpolated_argument(value))
98
+ end
99
+
100
+ def replace(value)
101
+ super(implicit_html_escape_interpolated_argument(value))
102
+ end
103
+
104
+ def []=(arg1, arg2, arg3 = nil)
105
+ if arg3
106
+ super(arg1, arg2, implicit_html_escape_interpolated_argument(arg3))
107
+ else
108
+ super(arg1, implicit_html_escape_interpolated_argument(arg2))
109
+ end
110
+ end
111
+
112
+ def +(other)
113
+ dup.concat(other)
114
+ end
115
+
116
+ def *(_)
117
+ new_string = super
118
+ new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string)
119
+ new_safe_buffer.instance_variable_set(:@html_safe, @html_safe)
120
+ new_safe_buffer
121
+ end
122
+
123
+ def %(args)
124
+ case args
125
+ when Hash
126
+ escaped_args = args.transform_values { |arg| explicit_html_escape_interpolated_argument(arg) }
127
+ else
128
+ escaped_args = Array(args).map { |arg| explicit_html_escape_interpolated_argument(arg) }
129
+ end
130
+
131
+ self.class.new(super(escaped_args))
132
+ end
133
+
134
+ attr_reader :html_safe
135
+ alias_method :html_safe?, :html_safe
136
+ remove_method :html_safe
137
+
138
+ def to_s
139
+ self
140
+ end
141
+
142
+ def to_param
143
+ to_str
144
+ end
145
+
146
+ def encode_with(coder)
147
+ coder.represent_object nil, to_str
148
+ end
149
+
150
+ UNSAFE_STRING_METHODS.each do |unsafe_method|
151
+ if unsafe_method.respond_to?(unsafe_method)
152
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
153
+ def #{unsafe_method}(*args, &block) # def capitalize(*args, &block)
154
+ to_str.#{unsafe_method}(*args, &block) # to_str.capitalize(*args, &block)
155
+ end # end
156
+
157
+ def #{unsafe_method}!(*args) # def capitalize!(*args)
158
+ @html_safe = false # @html_safe = false
159
+ super # super
160
+ end # end
161
+ EOT
162
+ end
163
+ end
164
+
165
+ UNSAFE_STRING_METHODS_WITH_BACKREF.each do |unsafe_method|
166
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
167
+ def #{unsafe_method}(*args, &block) # def gsub(*args, &block)
168
+ if block # if block
169
+ to_str.#{unsafe_method}(*args) { |*params| # to_str.gsub(*args) { |*params|
170
+ set_block_back_references(block, $~) # set_block_back_references(block, $~)
171
+ block.call(*params) # block.call(*params)
172
+ } # }
173
+ else # else
174
+ to_str.#{unsafe_method}(*args) # to_str.gsub(*args)
175
+ end # end
176
+ end # end
177
+
178
+ def #{unsafe_method}!(*args, &block) # def gsub!(*args, &block)
179
+ @html_safe = false # @html_safe = false
180
+ if block # if block
181
+ super(*args) { |*params| # super(*args) { |*params|
182
+ set_block_back_references(block, $~) # set_block_back_references(block, $~)
183
+ block.call(*params) # block.call(*params)
184
+ } # }
185
+ else # else
186
+ super # super
187
+ end # end
188
+ end # end
189
+ EOT
190
+ end
191
+
192
+ private
193
+ def explicit_html_escape_interpolated_argument(arg)
194
+ (!html_safe? || arg.html_safe?) ? arg : CGI.escapeHTML(arg.to_s)
195
+ end
196
+
197
+ def implicit_html_escape_interpolated_argument(arg)
198
+ if !html_safe? || arg.html_safe?
199
+ arg
200
+ else
201
+ CGI.escapeHTML(arg.to_str)
202
+ end
203
+ end
204
+
205
+ def set_block_back_references(block, match_data)
206
+ block.binding.eval("proc { |m| $~ = m }").call(match_data)
207
+ rescue ArgumentError
208
+ # Can't create binding from C level Proc
209
+ end
210
+
211
+ def string_into_safe_buffer(new_string, is_html_safe)
212
+ new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string)
213
+ new_safe_buffer.instance_variable_set :@html_safe, is_html_safe
214
+ new_safe_buffer
215
+ end
216
+ end
217
+ end
218
+
219
+ class String
220
+ # Marks a string as trusted safe. It will be inserted into HTML with no
221
+ # additional escaping performed. It is your responsibility to ensure that the
222
+ # string contains no malicious content. This method is equivalent to the
223
+ # +raw+ helper in views. It is recommended that you use +sanitize+ instead of
224
+ # this method. It should never be called on user input.
225
+ def html_safe
226
+ ActiveSupport::SafeBuffer.new(self)
227
+ end
228
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ alias :starts_with? :start_with?
5
+ alias :ends_with? :end_with?
6
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ # Strips indentation in heredocs.
5
+ #
6
+ # For example in
7
+ #
8
+ # if options[:usage]
9
+ # puts <<-USAGE.strip_heredoc
10
+ # This command does such and such.
11
+ #
12
+ # Supported options are:
13
+ # -h This message
14
+ # ...
15
+ # USAGE
16
+ # end
17
+ #
18
+ # the user would see the usage message aligned against the left margin.
19
+ #
20
+ # Technically, it looks for the least indented non-empty line
21
+ # in the whole string, and removes that amount of leading whitespace.
22
+ def strip_heredoc
23
+ gsub(/^#{scan(/^[ \t]*(?=\S)/).min}/, "").tap do |stripped|
24
+ stripped.freeze if frozen?
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/string/conversions"
4
+ require "active_support/core_ext/time/zones"
5
+
6
+ class String
7
+ # Converts String to a TimeWithZone in the current zone if Time.zone or Time.zone_default
8
+ # is set, otherwise converts String to a Time via String#to_time
9
+ def in_time_zone(zone = ::Time.zone)
10
+ if zone
11
+ ::Time.find_zone!(zone).parse(self)
12
+ else
13
+ to_time
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/string/conversions"
4
+ require "active_support/core_ext/string/filters"
5
+ require "active_support/core_ext/string/multibyte"
6
+ require "active_support/core_ext/string/starts_ends_with"
7
+ require "active_support/core_ext/string/inflections"
8
+ require "active_support/core_ext/string/access"
9
+ require "active_support/core_ext/string/behavior"
10
+ require "active_support/core_ext/string/output_safety"
11
+ require "active_support/core_ext/string/exclude"
12
+ require "active_support/core_ext/string/strip"
13
+ require "active_support/core_ext/string/inquiry"
14
+ require "active_support/core_ext/string/indent"
15
+ require "active_support/core_ext/string/zones"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Symbol
4
+ alias :starts_with? :start_with?
5
+ alias :ends_with? :end_with?
6
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/symbol/starts_ends_with"