walter/lib/generators/abraham/install_generator.rb
2016-11-22 13:29:44 -05:00

29 lines
986 B
Ruby

# frozen_string_literal: true
require 'rails/generators'
require 'rails/generators/active_record'
module Abraham
module Generators
class InstallGenerator < ActiveRecord::Generators::Base
argument :name, type: :string, default: 'random_name'
class_option :'skip-migration', type: :boolean, desc: "Don't generate a migration for the histories table"
class_option :'skip-initializer', type: :boolean, desc: "Don't generate an initializer"
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
# Copies the migration template to db/migrate.
def copy_files
return if options['skip-migration']
migration_template 'migration.rb', 'db/migrate/create_abraham_histories.rb'
end
def create_initializer
return if options['skip-initializer']
copy_file 'initializer.rb', 'config/initializers/abraham.rb'
copy_file 'abraham.yml', 'config/abraham.yml'
end
end
end
end