class Comfy::Generators::ScaffoldGenerator

Public Class Methods

new(*args, &block) click to toggle source
Calls superclass method
# File lib/generators/comfy/scaffold/scaffold_generator.rb, line 20
def initialize(*args, &block)
  super
  @model_attrs = []
  model_args.each do |arg|
    next unless arg.include?(":")
    @model_attrs << Rails::Generators::GeneratedAttribute.new(*arg.split(":"))
  end
end
next_migration_number(dirname) click to toggle source
# File lib/generators/comfy/scaffold/scaffold_generator.rb, line 29
def self.next_migration_number(dirname)
  ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Public Instance Methods

generate_controller() click to toggle source
# File lib/generators/comfy/scaffold/scaffold_generator.rb, line 40
def generate_controller
  template "controller.rb", "app/controllers/admin/#{file_name.pluralize}_controller.rb"
  template "tests/controller.rb", "test/controllers/admin/#{file_name.pluralize}_controller_test.rb"
end
generate_model() click to toggle source
# File lib/generators/comfy/scaffold/scaffold_generator.rb, line 33
def generate_model
  migration_template "migration.rb", "db/migrate/create_#{file_name.pluralize}.rb"
  template "model.rb", "app/models/#{file_name}.rb"
  template "tests/model.rb", "test/models/#{file_name}_test.rb"
  template "tests/fixture.yml", "test/fixtures/#{file_name.pluralize}.yml"
end
generate_route() click to toggle source
# File lib/generators/comfy/scaffold/scaffold_generator.rb, line 53
      def generate_route
        route_string = <<~TEXT
          namespace :admin do
            resources :#{file_name.pluralize}
          end

        TEXT
        route route_string
      end
generate_views() click to toggle source
# File lib/generators/comfy/scaffold/scaffold_generator.rb, line 45
def generate_views
  template "views/index.haml", "app/views/admin/#{file_name.pluralize}/index.html.haml"
  template "views/show.haml", "app/views/admin/#{file_name.pluralize}/show.html.haml"
  template "views/new.haml", "app/views/admin/#{file_name.pluralize}/new.html.haml"
  template "views/edit.haml", "app/views/admin/#{file_name.pluralize}/edit.html.haml"
  template "views/_form.haml", "app/views/admin/#{file_name.pluralize}/_form.html.haml"
end