Class: Cable::Generators::ResourceGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Cable::Generators::ResourceGenerator
- Includes:
- Rails::Generators::Migration, Rails::Generators::ResourceHelpers
- Defined in:
- lib/generators/cable/resource/resource_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_controller_file ⇒ Object
- #create_migration_file ⇒ Object
- #create_model_file ⇒ Object
- #create_scaffold ⇒ Object
- #install_route ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/generators/cable/resource/resource_generator.rb', line 55 def self.next_migration_number(dirname) if ActiveRecord::Base. Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
Instance Method Details
#create_controller_file ⇒ Object
33 34 35 36 37 |
# File 'lib/generators/cable/resource/resource_generator.rb', line 33 def create_controller_file if .controller? template 'controller.rb' , "app/controllers/admin/#{file_name.pluralize}_controller.rb" if yes?("Would you like to generate a controller?".color(:yellow)) end end |
#create_migration_file ⇒ Object
25 26 27 |
# File 'lib/generators/cable/resource/resource_generator.rb', line 25 def create_migration_file migration_template 'migration.rb', "db/migrate/create_#{table_name}.rb" if .migration? and yes?("Would you like to generate a migration?".color(:yellow)) end |
#create_model_file ⇒ Object
29 30 31 |
# File 'lib/generators/cable/resource/resource_generator.rb', line 29 def create_model_file template 'model.rb' , "app/models/#{model_name}.rb" if .model? and yes?("Would you like to generate a model?".color(:yellow)) end |
#create_scaffold ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/cable/resource/resource_generator.rb', line 39 def create_scaffold if .views? if yes?("Would you like Cable to generate views for #{model_name.capitalize}?".color(:yellow)) template 'erb/scaffold/_form.html.erb', "app/views/admin/#{plural_table_name}/_#{singular_table_name}.html.erb" template 'erb/scaffold/index.html.erb', "app/views/admin/#{plural_table_name}/index.html.erb" template 'erb/scaffold/edit.html.erb', "app/views/admin/#{plural_table_name}/edit.html.erb" template 'erb/scaffold/new.html.erb', "app/views/admin/#{plural_table_name}/new.html.erb" template 'erb/scaffold/show.html.erb', "app/views/admin/#{plural_table_name}/show.html.erb" end end end |
#install_route ⇒ Object
51 52 53 |
# File 'lib/generators/cable/resource/resource_generator.rb', line 51 def install_route route("cable_to :#{plural_table_name}") if .routes? and yes?("Would you like to generate routes for #{model_name.capitalize}?".color(:yellow)) end |