Class: Natra::Generators::AppGenerator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/natra/generators/app/app_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



20
21
22
# File 'lib/natra/generators/app/app_generator.rb', line 20

def self.source_root
  File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
end

Instance Method Details

#create_app_directoryObject



47
48
49
# File 'lib/natra/generators/app/app_generator.rb', line 47

def create_app_directory
  %w[app/controllers app/views app/models].each {|dir| directory dir, File.join(@app_path, dir)}
end

#create_app_specObject



51
52
53
# File 'lib/natra/generators/app/app_generator.rb', line 51

def create_app_spec
  template 'spec/application_controller_spec.rb', File.join(@app_path, 'spec/application_controller_spec.rb')
end

#create_capistrano_configObject



119
120
121
# File 'lib/natra/generators/app/app_generator.rb', line 119

def create_capistrano_config
  inside(@app_path) { run('cap install') } if @capistrano
end

#create_configObject



59
60
61
# File 'lib/natra/generators/app/app_generator.rb', line 59

def create_config
  template 'config.ru', File.join(@app_path, 'config.ru')
end

#create_db_configObject



75
76
77
# File 'lib/natra/generators/app/app_generator.rb', line 75

def create_db_config
  template('config/database.yml', File.join(@app_path, 'config/database.yml'))
end

#create_dockerObject



99
100
101
# File 'lib/natra/generators/app/app_generator.rb', line 99

def create_docker
  copy_file 'Dockerfile', File.join(@app_path, 'Dockerfile')
end

#create_docker_composeObject



103
104
105
# File 'lib/natra/generators/app/app_generator.rb', line 103

def create_docker_compose
  template('docker-compose.yml', File.join(@app_path, 'docker-compose.yml'))
end

#create_empty_directoriesObject



24
25
26
27
28
29
# File 'lib/natra/generators/app/app_generator.rb', line 24

def create_empty_directories
  %w[config/initializers lib spec].each {|dir| empty_directory File.join(@app_path, dir)}
  empty_directory File.join(@app_path, 'db/migrate')
  create_file File.join(@app_path, 'lib', '.keep')
  template 'config/environment.rb', File.join(@app_path, 'config/environment.rb')
end

#create_gemfileObject



63
64
65
# File 'lib/natra/generators/app/app_generator.rb', line 63

def create_gemfile
  template 'Gemfile', File.join(@app_path, 'Gemfile')
end

#create_gitignoreObject



87
88
89
# File 'lib/natra/generators/app/app_generator.rb', line 87

def create_gitignore
  copy_file 'gitignore', File.join(@app_path, '.gitignore')
end

#create_guardfileObject



107
108
109
# File 'lib/natra/generators/app/app_generator.rb', line 107

def create_guardfile
  copy_file 'Guardfile', File.join(@app_path, 'Guardfile')
end

#create_public_directoryObject



43
44
45
# File 'lib/natra/generators/app/app_generator.rb', line 43

def create_public_directory
  template 'public/favicon.ico', File.join(@app_path, 'public/favicon.ico')
end

#create_rakefileObject



67
68
69
# File 'lib/natra/generators/app/app_generator.rb', line 67

def create_rakefile
  template 'Rakefile', File.join(@app_path, 'Rakefile')
end

#create_readmeObject



71
72
73
# File 'lib/natra/generators/app/app_generator.rb', line 71

def create_readme
  template('README.md', File.join(@app_path, 'README.md'))
end

#create_redis_configObject



79
80
81
# File 'lib/natra/generators/app/app_generator.rb', line 79

def create_redis_config
  copy_file('config/redis.yml', File.join(@app_path, 'config/redis.yml')) if @redis
end

#create_redis_initializerObject



83
84
85
# File 'lib/natra/generators/app/app_generator.rb', line 83

def create_redis_initializer
  template('config/initializers/redis.rb', File.join(@app_path, 'config/initializers/redis.rb')) if @redis
end

#create_rspecObject



91
92
93
# File 'lib/natra/generators/app/app_generator.rb', line 91

def create_rspec
  copy_file 'rspec', File.join(@app_path, '.rspec')
end

#create_rubocopObject



95
96
97
# File 'lib/natra/generators/app/app_generator.rb', line 95

def create_rubocop
  copy_file 'rubocop.yml', File.join(@app_path, '.rubocop.yml')
end

#create_rvm_gemsetObject



123
124
125
126
127
128
129
130
131
# File 'lib/natra/generators/app/app_generator.rb', line 123

def create_rvm_gemset
  if @rvm
    create_file(File.join(@app_path, '.ruby-version'), 'ruby-2.1.0')
    create_file(File.join(@app_path, '.ruby-gemset'), @app_path)

    @bundle = false
    puts "You need to run 'bundle install' manually."
  end
end

#create_secretsObject



115
116
117
# File 'lib/natra/generators/app/app_generator.rb', line 115

def create_secrets
  template('secrets.env', File.join(@app_path, 'secrets.env'))
end

#create_seeds_fileObject



31
32
33
# File 'lib/natra/generators/app/app_generator.rb', line 31

def create_seeds_file
  create_file File.join(@app_path, 'db', 'seeds.rb')
end

#create_spec_helperObject



55
56
57
# File 'lib/natra/generators/app/app_generator.rb', line 55

def create_spec_helper
  template 'spec/spec_helper.rb', File.join(@app_path, 'spec/spec_helper.rb')
end

#create_spec_supportObject



111
112
113
# File 'lib/natra/generators/app/app_generator.rb', line 111

def create_spec_support
  create_file File.join(@app_path, 'spec/support/', '.keep')
end

#initialize_appObject



141
142
143
144
145
146
147
148
149
# File 'lib/natra/generators/app/app_generator.rb', line 141

def initialize_app
  system <<~SCRIPT
    cd #{@app_path}
    #{'chmod +x bin/setup'}
    git init
    git add .
    docker-compose build --pull
  SCRIPT
end

#initialize_dbObject



35
36
37
# File 'lib/natra/generators/app/app_generator.rb', line 35

def initialize_db
  copy_file('bin/setup', File.join(@app_path, 'bin/setup'))
end

#initialize_git_repoObject



133
134
135
# File 'lib/natra/generators/app/app_generator.rb', line 133

def initialize_git_repo
  inside(@app_path) { run('git init .') if @git }
end

#install_dependenciesObject



137
138
139
# File 'lib/natra/generators/app/app_generator.rb', line 137

def install_dependencies
  inside(@app_path) { run('bundle') if @bundle }
end

#setupObject



14
15
16
17
18
# File 'lib/natra/generators/app/app_generator.rb', line 14

def setup
  @app_path = name.directory_name
  @name     = name.file_name
  options.each { |key, value| instance_variable_set "@#{key}".to_sym, value }
end

#uuid_setupObject



39
40
41
# File 'lib/natra/generators/app/app_generator.rb', line 39

def uuid_setup
  template 'db/migrate/add_extensions.rb', File.join(@app_path, "db/migrate/#{Time.now.strftime('%Y%m%d')}0000_add_extensions.rb")
end