Extract the deprecation message to avoid duplication

This commit is contained in:
Rafael Mendonça França 2014-03-11 16:06:45 -03:00
parent 9e3aae1da3
commit 61865123f4
3 changed files with 13 additions and 23 deletions

View File

@ -24,6 +24,16 @@ module SimpleForm
SimpleForm::Components.eager_load!
end
CUSTOM_INPUT_DEPRECATION_WARN = <<-WARN
%{name} method now accepts a `context` argument. The method definition without the argument is deprecated and will be removed in the next Simple Form version. Change your code from:
def %{name}
to
def %{name}(context)
WARN
## CONFIGURATION OPTIONS
# Method used to tidy up errors.

View File

@ -1,16 +1,6 @@
module SimpleForm
module Components
module LabelInput
DEPRECATION_WARN = <<-WARN
%{name} method now accepts a `context` argument. The method definition without the argument is deprecated and will be removed in the next Simple Form version. Change your code from:
def %{name}
to
def %{name}(context)
WARN
extend ActiveSupport::Concern
included do
@ -27,7 +17,7 @@ to
method = method(:input)
if method.arity == 0
ActiveSupport::Deprecation.warn(DEPRECATION_WARN % { name: 'input' })
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: 'input' })
method.call
else
@ -39,7 +29,7 @@ to
method = method(:label)
if method.arity == 0
ActiveSupport::Deprecation.warn(DEPRECATION_WARN % { name: 'label' })
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: 'label' })
method.call
else

View File

@ -1,16 +1,6 @@
module SimpleForm
module Wrappers
class Leaf
DEPRECATION_WARN = <<-WARN
%{name} method now accepts a `context` argument. The method definition without the argument is deprecated and will be removed in the next Simple Form version. Change your code from:
def %{name}
to
def %{name}(context)
WARN
attr_reader :namespace, :options
def initialize(namespace, options={})
@ -22,7 +12,7 @@ to
method = input.method(@namespace)
if method.arity == 0
ActiveSupport::Deprecation.warn(DEPRECATION_WARN % { name: @namespace })
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: @namespace })
method.call
else