Class: Natra::Generators::AppGenerator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Natra::Generators::AppGenerator
- Includes:
- Thor::Actions
- Defined in:
- lib/natra/generators/app/app_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_app_directory ⇒ Object
- #create_app_spec ⇒ Object
- #create_capistrano_config ⇒ Object
- #create_config ⇒ Object
- #create_db_config ⇒ Object
- #create_docker ⇒ Object
- #create_docker_compose ⇒ Object
- #create_empty_directories ⇒ Object
- #create_gemfile ⇒ Object
- #create_gitignore ⇒ Object
- #create_guardfile ⇒ Object
- #create_public_directory ⇒ Object
- #create_rakefile ⇒ Object
- #create_readme ⇒ Object
- #create_redis_config ⇒ Object
- #create_redis_initializer ⇒ Object
- #create_rspec ⇒ Object
- #create_rubocop ⇒ Object
- #create_rvm_gemset ⇒ Object
- #create_secrets ⇒ Object
- #create_seeds_file ⇒ Object
- #create_spec_helper ⇒ Object
- #create_spec_support ⇒ Object
- #initialize_app ⇒ Object
- #initialize_db ⇒ Object
- #initialize_git_repo ⇒ Object
- #install_dependencies ⇒ Object
- #setup ⇒ Object
- #uuid_setup ⇒ Object
Class Method Details
.source_root ⇒ Object
20 21 22 |
# File 'lib/natra/generators/app/app_generator.rb', line 20 def self.source_root File.(File.join(File.dirname(__FILE__), 'templates')) end |
Instance Method Details
#create_app_directory ⇒ Object
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_spec ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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_docker ⇒ Object
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_compose ⇒ Object
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_directories ⇒ Object
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_gemfile ⇒ Object
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_gitignore ⇒ Object
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_guardfile ⇒ Object
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_directory ⇒ Object
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_rakefile ⇒ Object
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_readme ⇒ Object
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_config ⇒ Object
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_initializer ⇒ Object
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_rspec ⇒ Object
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_rubocop ⇒ Object
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_gemset ⇒ Object
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_secrets ⇒ Object
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_file ⇒ Object
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_helper ⇒ Object
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_support ⇒ Object
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_app ⇒ Object
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_db ⇒ Object
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_repo ⇒ Object
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_dependencies ⇒ Object
137 138 139 |
# File 'lib/natra/generators/app/app_generator.rb', line 137 def install_dependencies inside(@app_path) { run('bundle') if @bundle } end |
#setup ⇒ Object
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 .each { |key, value| instance_variable_set "@#{key}".to_sym, value } end |
#uuid_setup ⇒ Object
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 |