Class: OldSql::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/old_sql/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#check_for_deviseObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/generators/old_sql/install_generator.rb', line 8

def check_for_devise
  puts "Old SQL works with devise. Checking for a current installation of devise!\n"

  if defined?(Devise)
    check_for_devise_models
  else
    puts "Please put gem 'devise' into your Gemfile"
  end
  
  puts "Also you need a new migration. We'll generate it for you now."
  invoke 'old_sql:install_migrations', ["#{model_name}"]
end

#configure_initializerObject



64
65
66
67
# File 'lib/generators/old_sql/install_generator.rb', line 64

def configure_initializer
  initializer_path = "#{app_path}/config/initializers/old_sql.rb"
  gsub_file initializer_path, /DeviseModel/, "#{model_name.singularize.downcase}"
end

#copy_initializerObject



21
22
23
# File 'lib/generators/old_sql/install_generator.rb', line 21

def copy_initializer
  template "old_sql.rb", "config/initializers/old_sql.rb"
end

#copy_locales_filesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/old_sql/install_generator.rb', line 25

def copy_locales_files
  print "Now copying locales files! "
  ###
  locales_path = "#{gem_path}/config/locales/*.yml"

  locales_app_path = "#{app_path}/config/locales"

  unless File.directory?(locales_app_path)
    FileUtils.mkdir locales_app_path
  end

  Dir.glob(locales_path).each do |file|
    file_path = file.split("/")
    file_path = file_path[-1]
    FileUtils.copy_file(file, "#{locales_app_path}/#{file_path}")
    print "."
  end
  print "\n"

end

#copy_old_sql_filesObject



54
55
56
57
58
59
60
61
62
# File 'lib/generators/old_sql/install_generator.rb', line 54

def copy_old_sql_files
  path_to_reports_config = "#{app_path}/config/old_sql/reports.yml"
  copy_file "reports.yml.example", path_to_reports_config unless File.exists?(path_to_reports_config)
  copy_file "user.erb.example", "#{app_path}/config/old_sql/report_sql/user_old_sql_demo.erb"
  copy_file "user_processor.rb.example", "#{app_path}/lib/old_sql/report_processor/user_old_sql_demo_processor.rb"
  copy_file "user_design_template.csv", "#{app_path}/config/old_sql/report_design/user_old_sql_demo.csv"
  copy_file "user_old_sql_demo_chart_design.yml", "#{app_path}/config/old_sql/report_design/user_old_sql_demo.yml"
  copy_file "test_db.rb", "#{app_path}/lib/old_sql/db/test.rb"
end

#create_old_sql_dirsObject



46
47
48
49
50
51
52
# File 'lib/generators/old_sql/install_generator.rb', line 46

def create_old_sql_dirs
  empty_directory "#{app_path}/config/old_sql/"
  empty_directory "#{app_path}/config/old_sql/report_sql"
  empty_directory "#{app_path}/config/old_sql/report_design"
  empty_directory "#{app_path}/lib/old_sql/report_processor"
  empty_directory "#{app_path}/lib/old_sql/db"
end