Module: Formtastic::Helpers::InputHelper

Defined in:
lib/locomotive/formtastic.rb

Instance Method Summary collapse

Instance Method Details

#input_class_with_const_defined(as) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/locomotive/formtastic.rb', line 18

def input_class_with_const_defined(as)
  input_class_name = custom_input_class_name(as)

  # get the parent module
  module_class_name = input_class_name.deconstantize
  module_class = module_class_name.blank? ? ::Object : module_class_name.constantize

  # the input class name without the module part
  input_class_name_wo_module = input_class_name.demodulize

  if module_class.const_defined?(input_class_name_wo_module)
    input_class_name.constantize
  elsif Formtastic::Inputs.const_defined?(input_class_name)
    standard_input_class_name(as).constantize
  else
    raise Formtastic::UnknownInputError, "Unable to find input class #{input_class_name}"
  end
end