ruby-rails-extensions 2.4.0 → 3.0.0.rc.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/lib/ruby-rails-extensions/extensions/all_keys.rb +1 -1
  4. data/lib/ruby-rails-extensions/extensions/all_values.rb +1 -1
  5. data/lib/ruby-rails-extensions/extensions/any_key.rb +1 -1
  6. data/lib/ruby-rails-extensions/extensions/any_value.rb +1 -1
  7. data/lib/ruby-rails-extensions/extensions/compact_blank_join.rb +1 -1
  8. data/lib/ruby-rails-extensions/extensions/compact_map.rb +2 -2
  9. data/lib/ruby-rails-extensions/extensions/current_day.rb +1 -1
  10. data/lib/ruby-rails-extensions/extensions/current_month.rb +2 -2
  11. data/lib/ruby-rails-extensions/extensions/current_week.rb +2 -2
  12. data/lib/ruby-rails-extensions/extensions/cutoff.rb +1 -1
  13. data/lib/ruby-rails-extensions/extensions/day_of_week.rb +2 -2
  14. data/lib/ruby-rails-extensions/extensions/display_military.rb +2 -2
  15. data/lib/ruby-rails-extensions/extensions/display_user.rb +4 -4
  16. data/lib/ruby-rails-extensions/extensions/find_bang.rb +2 -2
  17. data/lib/ruby-rails-extensions/extensions/find_dupes.rb +1 -1
  18. data/lib/ruby-rails-extensions/extensions/first_dupe.rb +2 -2
  19. data/lib/ruby-rails-extensions/extensions/flatten_compact.rb +2 -2
  20. data/lib/ruby-rails-extensions/extensions/google_format.rb +1 -1
  21. data/lib/ruby-rails-extensions/extensions/hash_only.rb +1 -1
  22. data/lib/ruby-rails-extensions/extensions/humanize_symbol.rb +1 -1
  23. data/lib/ruby-rails-extensions/extensions/in_utc.rb +3 -3
  24. data/lib/ruby-rails-extensions/extensions/input.rb +2 -2
  25. data/lib/ruby-rails-extensions/extensions/invert_with_dups.rb +1 -1
  26. data/lib/ruby-rails-extensions/extensions/left_deep_merge.rb +1 -1
  27. data/lib/ruby-rails-extensions/extensions/month_and_year.rb +1 -1
  28. data/lib/ruby-rails-extensions/extensions/month_year.rb +1 -1
  29. data/lib/ruby-rails-extensions/extensions/nmerge.rb +1 -1
  30. data/lib/ruby-rails-extensions/extensions/no_keys.rb +1 -1
  31. data/lib/ruby-rails-extensions/extensions/no_values.rb +1 -1
  32. data/lib/ruby-rails-extensions/extensions/only_some.rb +1 -1
  33. data/lib/ruby-rails-extensions/extensions/overlaps.rb +2 -2
  34. data/lib/ruby-rails-extensions/extensions/pipe.rb +2 -2
  35. data/lib/ruby-rails-extensions/extensions/presence_bang.rb +1 -1
  36. data/lib/ruby-rails-extensions/extensions/quarter_dates.rb +1 -1
  37. data/lib/ruby-rails-extensions/extensions/quarter_str.rb +6 -4
  38. data/lib/ruby-rails-extensions/extensions/range_add.rb +1 -1
  39. data/lib/ruby-rails-extensions/extensions/range_comparisons.rb +1 -1
  40. data/lib/ruby-rails-extensions/extensions/range_multiply.rb +1 -1
  41. data/lib/ruby-rails-extensions/extensions/range_round.rb +1 -1
  42. data/lib/ruby-rails-extensions/extensions/remove_reserved_keywords.rb +21 -19
  43. data/lib/ruby-rails-extensions/extensions/safe_parse.rb +2 -15
  44. data/lib/ruby-rails-extensions/extensions/select_present.rb +1 -1
  45. data/lib/ruby-rails-extensions/extensions/select_present_join.rb +1 -1
  46. data/lib/ruby-rails-extensions/extensions/set_to_sentence.rb +1 -1
  47. data/lib/ruby-rails-extensions/extensions/to_bool.rb +5 -5
  48. data/lib/ruby-rails-extensions/extensions/to_d.rb +2 -2
  49. data/lib/ruby-rails-extensions/extensions/to_dec.rb +3 -3
  50. data/lib/ruby-rails-extensions/extensions/to_delimited.rb +4 -4
  51. data/lib/ruby-rails-extensions/extensions/to_i.rb +2 -2
  52. data/lib/ruby-rails-extensions/extensions/to_local.rb +2 -2
  53. data/lib/ruby-rails-extensions/extensions/to_money.rb +2 -2
  54. data/lib/ruby-rails-extensions/extensions/to_negative_i.rb +3 -3
  55. data/lib/ruby-rails-extensions/extensions/to_new_date.rb +1 -1
  56. data/lib/ruby-rails-extensions/extensions/to_new_time.rb +1 -1
  57. data/lib/ruby-rails-extensions/extensions/to_nonzero_i.rb +3 -3
  58. data/lib/ruby-rails-extensions/extensions/to_or_sentence.rb +2 -2
  59. data/lib/ruby-rails-extensions/extensions/to_percentage.rb +2 -2
  60. data/lib/ruby-rails-extensions/extensions/to_positive_i.rb +3 -3
  61. data/lib/ruby-rails-extensions/extensions/to_sort_i.rb +3 -3
  62. data/lib/ruby-rails-extensions/extensions/to_x.rb +3 -3
  63. data/lib/ruby-rails-extensions/extensions/todays_date.rb +1 -1
  64. data/lib/ruby-rails-extensions/extensions/uniq_map.rb +1 -1
  65. data/lib/ruby-rails-extensions/extensions/usd_to_f.rb +3 -3
  66. data/lib/ruby-rails-extensions/extensions/usd_to_i.rb +2 -2
  67. data/lib/ruby-rails-extensions/extensions/utf8_encode.rb +1 -1
  68. data/lib/ruby-rails-extensions/extensions/weighted_sum.rb +1 -1
  69. data/lib/ruby-rails-extensions/extensions/yesno.rb +3 -3
  70. data/lib/ruby-rails-extensions/extensions/zero_range.rb +1 -1
  71. data/lib/ruby-rails-extensions/version.rb +3 -3
  72. data/lib/ruby-rails-extensions.rb +0 -2
  73. metadata +2 -4
  74. data/lib/ruby-rails-extensions/extensions/assign_nil.rb +0 -70
  75. data/lib/ruby-rails-extensions/extensions/clean_string.rb +0 -61
@@ -2,35 +2,35 @@
2
2
 
3
3
  require 'forwardable'
4
4
 
5
- TrueClass.class_eval do
5
+ class TrueClass
6
6
  # :nodoc:
7
7
  def to_bool
8
8
  true
9
9
  end
10
10
  end
11
11
 
12
- FalseClass.class_eval do
12
+ class FalseClass
13
13
  # :nodoc:
14
14
  def to_bool
15
15
  false
16
16
  end
17
17
  end
18
18
 
19
- NilClass.class_eval do
19
+ class NilClass
20
20
  # :nodoc:
21
21
  def to_bool
22
22
  false
23
23
  end
24
24
  end
25
25
 
26
- String.class_eval do
26
+ class String
27
27
  # :nodoc:
28
28
  def to_bool
29
29
  match?(/^(true|1|t|y|yes)$/i)
30
30
  end
31
31
  end
32
32
 
33
- Numeric.class_eval do
33
+ class Numeric
34
34
  extend Forwardable
35
35
 
36
36
  def_delegators :to_s, :to_bool
@@ -2,14 +2,14 @@
2
2
 
3
3
  require 'bigdecimal'
4
4
 
5
- FalseClass.class_eval do
5
+ class FalseClass
6
6
  # @return [BigDecimal]
7
7
  def to_d
8
8
  BigDecimal('0')
9
9
  end
10
10
  end
11
11
 
12
- TrueClass.class_eval do
12
+ class TrueClass
13
13
  # @return [BigDecimal]
14
14
  def to_d
15
15
  BigDecimal('1')
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- NilClass.class_eval do
3
+ class NilClass
4
4
  # :nodoc:
5
5
  def to_dec(*_args)
6
6
  nil
7
7
  end
8
8
  end
9
9
 
10
- Numeric.class_eval do
10
+ class Numeric
11
11
  # :nodoc:
12
12
  def to_dec(p = 4)
13
13
  (to_f / 100.0).round(p)
14
14
  end
15
15
  end
16
16
 
17
- String.class_eval do
17
+ class String
18
18
  # :nodoc:
19
19
  def to_dec(p = 4)
20
20
  (to_f / 100.0).round(p)
@@ -6,7 +6,7 @@ require 'active_support/number_helper'
6
6
  require 'bigdecimal'
7
7
  require 'forwardable'
8
8
 
9
- String.class_eval do
9
+ class String
10
10
  include ActiveSupport::NumberHelper
11
11
 
12
12
  # Converts a number to a delimited number string
@@ -21,15 +21,15 @@ String.class_eval do
21
21
  end
22
22
 
23
23
  # Adding this alias to follow {ActionView::Helpers::NumberHelper#number_with_delimiter}
24
- alias_method :with_delimiter, :to_delimited
24
+ alias with_delimiter to_delimited
25
25
 
26
26
  # @deprecated This alias is only for Atlas and will be removed in future versions
27
- alias_method :with_sep, :to_delimited
27
+ alias with_sep to_delimited
28
28
 
29
29
  deprecate :with_sep, deprecator: ActiveSupport::Deprecation.new('3.0', 'ruby-rails-extensions')
30
30
  end
31
31
 
32
- Numeric.class_eval do
32
+ class Numeric
33
33
  extend Forwardable
34
34
 
35
35
  def_delegators :to_s, :to_delimited, :with_delimiter, :with_sep
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- TrueClass.class_eval do
3
+ class TrueClass
4
4
  # :nodoc:
5
5
  def to_i
6
6
  1
7
7
  end
8
8
  end
9
9
 
10
- FalseClass.class_eval do
10
+ class FalseClass
11
11
  # :nodoc:
12
12
  def to_i
13
13
  0
@@ -4,13 +4,13 @@
4
4
  if defined?(ActiveSupport::TimeWithZone)
5
5
  require 'forwardable'
6
6
 
7
- Time.class_eval do
7
+ class Time
8
8
  extend Forwardable
9
9
 
10
10
  def_delegators :to_datetime, :to_local
11
11
  end
12
12
 
13
- DateTime.class_eval do
13
+ class DateTime
14
14
  # Converts to an Eastern time zone
15
15
  #
16
16
  # @return [DateTime]
@@ -4,7 +4,7 @@ require 'active_support'
4
4
  require 'active_support/number_helper'
5
5
  require 'bigdecimal'
6
6
 
7
- Numeric.class_eval do
7
+ class Numeric
8
8
  include ActiveSupport::NumberHelper
9
9
 
10
10
  # Converts a number to a money string
@@ -19,7 +19,7 @@ Numeric.class_eval do
19
19
  end
20
20
  end
21
21
 
22
- String.class_eval do
22
+ class String
23
23
  # @see Numeric#to_money
24
24
  def to_money(...)
25
25
  to_d.to_money(...)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- String.class_eval do
3
+ class String
4
4
  # Calls `to_i` and returns the value if it is negative
5
5
  #
6
6
  # @return [Integer, Nil]
@@ -14,7 +14,7 @@ String.class_eval do
14
14
  end
15
15
  end
16
16
 
17
- Numeric.class_eval do
17
+ class Numeric
18
18
  # Calls `to_i` and returns the value if it is negative
19
19
  #
20
20
  # @return [Integer, Nil]
@@ -28,7 +28,7 @@ Numeric.class_eval do
28
28
  end
29
29
  end
30
30
 
31
- NilClass.class_eval do
31
+ class NilClass
32
32
  # Calls `to_i` and returns the value if it is negative
33
33
  #
34
34
  # @return [Nil]
@@ -144,6 +144,6 @@ module StringToNewDate
144
144
  end
145
145
  end
146
146
 
147
- String.class_eval do
147
+ class String
148
148
  include StringToNewDate
149
149
  end
@@ -105,6 +105,6 @@ module StringToNewTime
105
105
  end
106
106
  end
107
107
 
108
- String.class_eval do
108
+ class String
109
109
  include StringToNewTime
110
110
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- String.class_eval do
3
+ class String
4
4
  # Calls `to_i` and returns the value if it is nonzero
5
5
  #
6
6
  # @return [Integer, Nil]
@@ -14,7 +14,7 @@ String.class_eval do
14
14
  end
15
15
  end
16
16
 
17
- Numeric.class_eval do
17
+ class Numeric
18
18
  # Calls `to_i` and returns the value if it is nonzero
19
19
  #
20
20
  # @return [Integer, Nil]
@@ -28,7 +28,7 @@ Numeric.class_eval do
28
28
  end
29
29
  end
30
30
 
31
- NilClass.class_eval do
31
+ class NilClass
32
32
  # Calls `to_i` and returns the value if it is nonzero
33
33
  #
34
34
  # @return [Integer, Nil]
@@ -3,14 +3,14 @@
3
3
  require 'forwardable'
4
4
  require 'set'
5
5
 
6
- Array.class_eval do
6
+ class Array
7
7
  # @return [String]
8
8
  def to_or_sentence
9
9
  to_sentence(two_words_connector: ' or ', last_word_connector: ', or ')
10
10
  end
11
11
  end
12
12
 
13
- Set.class_eval do
13
+ class Set
14
14
  extend Forwardable
15
15
 
16
16
  def_delegators :to_a, :to_or_sentence
@@ -4,7 +4,7 @@ require 'active_support'
4
4
  require 'active_support/number_helper'
5
5
  require 'bigdecimal'
6
6
 
7
- Numeric.class_eval do
7
+ class Numeric
8
8
  # Converts an {#Integer}, {#Float}, or {#BigDecimal} into a percentage string.
9
9
  # @see ActiveSupport::NumberHelper#number_to_percentage
10
10
  #
@@ -20,5 +20,5 @@ Numeric.class_eval do
20
20
  "#{(to_f * 100).round(options.fetch(:precision, 2))}%"
21
21
  end
22
22
 
23
- alias_method :to_per, :to_percentage
23
+ alias to_per to_percentage
24
24
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- String.class_eval do
3
+ class String
4
4
  # Calls `to_i` and returns the value if it is positive
5
5
  #
6
6
  # @return [Integer, Nil]
@@ -14,7 +14,7 @@ String.class_eval do
14
14
  end
15
15
  end
16
16
 
17
- Numeric.class_eval do
17
+ class Numeric
18
18
  # Calls `to_i` and returns the value if it is positive
19
19
  #
20
20
  # @return [Integer, Nil]
@@ -28,7 +28,7 @@ Numeric.class_eval do
28
28
  end
29
29
  end
30
30
 
31
- NilClass.class_eval do
31
+ class NilClass
32
32
  # Calls `to_i` and returns the value if it is positive
33
33
  #
34
34
  # @return [Integer, Nil]
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- TrueClass.class_eval do
3
+ class TrueClass
4
4
  # @see `to_i`
5
5
  def to_sort_i
6
6
  to_i
7
7
  end
8
8
  end
9
9
 
10
- FalseClass.class_eval do
10
+ class FalseClass
11
11
  # @see `to_i`
12
12
  def to_sort_i
13
13
  to_i
14
14
  end
15
15
  end
16
16
 
17
- NilClass.class_eval do
17
+ class NilClass
18
18
  # :nodoc:
19
19
  def to_sort_i
20
20
  -1
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- TrueClass.class_eval do
3
+ class TrueClass
4
4
  # :nodoc:
5
5
  def to_x(*_args)
6
6
  'X'
7
7
  end
8
8
  end
9
9
 
10
- FalseClass.class_eval do
10
+ class FalseClass
11
11
  # :nodoc:
12
12
  def to_x(unless_true = '')
13
13
  unless_true
14
14
  end
15
15
  end
16
16
 
17
- NilClass.class_eval do
17
+ class NilClass
18
18
  # :nodoc:
19
19
  def to_x(unless_true = nil)
20
20
  unless_true
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Requires `ActiveSupport::TimeWithZone` and `Time#to_local`
4
- Date.class_eval do
4
+ class Date
5
5
  class << self
6
6
  # Returns today according to Eastern time
7
7
  #
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Array.class_eval do
3
+ class Array
4
4
  # Same as `my_array.map(&block).uniq`
5
5
  #
6
6
  # @return [Array, Enumerable]
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- NilClass.class_eval do
3
+ class NilClass
4
4
  # :nodoc:
5
5
  def usd_to_f
6
6
  nil
7
7
  end
8
8
  end
9
9
 
10
- Numeric.class_eval do
10
+ class Numeric
11
11
  # :nodoc:
12
12
  def usd_to_f
13
13
  to_f
14
14
  end
15
15
  end
16
16
 
17
- String.class_eval do
17
+ class String
18
18
  # :nodoc:
19
19
  def usd_to_f
20
20
  gsub(/[$,]/, '').to_f
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- NilClass.class_eval do
3
+ class NilClass
4
4
  # :nodoc:
5
5
  def usd_to_i
6
6
  nil
7
7
  end
8
8
  end
9
9
 
10
- String.class_eval do
10
+ class String
11
11
  # :nodoc:
12
12
  def usd_to_i
13
13
  gsub(/[$,]/, '').to_i
@@ -3,7 +3,7 @@
3
3
  require 'active_support'
4
4
  require 'active_support/deprecation'
5
5
 
6
- String.class_eval do
6
+ class String
7
7
  # Remove all non-UTF-8 chars from a string.
8
8
  #
9
9
  # @raise [Encoding::UndefinedConversionError] Failed to encode string
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Array.class_eval do
3
+ class Array
4
4
  # Sums the array with each element weighing 10 times as the next.
5
5
  # Expects `self` to be [Array<Numeric>]
6
6
  #
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- TrueClass.class_eval do
3
+ class TrueClass
4
4
  # :nodoc:
5
5
  def yesno
6
6
  'Yes'
7
7
  end
8
8
  end
9
9
 
10
- FalseClass.class_eval do
10
+ class FalseClass
11
11
  # :nodoc:
12
12
  def yesno
13
13
  'No'
14
14
  end
15
15
  end
16
16
 
17
- NilClass.class_eval do
17
+ class NilClass
18
18
  # :nodoc:
19
19
  def yesno
20
20
  'N/A'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Range.class_eval do
3
+ class Range
4
4
  # Checks if the whole range is zero.
5
5
  #
6
6
  # @raise [RubyRailsExtensions::Errors::NonNumericError]
@@ -2,12 +2,12 @@
2
2
 
3
3
  module RubyRailsExtensions
4
4
  module VERSION
5
- MAJOR = 2
6
- MINOR = 4
5
+ MAJOR = 3
6
+ MINOR = 0
7
7
  TINY = 0
8
8
 
9
9
  # Set PRE to nil unless it's a pre-release (beta, rc, etc.)
10
- PRE = nil
10
+ PRE = 'rc.pre.1'
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.').freeze
13
13
 
@@ -11,9 +11,7 @@ module RubyRailsExtensions
11
11
  all_values
12
12
  any_key
13
13
  any_value
14
- assign_nil
15
14
  boolean_scope
16
- clean_string
17
15
  compact_map
18
16
  compact_blank_join
19
17
  current_day
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-rails-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 3.0.0.rc.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brands Insurance
@@ -25,9 +25,7 @@ files:
25
25
  - lib/ruby-rails-extensions/extensions/all_values.rb
26
26
  - lib/ruby-rails-extensions/extensions/any_key.rb
27
27
  - lib/ruby-rails-extensions/extensions/any_value.rb
28
- - lib/ruby-rails-extensions/extensions/assign_nil.rb
29
28
  - lib/ruby-rails-extensions/extensions/boolean_scope.rb
30
- - lib/ruby-rails-extensions/extensions/clean_string.rb
31
29
  - lib/ruby-rails-extensions/extensions/compact_blank_join.rb
32
30
  - lib/ruby-rails-extensions/extensions/compact_map.rb
33
31
  - lib/ruby-rails-extensions/extensions/current_day.rb
@@ -109,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
107
  requirements:
110
108
  - - ">="
111
109
  - !ruby/object:Gem::Version
112
- version: 3.0.1
110
+ version: 3.3.0
113
111
  required_rubygems_version: !ruby/object:Gem::Requirement
114
112
  requirements:
115
113
  - - ">="
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/deprecation'
4
-
5
- # requires `ActiveModel::AttributeAssignment` and `Hash#stringify_keys`
6
- module ActiveModel
7
- module AttributeAssignment
8
- # @deprecated Will be removed in ruby-rails-extensions 3.0
9
- #
10
- # Allows you to set nil attributes by passing in a hash of attributes with
11
- # keys matching the attribute names.
12
- #
13
- # @raise [ActiveModel::ForbiddenAttributesError] If the passed hash responds to `permitted?` method
14
- # and the return value of this method is +false+.
15
- #
16
- # @example
17
- #
18
- # class Cat
19
- # include ActiveModel::AttributeAssignment
20
- # attr_accessor :name, :status
21
- # end
22
- #
23
- # cat = Cat.new
24
- # cat.assign_nil_attributes(name: "Gorby")
25
- # cat.name # => 'Gorby'
26
- # cat.status # => nil
27
- # cat.assign_nil_attributes(status: "yawning")
28
- # cat.name # => 'Gorby'
29
- # cat.status # => 'yawning'
30
- # cat.assign_nil_attributes(status: "sleeping")
31
- # cat.name # => 'Gorby'
32
- # cat.status # => 'yawning'
33
- #
34
- # @param new_attributes
35
- #
36
- # @return [void]
37
- #
38
- def assign_nil_attributes(new_attributes)
39
- ActiveSupport::Deprecation
40
- .new('3.0', 'ruby-rails-extensions')
41
- .warn('assign_nil_attributes is deprecated and will be removed from ruby-rails-extensions 3.0')
42
-
43
- unless new_attributes.respond_to?(:stringify_keys)
44
- raise(ArgumentError, 'When assigning attributes, you must pass a hash as an argument.')
45
- end
46
-
47
- return if new_attributes.empty?
48
-
49
- attributes = new_attributes.stringify_keys
50
-
51
- _assign_nil_attributes(sanitize_for_mass_assignment(attributes))
52
- end
53
-
54
- private
55
-
56
- # Assign any `nil` attribute
57
- #
58
- # @param attributes [Hash]
59
- #
60
- # @return [void]
61
- #
62
- def _assign_nil_attributes(attributes)
63
- attributes.each do |k, v|
64
- next unless v.nil?
65
-
66
- _assign_attribute(k, v)
67
- end
68
- end
69
- end
70
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- String.class_eval do
4
- # @deprecated Use {String#utf8_encode!} instead
5
- # Remove all non-UTF-8 chars from a string.
6
- #
7
- # @param replace_with [String, nil] What to replace invalid chars with.
8
- #
9
- # @return [String]
10
- #
11
- def clean!(replace_with = '')
12
- utf8_encode_dep_warn('clean!')
13
-
14
- replace(encode('UTF-8', invalid: :replace, undef: :replace, replace: replace_with))
15
- end
16
-
17
- # @deprecated Use {String#utf8_encode} instead
18
- # @see {#clean!}
19
- def clean(replace_with = '')
20
- utf8_encode_dep_warn('clean')
21
-
22
- dup.clean!(replace_with)
23
- end
24
-
25
- # @deprecated Use {String#utf8_encode!} instead
26
- # Remove all non-UTF-8 chars from a string and convert to binary.
27
- #
28
- # @param replace_with [String, nil] What to replace invalid chars with.
29
- #
30
- # @return [String]
31
- #
32
- def clean_binary!(replace_with = '')
33
- utf8_encode_dep_warn('clean_binary!')
34
-
35
- replace(encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: replace_with))
36
- end
37
-
38
- # @deprecated Use {String#utf8_encode} instead
39
- # @see {#clean_binary!}
40
- def clean_binary(replace_with = '')
41
- utf8_encode_dep_warn('clean_binary!')
42
-
43
- dup.clean_binary!(replace_with)
44
- end
45
-
46
- private
47
-
48
- # Triggers a deprecation warning
49
- #
50
- # @param method_name [String]
51
- # @param projected_version [String] Projected version methods will
52
- # be removed / no longer supported.
53
- #
54
- # @return [void]
55
- #
56
- def utf8_encode_dep_warn(method_name, projected_version = '3.0')
57
- dep = ActiveSupport::Deprecation.new(projected_version, 'ruby-rails-extensions')
58
-
59
- dep.warn("#{method_name} is deprecated and will be removed from ruby-rails-extensions #{projected_version}")
60
- end
61
- end