From 61865123f45c08303ac5e3f08e69ddb1b1c77246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 11 Mar 2014 16:06:45 -0300 Subject: [PATCH] Extract the deprecation message to avoid duplication --- lib/simple_form.rb | 10 ++++++++++ lib/simple_form/components/label_input.rb | 14 ++------------ lib/simple_form/wrappers/leaf.rb | 12 +----------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/lib/simple_form.rb b/lib/simple_form.rb index 4f977dea..e4e5f74a 100644 --- a/lib/simple_form.rb +++ b/lib/simple_form.rb @@ -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. diff --git a/lib/simple_form/components/label_input.rb b/lib/simple_form/components/label_input.rb index 76a7e150..8a8becb3 100644 --- a/lib/simple_form/components/label_input.rb +++ b/lib/simple_form/components/label_input.rb @@ -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 diff --git a/lib/simple_form/wrappers/leaf.rb b/lib/simple_form/wrappers/leaf.rb index 5ab96021..426ddb7e 100644 --- a/lib/simple_form/wrappers/leaf.rb +++ b/lib/simple_form/wrappers/leaf.rb @@ -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