Class: ScaffoldPlus::Generators::EnumerizeGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- ScaffoldPlus::Generators::EnumerizeGenerator
- Defined in:
- lib/generators/scaffold_plus/enumerize/enumerize_generator.rb
Instance Method Summary collapse
Instance Method Details
#add_migration ⇒ Object
25 26 27 28 |
# File 'lib/generators/scaffold_plus/enumerize/enumerize_generator.rb', line 25 def add_migration return unless .migration? migration_template "enum_migration.rb", "db/migrate/#{migration_name}.rb" end |
#update_controller ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/generators/scaffold_plus/enumerize/enumerize_generator.rb', line 40 def update_controller return unless .permit? text = ":#{column}" 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 |
#update_model ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/scaffold_plus/enumerize/enumerize_generator.rb', line 30 def update_model inject_into_class "app/models/#{name}.rb", class_name do text = .before? ? "\n" : "" text << " extend Enumerize\n" text << " enumerize :#{column}, in: #{values}\n" text << "\n" if .after? text end end |