Class: Visionbundles::Generators::SecurityGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_database_example_configObject

copy exists database config to predefine folder



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/security_generator.rb', line 14

def create_database_example_config
  if File.exists?('config/database.yml')
    copy_file "#{Rails.root}/config/database.yml", "config/database.example.yml"
    copy_file "#{Rails.root}/config/database.example.yml", "preconfig/database.yml"
  else
    copy_file "database.yml", "preconfig/database.yml"
    copy_file "database.yml", "config/database.example.yml"
  end
  run 'git add config/database.example.yml'
  run 'git commit -m "create a database config template!"'
end

#git_initObject

check and add first commit for this project



8
9
10
11
# File 'lib/generators/security_generator.rb', line 8

def git_init
  run 'git init; git add .; git commit -m "init project"' unless File.exists?('.git')
  run 'git reset .'
end

#out_of_database_config_from_source_controlObject

check and ignore database config out of source control



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/security_generator.rb', line 27

def out_of_database_config_from_source_control
  if `git ls-files config/database.yml` != ''
    run 'git rm config/database.yml'
    run 'git commit -m "remove database configuration out of source control!"'
  end

  append_file ".gitignore" do
    <<-eos
    /preconfig/ # production preconfig folder
    /config/database.yml" # should not in source control
    eos
  end
  run 'git add .gitignore'
  run 'git commit -m "git ignore files: preconfig, database.yml"'
end