Module: ActiveSupport::DeprecatedRangeWithFormat

Included in:
Range
Defined in:
lib/active_support/core_ext/range/deprecated_conversions.rb

Overview

:nodoc:

Constant Summary collapse

NOT_SET =

:nodoc:

Object.new

Instance Method Summary collapse

Instance Method Details

#to_s(format = NOT_SET) ⇒ Object Also known as: to_default_s



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_support/core_ext/range/deprecated_conversions.rb', line 6

def to_s(format = NOT_SET)
  if formatter = RangeWithFormat::RANGE_FORMATS[format]
    ActiveSupport::Deprecation.warn(
      "Range#to_s(#{format.inspect}) is deprecated. Please use Range#to_fs(#{format.inspect}) instead."
    )
    formatter.call(first, last)
  elsif format == NOT_SET
    if formatter = RangeWithFormat::RANGE_FORMATS[:default]
      ActiveSupport::Deprecation.warn(<<-MSG.squish)
        Using a :default format for Range#to_s is deprecated. Please use Range#to_fs instead. If you fixed all
        places inside your application that you see this deprecation, you can set
        `ENV['RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION']` to `"true"` in the `config/application.rb` file before
        the `Bundler.require` call to fix all the callers outside of your application.
      MSG
      formatter.call(first, last)
    else
      super()
    end
  else
    ActiveSupport::Deprecation.warn(
      "Range#to_s(#{format.inspect}) is deprecated. Please use Range#to_fs(#{format.inspect}) instead."
    )
    super()
  end
end