class ScaffoldPlus::Generators::HabtmGenerator
Public Instance Methods
add_migration()
click to toggle source
# File lib/generators/scaffold_plus/habtm/habtm_generator.rb, line 21 def add_migration return unless options.migration? migration_template "habtm_migration.rb", "db/migrate/#{habtm_migration_name}.rb" end
add_to_models()
click to toggle source
# File lib/generators/scaffold_plus/habtm/habtm_generator.rb, line 26 def add_to_models inject_into_class "app/models/#{name}.rb", class_name do text = before_array.include?(name) ? "\n" : "" text << " has_and_belongs_to_many :#{other.pluralize}\n" text << "\n" if after_array.include?(name) text end inject_into_class "app/models/#{other}.rb", other.camelize do text = before_array.include?(other) ? "\n" : "" text << " has_and_belongs_to_many :#{table_name}\n" text << "\n" if after_array.include?(other) text end end
add_to_permit()
click to toggle source
# File lib/generators/scaffold_plus/habtm/habtm_generator.rb, line 41 def add_to_permit return unless options.permit? text = "{ :#{other}_ids => [] }" file = "app/controllers/#{table_name}_controller.rb" gsub_file file, /(permit\(.*)\)/, "\\1, #{text})" # Special case: no previous permit gsub_file file, /^(\s*params)\[:#{name}\]$/, "\\1.require(:#{name}).permit(#{text})" end
Protected Instance Methods
after_array()
click to toggle source
# File lib/generators/scaffold_plus/habtm/habtm_generator.rb, line 56 def after_array options['after'] || [] end
before_array()
click to toggle source
# File lib/generators/scaffold_plus/habtm/habtm_generator.rb, line 52 def before_array options['before'] || [] end
habtm_migration_name()
click to toggle source
# File lib/generators/scaffold_plus/habtm/habtm_generator.rb, line 68 def habtm_migration_name "create_#{sorted_pl.first}_and_#{sorted_pl.second}" end
habtm_table_name()
click to toggle source
# File lib/generators/scaffold_plus/habtm/habtm_generator.rb, line 72 def habtm_table_name "#{sorted_pl.first}_#{sorted_pl.second}" end
sorted_pl()
click to toggle source
# File lib/generators/scaffold_plus/habtm/habtm_generator.rb, line 64 def sorted_pl [table_name, other.pluralize].sort end
sorted_sg()
click to toggle source
# File lib/generators/scaffold_plus/habtm/habtm_generator.rb, line 60 def sorted_sg [name, other].sort end