Module: ViewMapper::HasManyAutoCompleteView
- Defined in:
- lib/view_mapper/has_many_auto_complete_view.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_auto_complete_manifest(m) ⇒ Object
- #add_auto_complete_route(manifest, model_name, text_field) ⇒ Object
- #auto_complete_attributes ⇒ Object
- #auto_complete_attributes_for_model(model_info) ⇒ Object
- #auto_complete_attributes_from_command_line ⇒ Object
- #auto_complete_for_method(model_name, text_field) ⇒ Object
- #find_auto_complete_attributes ⇒ Object
- #is_auto_complete_attribute?(model_name, text_field) ⇒ Boolean
- #manifest ⇒ Object
- #source_roots_for_view ⇒ Object
- #validate ⇒ Object
Class Method Details
.extended(base) ⇒ Object
4 5 6 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 4 def self.extended(base) base.extend(ViewMapper::HasManyChildModels) end |
.source_root ⇒ Object
8 9 10 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 8 def self.source_root File.(File.dirname(__FILE__) + "/templates") end |
Instance Method Details
#add_auto_complete_manifest(m) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 30 def add_auto_complete_manifest(m) if valid auto_complete_attributes.each do |attrib| add_auto_complete_route(m, attrib[:model_name], attrib[:text_field]) end end end |
#add_auto_complete_route(manifest, model_name, text_field) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 38 def add_auto_complete_route(manifest, model_name, text_field) manifest.route :name => 'connect', :path => auto_complete_for_method(model_name, text_field), :controller => controller_file_name, :action => auto_complete_for_method(model_name, text_field) end |
#auto_complete_attributes ⇒ Object
49 50 51 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 49 def auto_complete_attributes @auto_complete_attributes = find_auto_complete_attributes end |
#auto_complete_attributes_for_model(model_info) ⇒ Object
64 65 66 67 68 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 64 def auto_complete_attributes_for_model(model_info) model_info.text_fields.collect do |text_field| { :model_name => model_info.name.underscore, :text_field => text_field } end end |
#auto_complete_attributes_from_command_line ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 70 def auto_complete_attributes_from_command_line attributes.reject do |cmd_line_attrib| !ViewMapper::ModelInfo.is_text_field_attrib_type? cmd_line_attrib.type end.collect do |cmd_line_attrib| { :model_name => singular_name, :text_field => cmd_line_attrib.name } end end |
#auto_complete_for_method(model_name, text_field) ⇒ Object
45 46 47 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 45 def auto_complete_for_method(model_name, text_field) "auto_complete_for_#{model_name}_#{text_field}" end |
#find_auto_complete_attributes ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 53 def find_auto_complete_attributes attribs = [] if view_only? attribs << auto_complete_attributes_for_model(model) else attribs << auto_complete_attributes_from_command_line end attribs << child_models.collect { |child| auto_complete_attributes_for_model(child) } attribs.flatten end |
#is_auto_complete_attribute?(model_name, text_field) ⇒ Boolean
78 79 80 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 78 def is_auto_complete_attribute?(model_name, text_field) !auto_complete_attributes.detect { |attrib| attrib[:model_name] == model_name && attrib[:text_field] == text_field }.nil? end |
#manifest ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 21 def manifest m = super.edit do |action| action unless is_child_model_action?(action) end add_child_models_manifest(m) add_auto_complete_manifest(m) m end |
#source_roots_for_view ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 12 def source_roots_for_view [ HasManyAutoCompleteView.source_root, HasManyView.source_root, File.(source_root), File.(File.join(self.class.lookup('model').path, 'templates')) ] end |
#validate ⇒ Object
82 83 84 85 |
# File 'lib/view_mapper/has_many_auto_complete_view.rb', line 82 def validate super @valid &&= validate_child_models end |