Class: Common::Generators::ScaffoldGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/common/scaffold/scaffold_generator.rb
Instance Method Summary collapse
- #create_controller ⇒ Object
- #create_migrations ⇒ Object
- #create_model ⇒ Object
- #create_views ⇒ Object
-
#initialize(*args, &block) ⇒ ScaffoldGenerator
constructor
complete:scaffold Admin:User login:string email:string time_zone:string.
Methods inherited from Base
Constructor Details
#initialize(*args, &block) ⇒ ScaffoldGenerator
complete:scaffold Admin:User login:string email:string time_zone:string
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/generators/common/scaffold/scaffold_generator.rb', line 20 def initialize(*args, &block) super @controller_actions = [] args_for_c_m.each do |arg| if arg == '!' [:invert] = true elsif arg.include?(':') model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':')) else @controller_actions << arg @controller_actions << 'create' if arg == 'new' @controller_actions << 'update' if arg == 'edit' end end if .invert? || @controller_actions.empty? @controller_actions = all_actions - @controller_actions end end |
Instance Method Details
#create_controller ⇒ Object
44 45 46 47 48 49 |
# File 'lib/generators/common/scaffold/scaffold_generator.rb', line 44 def create_controller unless .skip_controller? template 'controller.rb', "app/controllers/#{plural_name_path}_controller.rb" template 'helper.rb', "app/helpers/#{plural_name_path}_helper.rb" end end |
#create_migrations ⇒ Object
62 63 64 65 66 |
# File 'lib/generators/common/scaffold/scaffold_generator.rb', line 62 def create_migrations unless .skip_model? || .skip_migration? migration_template 'migration.rb', "db/migrate/create_#{plural_name}.rb" end end |
#create_model ⇒ Object
38 39 40 41 42 43 |
# File 'lib/generators/common/scaffold/scaffold_generator.rb', line 38 def create_model unless .skip_model? template 'model.rb', "app/models/#{singular_name_path}.rb" template "rspec/model.rb", "spec/models/#{singular_name_path}_spec.rb" end end |
#create_views ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/generators/common/scaffold/scaffold_generator.rb', line 50 def create_views unless .skip_controller? @controller_actions.each do |action| if %w[index show new edit].include?(action) # Actions with templates template "views/#{action}.html.haml", "app/views/#{plural_name_path}/#{action}.html.haml" end end template "views/_form.html.haml", "app/views/#{plural_name_path}/_form.html.haml" template "views/_collection.html.haml", "app/views/#{plural_name_path}/_#{collection_name}.html.haml" route "resources #{plural_name.to_sym.inspect}" end end |