Class: CassandraConfigurationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/cassandra_migrations/railtie/generators/cassandra_configuration/cassandra_configuration_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_configurationObject

Creates configuration file and migration directory

Any public method in the generator is run automatically when the generator is run. To understand fully see asciicasts.com/episodes/218-making-generators-in-rails-3



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cassandra_migrations/railtie/generators/cassandra_configuration/cassandra_configuration_generator.rb', line 10

def generate_configuration
  require 'fileutils'
  require 'colorize'

  # create cassandra.yaml
  if File.exists?(File.expand_path('config/cassandra.yml'))
    puts "[skip] 'config/cassandra.yml' already exists".yellow
  else
    puts "[new] creating 'config/cassandra.yml' (please update with your own configurations!)".green
    template "cassandra.yml", "config/cassandra.yml"
  end

  # create db/cassandra_migrations
  if File.exists?(File.expand_path('db/cassandra_migrate'))
    puts "[skip] 'db/cassandra_migrate' already exists".yellow
  else
    puts "[new] creating 'db/cassandra_migrate' directory".green
    FileUtils.mkdir(File.expand_path('db/cassandra_migrate'))
  end

  puts '[done]'.green
end