Class: Cable::Generators::MenuGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Cable::Generators::MenuGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/cable/menu/menu_generator.rb
Class Method Summary collapse
-
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
- #create_controller_file ⇒ Object
- #create_migration_file ⇒ Object
- #create_model_file ⇒ Object
- #create_routes ⇒ Object
- #create_views ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration. taken from github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
66 67 68 69 70 71 72 |
# File 'lib/generators/cable/menu/menu_generator.rb', line 66 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
34 35 36 37 38 |
# File 'lib/generators/cable/menu/menu_generator.rb', line 34 def create_controller_file if .controller? template 'controller.rb', "app/controllers/admin/#{model_name.pluralize}_controller.rb" if yes?("Would you like to generate a controller?".color(:yellow)) end end |
#create_migration_file ⇒ Object
22 23 24 25 26 |
# File 'lib/generators/cable/menu/menu_generator.rb', line 22 def create_migration_file if .migration? migration_template 'migration.rb', "db/migrate/create_#{model_name.pluralize}.rb" if yes?("Would you like to generate a migration?".color(:yellow)) end end |
#create_model_file ⇒ Object
28 29 30 31 32 |
# File 'lib/generators/cable/menu/menu_generator.rb', line 28 def create_model_file if .model? template 'model.rb' , "app/models/#{model_name}.rb" if yes?("Would you like to generate a model?".color(:yellow)) end end |
#create_routes ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/generators/cable/menu/menu_generator.rb', line 51 def create_routes route_string = <<EOF cable_to :#{plural_table_name} do |menu| collection do post :sort end end EOF route( route_string ) if yes?("Would you like to generate routes?".color(:yellow)) end |
#create_views ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/cable/menu/menu_generator.rb', line 40 def create_views if .views? if yes?( "Would you like Cable to generate menu views?".color(:yellow)) Dir.glob(File.("../templates", __FILE__) + '/erb/menus/*.erb') do |rb_file| template rb_file, "app/views/admin/#{plural_table_name}/#{File.basename(rb_file)}" end copy_file 'erb/partials/_menu_fields.html.erb', 'app/views/admin/partials/_menu_fields.html.erb' end end end |