Class: Cable::Generators::ResourceGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::Migration, Rails::Generators::ResourceHelpers
Defined in:
lib/generators/cable/resource/resource_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

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.timestamped_migrations
   Time.now.utc.strftime("%Y%m%d%H%M%S")
 else
   "%.3d" % (current_migration_number(dirname) + 1)
 end
end

Instance Method Details

#create_controller_fileObject



33
34
35
36
37
# File 'lib/generators/cable/resource/resource_generator.rb', line 33

def create_controller_file
  if options.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_fileObject



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 options.migration? and yes?("Would you like to generate a migration?".color(:yellow))
end

#create_model_fileObject



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 options.model? and yes?("Would you like to generate a model?".color(:yellow))
end

#create_scaffoldObject



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 options.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_routeObject



51
52
53
# File 'lib/generators/cable/resource/resource_generator.rb', line 51

def install_route
  route("cable_to :#{plural_table_name}") if options.routes? and yes?("Would you like to generate routes for #{model_name.capitalize}?".color(:yellow))
end