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 " development: &common\n enable_logging: yes\n autoload_paths:\n - app/models\n default_timezone: 'Pacific Time (US & Canada)'\n\n test:\n <<: *common\n enable_logging: no\n\n staging:\n <<: *common\n\n production:\n <<: *common\n enable_logging: no\n CONFIG\n end\nend\n".strip_heredoc |
#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 " # Defult database is used by default.\n # Any models locating at app/models root directory will point to this database by default.\n default:\n development: &common\n adapter: postgresql\n username:\n password:\n database: \#{db_name}_development\n min_messages: WARNING\n reconnect: true\n pool: 5\n encoding: unicode\n host: localhost\n\n test:\n <<: *common\n database: \#{db_name}_test\n\n production:\n <<: *common\n database: \#{db_name}_production\n\n second_one:\n development: &common\n adapter: postgresql\n username:\n password:\n database: second_sample_development\n min_messages: WARNING\n reconnect: true\n pool: 5\n encoding: unicode\n host: localhost\n\n test:\n <<: *common\n database: second_sample_test\n\n production:\n <<: *common\n database: second_sample_production\n CONFIG\n end\nend\n".strip_heredoc |
#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 " # Set up gems listed in the Gemfile.\n ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)\n require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])\n\n require 'framework'\n\n Bundler.require(:default, Framework.env)\n\n Framework::Application.new do |app|\n app.init!\n end\n CONFIG\n end\nend\n".strip_heredoc |
#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 " source 'https://rubygems.org'\n\n gem 'framework', '\#{Framework::VERSION}'\n gem 'pg'\n CONFIG\n end\nend\n".strip_heredoc |
#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 " # Add your own tasks in files placed in lib/tasks ending in .rake,\n # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.\n\n require 'framework'\n require 'framework/rake'\n\n Dir[\"\\\#{Dir.pwd}/app/tasks/**/*.rake\"].each(&method(:load))\n CONFIG\n end\nend\n".strip_heredoc |
#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 " # Sample usage of application config\n Time.zone = Framework.app.config['default_timezone']\n CONFIG\n end\nend\n".strip_heredoc |
#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 " task hello: :environment do\n Framework::Logger.disappointment(\"Hello from: Framework v\#{Framework::VERSION}\")\n end\n RAKE\n end\nend\n".strip_heredoc |