Module: EnumHelp::SimpleForm::BuilderExtension

Defined in:
lib/enum_help/simple_form.rb

Instance Method Summary collapse

Instance Method Details

#default_input_type(*args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/enum_help/simple_form.rb', line 7

def default_input_type(*args, &block)
  att_name = (args.first || @attribute_name).to_s
  options = args.last
  return :enum_radio_buttons if options.is_a?(Hash) && options[:as] == :radio_buttons &&
                                is_enum_attributes?( att_name )

  return :enum if (options.is_a?(Hash) ? options[:as] : @options[:as]).nil? &&
                  is_enum_attributes?( att_name )

  super
end

#is_enum_attributes?(attribute_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/enum_help/simple_form.rb', line 20

def is_enum_attributes?( attribute_name )
  object.class.respond_to?(:defined_enums) &&
    object.class.defined_enums.key?(attribute_name) &&
    attribute_name.pluralize != "references"
end