Class: BrainDamage::View::Input::PolymorphicSelect

Inherits:
NestedOnHideable show all
Defined in:
lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb

Instance Attribute Summary

Attributes inherited from Templateable::FieldTemplateable

#partial_html, #type

Attributes inherited from Templateable::Base

#inner_html, #options, #template_file

Instance Method Summary collapse

Methods inherited from NestedOnHideable

#guard, #label_guard, #label_guard?

Methods inherited from Base

#dir, #tag_options

Methods inherited from Templateable::FieldTemplateable

#empty_haml_path, #label_guard?, #method_missing, #render, #show?, #show_label?

Methods inherited from Templateable::Base

#indent, #method_missing, #render, #render_erb_file, #render_erb_string, #render_template_file

Constructor Details

#initialize(field, options) ⇒ PolymorphicSelect

Returns a new instance of PolymorphicSelect.



8
9
10
11
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 8

def initialize(field, options)
  super
  @normalized_name = name.to_s.gsub('_id', '').gsub('_type', '')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BrainDamage::Templateable::FieldTemplateable

Instance Method Details

#object_select_nameObject



17
18
19
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 17

def object_select_name
  "#{@normalized_name}_id"
end

#options_for_typeObject



21
22
23
24
25
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 21

def options_for_type
  @options[:options].map{ |option|
    "[cet('entities.#{option[:model].to_s.downcase}'), '#{option[:model].to_s}']"
  }.join ', '
end

#type_select_nameObject



13
14
15
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 13

def type_select_name
  "#{@normalized_name}_type"
end

#types_optionsObject



27
28
29
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 27

def types_options
  @options[:options]
end