1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

let's warn with heredocs

The current style for warning messages without newlines uses
concatenation of string literals with manual trailing spaces
where needed.

Heredocs have better readability, and with `squish` we can still
produce a single line.

This is a similar use case to the one that motivated defining
`strip_heredoc`, heredocs are super clean.
This commit is contained in:
Xavier Noria 2014-10-28 16:17:33 -07:00
parent 777142d3a7
commit b3bfa361c5
18 changed files with 149 additions and 76 deletions

View file

@ -1,4 +1,5 @@
require 'delegate' require 'delegate'
require 'active_support/core_ext/string/filters'
module ActionMailer module ActionMailer
@ -85,14 +86,22 @@ module ActionMailer
end end
def deliver! #:nodoc: def deliver! #:nodoc:
ActiveSupport::Deprecation.warn "#deliver! is deprecated and will be removed in Rails 5. " \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"Use #deliver_now! to deliver immediately or #deliver_later! to deliver through Active Job." #deliver! is deprecated and will be removed in Rails 5. Use
#deliver_now! to deliver immediately or #deliver_later! to
deliver through Active Job.
MSG
deliver_now! deliver_now!
end end
def deliver #:nodoc: def deliver #:nodoc:
ActiveSupport::Deprecation.warn "#deliver is deprecated and will be removed in Rails 5. " \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"Use #deliver_now to deliver immediately or #deliver_later to deliver through Active Job." #deliver is deprecated and will be removed in Rails 5. Use
#deliver_now to deliver immediately or #deliver_later to
deliver through Active Job.
MSG
deliver_now deliver_now
end end

View file

@ -1,5 +1,6 @@
require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/string/filters'
require 'active_support/deprecation' require 'active_support/deprecation'
require 'active_support/rescuable' require 'active_support/rescuable'
require 'action_dispatch/http/upload' require 'action_dispatch/http/upload'
@ -114,10 +115,12 @@ module ActionController
def self.const_missing(const_name) def self.const_missing(const_name)
super unless const_name == :NEVER_UNPERMITTED_PARAMS super unless const_name == :NEVER_UNPERMITTED_PARAMS
ActiveSupport::Deprecation.warn "`ActionController::Parameters::NEVER_UNPERMITTED_PARAMS`"\ ActiveSupport::Deprecation.warn(<<-MSG.squish)
" has been deprecated. Use "\ `ActionController::Parameters::NEVER_UNPERMITTED_PARAMS` has been deprecated.
"`ActionController::Parameters.always_permitted_parameters` instead." Use `ActionController::Parameters.always_permitted_parameters` instead.
self.always_permitted_parameters MSG
always_permitted_parameters
end end
# Returns a new instance of <tt>ActionController::Parameters</tt>. # Returns a new instance of <tt>ActionController::Parameters</tt>.

View file

@ -1,4 +1,5 @@
require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/filters'
require 'active_support/deprecation' require 'active_support/deprecation'
require 'action_dispatch/http/filter_redirect' require 'action_dispatch/http/filter_redirect'
require 'monitor' require 'monitor'
@ -288,7 +289,12 @@ module ActionDispatch # :nodoc:
# as arrays work, and "flattening" responses, cascading to the rack body! # as arrays work, and "flattening" responses, cascading to the rack body!
# Not sensible behavior. # Not sensible behavior.
def to_ary def to_ary
ActiveSupport::Deprecation.warn 'ActionDispatch::Response#to_ary no longer performs implicit conversion to an Array. Please use response.to_a instead, or a splat like `status, headers, body = *response`' ActiveSupport::Deprecation.warn(<<-MSG.squish)
'ActionDispatch::Response#to_ary no longer performs implicit conversion
to an Array. Please use response.to_a instead, or a splat like `status,
headers, body = *response`
MSG
to_a to_a
end end

View file

@ -6,6 +6,7 @@ require 'active_support/core_ext/object/to_query'
require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/module/remove_method' require 'active_support/core_ext/module/remove_method'
require 'active_support/core_ext/array/extract_options' require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/string/filters'
require 'action_controller/metal/exceptions' require 'action_controller/metal/exceptions'
require 'action_dispatch/http/request' require 'action_dispatch/http/request'
require 'action_dispatch/routing/endpoint' require 'action_dispatch/routing/endpoint'
@ -325,20 +326,22 @@ module ActionDispatch
LEGACY = ->(options) { LEGACY = ->(options) {
if options.key?(:only_path) if options.key?(:only_path)
if options[:only_path] if options[:only_path]
ActiveSupport::Deprecation.warn \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"You are calling a `*_path` helper with the `only_path` option " \ You are calling a `*_path` helper with the `only_path` option
"explicitly set to `true`. This option will stop working on " \ explicitly set to `true`. This option will stop working on
"path helpers in Rails 5. Simply remove the `only_path: true` " \ path helpers in Rails 5. Simply remove the `only_path: true`
"argument from your call as it is redundant when applied to a " \ argument from your call as it is redundant when applied to a
"path helper." path helper.
MSG
PATH.call(options) PATH.call(options)
else else
ActiveSupport::Deprecation.warn \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"You are calling a `*_path` helper with the `only_path` option " \ You are calling a `*_path` helper with the `only_path` option
"explicitly set to `false`. This option will stop working on " \ explicitly set to `false`. This option will stop working on
"path helpers in Rails 5. Use the corresponding `*_url` helper " \ path helpers in Rails 5. Use the corresponding `*_url` helper
"instead." instead.
MSG
FULL.call(options) FULL.call(options)
end end

View file

@ -1,6 +1,7 @@
require "pathname" require "pathname"
require "active_support/core_ext/class" require "active_support/core_ext/class"
require "active_support/core_ext/module/attribute_accessors" require "active_support/core_ext/module/attribute_accessors"
require 'active_support/core_ext/string/filters'
require "action_view/template" require "action_view/template"
require "thread" require "thread"
require "thread_safe" require "thread_safe"
@ -251,9 +252,10 @@ module ActionView
extension = pieces.pop extension = pieces.pop
unless extension unless extension
message = "The file #{path} did not specify a template handler. The default is currently ERB, " \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"but will change to RAW in the future." The file #{path} did not specify a template handler. The default is
ActiveSupport::Deprecation.warn message currently ERB, but will change to RAW in the future.
MSG
end end
handler = Template.handler_for_extension(extension) handler = Template.handler_for_extension(extension)

View file

@ -1,3 +1,5 @@
require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
# = Active Record Has Many Through Association # = Active Record Has Many Through Association
module Associations module Associations
@ -63,11 +65,12 @@ module ActiveRecord
save_through_record(record) save_through_record(record)
if has_cached_counter? && !through_reflection_updates_counter_cache? if has_cached_counter? && !through_reflection_updates_counter_cache?
ActiveSupport::Deprecation.warn \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"Automatic updating of counter caches on through associations has been " \ Automatic updating of counter caches on through associations has been
"deprecated, and will be removed in Rails 5.0. Instead, please set the " \ deprecated, and will be removed in Rails 5.0. Instead, please set the
"appropriate counter_cache options on the has_many and belongs_to for " \ appropriate counter_cache options on the has_many and belongs_to for
"your associations to #{through_reflection.name}." your associations to #{through_reflection.name}.
MSG
update_counter_in_database(1) update_counter_in_database(1)
end end

View file

@ -1,4 +1,5 @@
require 'active_support/core_ext/enumerable' require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/string/filters'
require 'mutex_m' require 'mutex_m'
require 'thread_safe' require 'thread_safe'
@ -205,9 +206,11 @@ module ActiveRecord
def column_for_attribute(name) def column_for_attribute(name)
column = columns_hash[name.to_s] column = columns_hash[name.to_s]
if column.nil? if column.nil?
ActiveSupport::Deprecation.warn \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"`column_for_attribute` will return a null object for non-existent columns " \ `column_for_attribute` will return a null object for non-existent
"in Rails 5.0. Use `has_attribute?` if you need to check for an attribute's existence." columns in Rails 5.0. Use `has_attribute?` if you need to check for
an attribute's existence.
MSG
end end
column column
end end

View file

@ -1,3 +1,5 @@
require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
module AttributeMethods module AttributeMethods
module Serialization module Serialization
@ -51,8 +53,10 @@ module ActiveRecord
end end
def serialized_attributes def serialized_attributes
ActiveSupport::Deprecation.warn "`serialized_attributes` is deprecated " \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"without replacement, and will be removed in Rails 5.0." `serialized_attributes` is deprecated without replacement, and will
be removed in Rails 5.0.
MSG
@serialized_attributes ||= Hash[ @serialized_attributes ||= Hash[
columns.select { |t| t.cast_type.is_a?(Type::Serialized) }.map { |c| columns.select { |t| t.cast_type.is_a?(Type::Serialized) }.map { |c|

View file

@ -2,6 +2,7 @@ require 'thread'
require 'thread_safe' require 'thread_safe'
require 'monitor' require 'monitor'
require 'set' require 'set'
require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
# Raised when a connection could not be obtained within the connection # Raised when a connection could not be obtained within the connection
@ -518,10 +519,11 @@ module ActiveRecord
end end
def connection_pools def connection_pools
ActiveSupport::Deprecation.warn( ActiveSupport::Deprecation.warn(<<-MSG.squish)
"In the next release, this will return the same as #connection_pool_list. " \ In the next release, this will return the same as #connection_pool_list.
"(An array of pools, rather than a hash mapping specs to pools.)" (An array of pools, rather than a hash mapping specs to pools.)
) MSG
Hash[connection_pool_list.map { |pool| [pool.spec, pool] }] Hash[connection_pool_list.map { |pool| [pool.spec, pool] }]
end end

View file

@ -60,11 +60,12 @@ module ActiveRecord
def emit_warning_if_null_unspecified(options) def emit_warning_if_null_unspecified(options)
return if options.key?(:null) return if options.key?(:null)
ActiveSupport::Deprecation.warn \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"`timestamp` was called without specifying an option for `null`. In Rails " \ `timestamp` was called without specifying an option for `null`. In Rails
"5.0, this behavior will change to `null: false`. You should manually " \ 5.0, this behavior will change to `null: false`. You should manually
"specify `null: true` to prevent the behavior of your existing migrations " \ specify `null: true` to prevent the behavior of your existing migrations
"from changing." from changing.
MSG
end end
end end

View file

@ -1,4 +1,5 @@
require 'uri' require 'uri'
require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
module ConnectionAdapters module ConnectionAdapters
@ -221,8 +222,12 @@ module ActiveRecord
# this ambiguous behaviour and in the future this function # this ambiguous behaviour and in the future this function
# can be removed in favor of resolve_url_connection. # can be removed in favor of resolve_url_connection.
if configurations.key?(spec) || spec !~ /:/ if configurations.key?(spec) || spec !~ /:/
ActiveSupport::Deprecation.warn "Passing a string to ActiveRecord::Base.establish_connection " \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"for a configuration lookup is deprecated, please pass a symbol (#{spec.to_sym.inspect}) instead" Passing a string to ActiveRecord::Base.establish_connection for a
configuration lookup is deprecated, please pass a symbol
(#{spec.to_sym.inspect}) instead
MSG
resolve_symbol_connection(spec) resolve_symbol_connection(spec)
else else
resolve_url_connection(spec) resolve_url_connection(spec)

View file

@ -1,3 +1,5 @@
require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
module ConnectionAdapters module ConnectionAdapters
module PostgreSQL module PostgreSQL
@ -25,10 +27,11 @@ module ActiveRecord
if !infinity?(from) && extracted[:exclude_start] if !infinity?(from) && extracted[:exclude_start]
if from.respond_to?(:succ) if from.respond_to?(:succ)
from = from.succ from = from.succ
ActiveSupport::Deprecation.warn \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"Excluding the beginning of a Range is only partialy supported " \ Excluding the beginning of a Range is only partialy supported
"through `#succ`. This is not reliable and will be removed in " \ through `#succ`. This is not reliable and will be removed in
"the future." the future.
MSG
else else
raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')" raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')"
end end

View file

@ -1,6 +1,7 @@
require 'thread'
require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/object/duplicable'
require 'thread' require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
module Core module Core
@ -88,8 +89,10 @@ module ActiveRecord
mattr_accessor :maintain_test_schema, instance_accessor: false mattr_accessor :maintain_test_schema, instance_accessor: false
def self.disable_implicit_join_references=(value) def self.disable_implicit_join_references=(value)
ActiveSupport::Deprecation.warn("Implicit join references were removed with Rails 4.1." \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"Make sure to remove this configuration because it does nothing.") Implicit join references were removed with Rails 4.1.
Make sure to remove this configuration because it does nothing.
MSG
end end
class_attribute :default_connection_handler, instance_writer: false class_attribute :default_connection_handler, instance_writer: false
@ -135,8 +138,10 @@ module ActiveRecord
id = ids.first id = ids.first
if ActiveRecord::Base === id if ActiveRecord::Base === id
id = id.id id = id.id
ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `find`." \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"Please pass the id of the object by calling `.id`" You are passing an instance of ActiveRecord::Base to `find`.
Please pass the id of the object by calling `.id`
MSG
end end
key = primary_key key = primary_key

View file

@ -1,4 +1,5 @@
require 'thread' require 'thread'
require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
# = Active Record Reflection # = Active Record Reflection
@ -153,8 +154,11 @@ module ActiveRecord
end end
def source_macro def source_macro
ActiveSupport::Deprecation.warn("ActiveRecord::Base.source_macro is deprecated and " \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"will be removed without replacement.") ActiveRecord::Base.source_macro is deprecated and will be removed
without replacement.
MSG
macro macro
end end
end end
@ -339,13 +343,14 @@ module ActiveRecord
return unless scope return unless scope
if scope.arity > 0 if scope.arity > 0
ActiveSupport::Deprecation.warn \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"The association scope '#{name}' is instance dependent (the scope " \ The association scope '#{name}' is instance dependent (the scope
"block takes an argument). Preloading happens before the individual " \ block takes an argument). Preloading happens before the individual
"instances are created. This means that there is no instance being " \ instances are created. This means that there is no instance being
"passed to the association scope. This will most likely result in " \ passed to the association scope. This will most likely result in
"broken or incorrect behavior. Joining, Preloading and eager loading " \ broken or incorrect behavior. Joining, Preloading and eager loading
"of these associations is deprecated and will be removed in the future." of these associations is deprecated and will be removed in the future.
MSG
end end
end end
alias :check_eager_loadable! :check_preloadable! alias :check_eager_loadable! :check_preloadable!
@ -746,8 +751,11 @@ module ActiveRecord
# The macro used by the source association # The macro used by the source association
def source_macro def source_macro
ActiveSupport::Deprecation.warn("ActiveRecord::Base.source_macro is deprecated and " \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"will be removed without replacement.") ActiveRecord::Base.source_macro is deprecated and will be removed
without replacement.
MSG
source_reflection.source_macro source_reflection.source_macro
end end

View file

@ -1,4 +1,5 @@
require 'active_support/deprecation' require 'active_support/deprecation'
require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
module FinderMethods module FinderMethods
@ -284,8 +285,10 @@ module ActiveRecord
def exists?(conditions = :none) def exists?(conditions = :none)
if Base === conditions if Base === conditions
conditions = conditions.id conditions = conditions.id
ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `exists?`." \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"Please pass the id of the object by calling `.id`" You are passing an instance of ActiveRecord::Base to `exists?`.
Please pass the id of the object by calling `.id`
MSG
end end
return false if !conditions return false if !conditions
@ -435,8 +438,10 @@ module ActiveRecord
def find_one(id) def find_one(id)
if ActiveRecord::Base === id if ActiveRecord::Base === id
id = id.id id = id.id
ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `find`." \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"Please pass the id of the object by calling `.id`" You are passing an instance of ActiveRecord::Base to `find`.
Please pass the id of the object by calling `.id`
MSG
end end
column = columns_hash[primary_key] column = columns_hash[primary_key]

View file

@ -1,3 +1,5 @@
require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
class PredicateBuilder class PredicateBuilder
class ArrayHandler # :nodoc: class ArrayHandler # :nodoc:
@ -6,9 +8,12 @@ module ActiveRecord
nils, values = values.partition(&:nil?) nils, values = values.partition(&:nil?)
if values.any? { |val| val.is_a?(Array) } if values.any? { |val| val.is_a?(Array) }
ActiveSupport::Deprecation.warn "Passing a nested array to Active Record " \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"finder methods is deprecated and will be removed. Flatten your array " \ Passing a nested array to Active Record finder methods is
"before using it for 'IN' conditions." deprecated and will be removed. Flatten your array before using
it for 'IN' conditions.
MSG
values = values.flatten values = values.flatten
end end

View file

@ -1,4 +1,5 @@
require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/string/filters'
require 'active_model/forbidden_attributes_protection' require 'active_model/forbidden_attributes_protection'
module ActiveRecord module ActiveRecord
@ -94,8 +95,10 @@ module ActiveRecord
def check_cached_relation # :nodoc: def check_cached_relation # :nodoc:
if defined?(@arel) && @arel if defined?(@arel) && @arel
@arel = nil @arel = nil
ActiveSupport::Deprecation.warn "Modifying already cached Relation. The " \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"cache will be reset. Use a cloned Relation to prevent this warning." Modifying already cached Relation. The cache will be reset. Use a
cloned Relation to prevent this warning.
MSG
end end
end end

View file

@ -1,3 +1,5 @@
require 'active_support/core_ext/string/filters'
module ActiveRecord module ActiveRecord
module Tasks # :nodoc: module Tasks # :nodoc:
class DatabaseAlreadyExists < StandardError; end # :nodoc: class DatabaseAlreadyExists < StandardError; end # :nodoc:
@ -187,9 +189,10 @@ module ActiveRecord
end end
def load_schema(format = ActiveRecord::Base.schema_format, file = nil) def load_schema(format = ActiveRecord::Base.schema_format, file = nil)
ActiveSupport::Deprecation.warn \ ActiveSupport::Deprecation.warn(<<-MSG.squish)
"This method will act on a specific connection in the future. " \ This method will act on a specific connection in the future.
"To act on the current connection, use `load_schema_current` instead." To act on the current connection, use `load_schema_current` instead.
MSG
load_schema_current(format, file) load_schema_current(format, file)
end end