Sha256: 94fe0b35ed51470fd94c87284042b25e948930dc2b8af986d9f9c66753c24f14
Contents?: true
Size: 1.68 KB
Versions: 3
Compression:
Stored size: 1.68 KB
Contents
# frozen_string_literal: true String.class_eval do # @deprecated Use {String#utf8_encode!} instead # Remove all non-UTF-8 chars from a string. # # @param replace_with [String, nil] What to replace invalid chars with. # # @return [String] # def clean!(replace_with = '') utf8_encode_dep_warn('clean!') replace(encode('UTF-8', invalid: :replace, undef: :replace, replace: replace_with)) end # @deprecated Use {String#utf8_encode} instead # @see {#clean!} def clean(replace_with = '') utf8_encode_dep_warn('clean') dup.clean!(replace_with) end # @deprecated Use {String#utf8_encode!} instead # Remove all non-UTF-8 chars from a string and convert to binary. # # @param replace_with [String, nil] What to replace invalid chars with. # # @return [String] # def clean_binary!(replace_with = '') utf8_encode_dep_warn('clean_binary!') replace(encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: replace_with)) end # @deprecated Use {String#utf8_encode} instead # @see {#clean_binary!} def clean_binary(replace_with = '') utf8_encode_dep_warn('clean_binary!') dup.clean_binary!(replace_with) end private # Triggers a deprecation warning # # @param method_name [String] # @param projected_version [String] Projected version methods will # be removed / no longer supported. # # @return [void] # def utf8_encode_dep_warn(method_name, projected_version = '3.0') dep = ActiveSupport::Deprecation.new(projected_version, 'ruby-rails-extensions') dep.warn("#{method_name} is deprecated and will be removed from ruby-rails-extensions #{projected_version}") end end
Version data entries
3 entries across 3 versions & 1 rubygems