Remove duplication at the deprecated methods

This commit is contained in:
Rafael Mendonça França 2014-03-11 16:10:26 -03:00
parent 61865123f4
commit ed1862036c
1 changed files with 8 additions and 16 deletions

View File

@ -8,28 +8,20 @@ module SimpleForm
end
def label_input(context=nil)
options[:label] == false ? deprecated_input(context) : (deprecated_label(context) + deprecated_input(context))
if options[:label] == false
deprecated_component(:input ,context)
else
deprecated_component(:label, context) + deprecated_component(:input, context)
end
end
private
def deprecated_input(context)
method = method(:input)
def deprecated_component(namespace ,context)
method = method(namespace)
if method.arity == 0
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: 'input' })
method.call
else
method.call(context)
end
end
def deprecated_label(context)
method = method(:label)
if method.arity == 0
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: 'label' })
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: namespace })
method.call
else