class Gaku::InstallGenerator

Public Class Methods

source_paths() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 15
def self.source_paths
  paths = superclass.source_paths
  paths << File.expand_path('../templates', "../../#{__FILE__}")
  paths << File.expand_path('../templates', "../#{__FILE__}")
  paths << File.expand_path('../templates', __FILE__)
  paths.flatten
end

Public Instance Methods

complete() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 145
def complete
  unless options[:quiet]
    puts '*' * 50
    puts "Gaku has been installed successfully. You're all ready to go!"
    puts ' '
    puts 'Enjoy!'
  end
end
configure_application() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 62
    def configure_application
      application <<-APP

    config.to_prepare do
      # Load application's model / class injectors
      Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_injector*.rb")) do |c|
        Rails.configuration.cache_classes ? require(c) : load(c)
      end

      # Load application's view overrides
      Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
        Rails.configuration.cache_classes ? require(c) : load(c)
      end

      # Load application's services
      Dir.glob(File.join(File.dirname(__FILE__), "../app/services/**/*.rb")) do |c|
        Rails.configuration.cache_classes ? require(c) : load(c)
      end
    end
      APP

      append_file 'config/environment.rb', "\nActiveRecord::Base.include_root_in_json = true\n"
    end
copy_grading() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 23
def copy_grading
  directory 'lib/grading', 'lib/grading'
  copy_file 'Procfile', 'Procfile'
end
create_database() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 100
def create_database
  say_status :creating, 'database'
  silence_stream(STDOUT) do
    silence_stream(STDERR) do
      silence_warnings { rake 'db:create', env: @env }
    end
  end
end
create_overrides_directory() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 58
def create_overrides_directory
  empty_directory 'app/overrides'
end
include_seed_data() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 86
    def include_seed_data
      append_file 'db/seeds.rb', <<-SEEDS
\n
Gaku::Core::Engine.load_seed if defined?(Gaku::Core)
      SEEDS
    end
install_migrations() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 93
def install_migrations
  say_status :copying, 'migrations'
  silence_stream(STDOUT) do
    silence_warnings { rake 'railties:install:migrations' }
  end
end
notify_about_routes() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 128
def notify_about_routes
  if File.readlines(File.join('config', 'routes.rb')).grep(/mount Gaku::Core::Engine/).any?
    say_status :skipping, 'route Gaku::Core::Engine already present.'
  else
    insert_into_file File.join('config', 'routes.rb'), after: "Rails.application.routes.draw do\n" do
      %Q( mount Gaku::Core::Engine, at: '/' )
    end

    unless options[:quiet]
      puts '*' * 50
      puts "We added the following line to your application's config/routes.rb file:"
      puts ' '
      puts "    mount Gaku::Core::Engine, at: '/'"
    end
  end
end
populate_seed_data() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 118
def populate_seed_data
  if @load_seed_data
    say_status :loading,  'seed data'
    cmd = lambda { rake 'db:seed', env: @env }
    cmd.call
  else
    say_status :skipping, 'seed data (you can always run rake db:seed)'
  end
end
prepare_options() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 28
def prepare_options
  @env = options[:env]
  @run_migrations = options[:migrate]
  @load_seed_data = options[:seed]

  @load_seed_data = false unless @run_migrations
end
remove_unneeded_files() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 36
def remove_unneeded_files
  remove_file 'public/index.html'
end
run_migrations() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 109
def run_migrations
  if @run_migrations
    say_status :running, 'migrations'
    rake 'db:migrate', env: @env
  else
    say_status :skipping, "migrations (don't forget to run rake db:migrate)"
  end
end
setup_assets() click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 40
def setup_assets
  @lib_name = 'gaku'
  %w( javascripts stylesheets images ).each do |path|
    empty_directory "app/assets/#{path}/gaku/frontend" if defined? Gaku::Frontend || Rails.env.test?
    empty_directory "app/assets/#{path}/gaku/admin" if defined? Gaku::Admin || Rails.env.test?
  end

  if defined? Gaku::Frontend || Rails.env.test?
    template 'app/assets/javascripts/gaku/frontend/all.js'
    template 'app/assets/stylesheets/gaku/frontend/all.css'
  end

  if defined? Gaku::Admin || Rails.env.test?
    template 'app/assets/javascripts/gaku/admin/all.js'
    template 'app/assets/stylesheets/gaku/admin/all.css'
  end
end

Private Instance Methods

silence_stream(stream) { || ... } click to toggle source
# File lib/generators/gaku/install/install_generator.rb, line 156
def silence_stream(stream)
  old_stream = stream.dup
  stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
  stream.sync = true
  yield
ensure
  stream.reopen(old_stream)
  old_stream.close
end