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



52
53
54
55
56
57
58
# File 'lib/generators/cable/resource/resource_generator.rb', line 52

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



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

def create_controller_file
  if options.controller?
    template 'controller.rb' , "app/controllers/admin/#{file_name.pluralize}_controller.rb" 
  end
end

#create_migration_fileObject



24
25
26
# File 'lib/generators/cable/resource/resource_generator.rb', line 24

def create_migration_file
   migration_template 'migration.rb', "db/migrate/create_#{table_name}.rb" if options.migration?
end

#create_model_fileObject



28
29
30
# File 'lib/generators/cable/resource/resource_generator.rb', line 28

def create_model_file
   template 'model.rb' , "app/models/#{model_name}.rb" if options.model?
end

#create_scaffoldObject



38
39
40
41
42
43
44
45
46
# File 'lib/generators/cable/resource/resource_generator.rb', line 38

def create_scaffold
  if options.views?
    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

#install_routeObject



48
49
50
# File 'lib/generators/cable/resource/resource_generator.rb', line 48

def install_route
  route("cable_to :#{plural_table_name}") if options.routes?
end