require 'rails/generators' require 'highline/import' require 'bundler' require 'bundler/cli' module RaffleV1 class InstallGenerator < Rails::Generators::Base class_option :migrate, :type => :boolean, :default => true, :banner => 'Run Raffle migrations' class_option :seed, :type => :boolean, :default => true, :banner => 'load seed data (migrations must be run)' def self.source_paths paths = self.superclass.source_paths paths << File.expand_path('../templates', "../../#{__FILE__}") paths << File.expand_path('../templates', "../#{__FILE__}") paths << File.expand_path('../templates', __FILE__) paths.flatten end def prepare_options @run_migrations = options[:migrate] @load_seed_data = options[:seed] unless @run_migrations @load_seed_data = false end end def add_files template 'config/initializers/rafflev1.rb', 'config/initializers/rafflev1.rb' end def config_raffleV1_yml create_file "config/rafflev1.yml" do settings = { 'version' => RaffleV1.version } settings.to_yaml end end def remove_unneeded_files remove_file "public/index.html" end def create_overrides_directory empty_directory "app/overrides" end def install_migrations say_status :copying, "migrations" silence_stream(STDOUT) do silence_warnings { rake 'railties:install:migrations' } end end def create_database say_status :creating, "database" silence_stream(STDOUT) do silence_stream(STDERR) do silence_warnings { rake 'db:create' } end end end def run_migrations if @run_migrations say_status :running, "migrations" quietly { rake 'db:migrate' } else say_status :skipping, "migrations (remember to run rake db:migrate)" end end def populate_seed_data if @load_seed_data say_status :loading, "seed data" quietly { rake 'db:seed' } else say_status :skipping, "seed data (you can always run rake db:seed)" end end def notify_about_routes insert_into_file File.join('config', 'routes.rb'), :after => "Application.routes.draw do\n" do %Q{ mount RaffleV1::Engine, :at => '/' } end unless options[:quiet] puts "*" * 8 puts "We added the following line to your application's config/routes.rb file" puts " " puts " mount RaffleV1::Engine, :at => '/'" end end end def complete unless options[:quiet] puts "*" * 8 puts "RaffleV1 has been installed successfull!" puts " " puts "Enjoy Our Raffle Game!" end end end