Class: Framework::ApplicationGenerator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Framework::ApplicationGenerator
- Includes:
- Thor::Actions
- Defined in:
- lib/framework/generators/application_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_application_config ⇒ Object
- #create_base_directories ⇒ Object
- #create_database_config ⇒ Object
- #create_environment ⇒ Object
- #create_gemfile ⇒ Object
- #create_rakefile ⇒ Object
- #create_readme ⇒ Object
- #create_sample_initializers ⇒ Object
- #create_sample_tasks ⇒ Object
Class Method Details
.source_root ⇒ Object
10 11 12 |
# File 'lib/framework/generators/application_generator.rb', line 10 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#create_application_config ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/framework/generators/application_generator.rb', line 27 def create_application_config create_file 'config/application.yml' do <<-CONFIG.strip_heredoc development: &common enable_logging: yes autoload_paths: - app/models default_timezone: 'Pacific Time (US & Canada)' test: <<: *common enable_logging: no staging: <<: *common production: <<: *common enable_logging: no CONFIG end end |
#create_base_directories ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/framework/generators/application_generator.rb', line 14 def create_base_directories empty_directory 'app/models' empty_directory 'app/models/concerns' create_file 'app/models/concerns/.keep' empty_directory 'lib' create_file 'lib/.keep' empty_directory 'db' empty_directory 'db/migrate' create_file 'db/migrate/.keep' end |
#create_database_config ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/framework/generators/application_generator.rb', line 50 def create_database_config db_name = name.underscore create_file 'config/databases.yml' do <<-CONFIG.strip_heredoc # Defult database is used by default. # Any models locating at app/models root directory will point to this database by default. default: development: &common adapter: postgresql username: password: database: #{db_name}_development min_messages: WARNING reconnect: true pool: 5 encoding: unicode host: localhost test: <<: *common database: #{db_name}_test production: <<: *common database: #{db_name}_production second_one: development: &common adapter: postgresql username: password: database: second_sample_development min_messages: WARNING reconnect: true pool: 5 encoding: unicode host: localhost test: <<: *common database: second_sample_test production: <<: *common database: second_sample_production CONFIG end end |
#create_environment ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/framework/generators/application_generator.rb', line 100 def create_environment create_file 'config/environment.rb' do <<-CONFIG.strip_heredoc # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) require 'framework' Bundler.require(:default, Framework.env) Framework::Application.new do |app| app.init! end CONFIG end end |
#create_gemfile ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/framework/generators/application_generator.rb', line 118 def create_gemfile create_file 'Gemfile' do <<-CONFIG.strip_heredoc source 'https://rubygems.org' gem 'framework', '#{Framework::VERSION}' gem 'pg' CONFIG end end |
#create_rakefile ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/framework/generators/application_generator.rb', line 129 def create_rakefile create_file 'Rakefile' do <<-CONFIG.strip_heredoc # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require 'framework' require 'framework/rake' Dir["\#{Dir.pwd}/app/tasks/**/*.rake"].each(&method(:load)) CONFIG end end |
#create_readme ⇒ Object
164 165 166 |
# File 'lib/framework/generators/application_generator.rb', line 164 def create_readme create_file 'README.md', "This app utilizes Framework v#{Framework::VERSION} and rocks MIT license." end |
#create_sample_initializers ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'lib/framework/generators/application_generator.rb', line 154 def create_sample_initializers empty_directory 'config/initializers' create_file 'config/initializers/time_zone.rb' do <<-CONFIG.strip_heredoc # Sample usage of application config Time.zone = Framework.app.config['default_timezone'] CONFIG end end |
#create_sample_tasks ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/framework/generators/application_generator.rb', line 143 def create_sample_tasks empty_directory 'app/tasks' create_file 'app/tasks/hello.rake' do <<-RAKE.strip_heredoc task hello: :environment do Framework::Logger.disappointment("Hello from: Framework v#{Framework::VERSION}") end RAKE end end |