Class: Pineapples::AppGenerator
Constant Summary
collapse
- TEMPLATING_ENGINES =
[:erb, :haml, :slim]
Constants included
from Helpers
Helpers::RESERVED_NAMES
Constants included
from Actions
Pineapples::Actions::DEFAULT_COLOR, Pineapples::Actions::FILE_WITH_RUBY_CODE, Pineapples::Actions::TEMPLATE_EXTNAME
Instance Attribute Summary collapse
Attributes included from Actions
#behaviour
Instance Method Summary
collapse
Methods included from Settings
setting
Methods included from Helpers
#erb?, #haml?, #needs_user_model?, #slim?
#after_bundle, #copy_migration, #environment, #erb2haml, #erb2slim, #generate, #initializer, #lib, #rake, #rakefile, #route, #vendor
Methods included from Actions
#action, #append_to_file, #apply, #ask_file_collision, #bundle, #chmod, #convert_directory_to_new_hash_syntax, #convert_file_to_new_hash_syntax, #copy_file, #create_file, #current_app_dir, #dir_stack, #directory, #empty_directory, #empty_directory_with_keep_file, #find_in_source_paths, #get, #git, #gsub_file, #in_app_root, #in_root, #indent, #insert_into_file, #inside, #keep_file, #prepend_to_class, #prepend_to_file, #relative_to_app_root, #relative_to_current_app_dir, #remove_file, #ruby, #say_status, #say_title, #shell, #shell_with_app_gemset, #shell_with_clean_bundler_env, #source_paths, #source_paths_for_search, #template, #templates_root
Constructor Details
Returns a new instance of AppGenerator.
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/pineapples/app_generator.rb', line 57
def initialize(options)
@app_name = options.app_name.gsub(/\s+/, '-')
@app_root = options.app_root || File.expand_path(app_name)
@debug = options.debug || false
@pretend = options.pretend || false
@verbose = options.verbose || true
@testing = options.testing || false
@settings = self.class.settings
end
|
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
53
54
55
|
# File 'lib/pineapples/app_generator.rb', line 53
def app_name
@app_name
end
|
#app_root ⇒ Object
Returns the value of attribute app_root.
53
54
55
|
# File 'lib/pineapples/app_generator.rb', line 53
def app_root
@app_root
end
|
#settings ⇒ Object
Returns the value of attribute settings.
53
54
55
|
# File 'lib/pineapples/app_generator.rb', line 53
def settings
@settings
end
|
Instance Method Details
#ask_user_settings ⇒ Object
82
83
84
85
|
# File 'lib/pineapples/app_generator.rb', line 82
def ask_user_settings
settings[:heroku].ask_setting
settings[:template_engine].ask_setting
end
|
#convert_views ⇒ Object
231
232
233
234
235
236
237
|
# File 'lib/pineapples/app_generator.rb', line 231
def convert_views
if haml?
elsif slim?
end
end
|
#copy_example_files ⇒ Object
195
196
197
198
199
|
# File 'lib/pineapples/app_generator.rb', line 195
def copy_example_files
say_title 'Copying sample files'
template '.example.env', '.env'
copy_file '.example.rspec', '.rspec'
end
|
#create_app_files ⇒ Object
122
123
124
125
126
127
128
129
|
# File 'lib/pineapples/app_generator.rb', line 122
def create_app_files
directory 'app'
empty_directory_with_keep_file 'app/assets/fonts'
empty_directory_with_keep_file 'app/assets/images'
empty_directory_with_keep_file 'app/mailers'
empty_directory_with_keep_file 'app/models' if !needs_user_model?
end
|
#create_bin_files ⇒ Object
131
132
133
134
135
136
137
|
# File 'lib/pineapples/app_generator.rb', line 131
def create_bin_files
directory 'bin'
in_app_root do
shell 'chmod -v 755 bin'
shell 'chmod -v 644 bin/*'
end
end
|
#create_config_files ⇒ Object
139
140
141
|
# File 'lib/pineapples/app_generator.rb', line 139
def create_config_files
directory 'config'
end
|
#create_db_files ⇒ Object
143
144
145
146
147
148
149
150
151
|
# File 'lib/pineapples/app_generator.rb', line 143
def create_db_files
empty_directory 'db/migrate'
copy_migration 'enable_postgres_extensions'
copy_migration 'create_data_migrations'
if devise?
copy_migration 'devise_create_users'
copy_migration 'add_role_field_to_users' if user_role_field?
end
end
|
#create_files ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/pineapples/app_generator.rb', line 87
def create_files
create_root_files
create_app_files
create_bin_files
create_config_files
create_db_files
create_lib_files
create_public_files
create_spec_files
create_misc_folders
copy_example_files
end
|
#create_lib_files ⇒ Object
153
154
155
156
|
# File 'lib/pineapples/app_generator.rb', line 153
def create_lib_files
directory 'lib'
keep_file 'lib/assets'
end
|
#create_misc_folders ⇒ Object
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/pineapples/app_generator.rb', line 184
def create_misc_folders
empty_directory_with_keep_file 'log'
empty_directory 'tmp/pids'
inside 'vendor/assets' do
empty_directory_with_keep_file 'javascripts'
empty_directory_with_keep_file 'stylesheets'
end
end
|
#create_public_files ⇒ Object
158
159
160
|
# File 'lib/pineapples/app_generator.rb', line 158
def create_public_files
directory 'public'
end
|
#create_root_files ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/pineapples/app_generator.rb', line 100
def create_root_files
create_file '.ruby-version', Pineapples::RUBY_VERSION
create_file '.ruby-gemset', app_name
copy_file '.editor-config'
template '.example.env'
copy_file '.example.rspec'
copy_file '.gitignore'
template '.simplecov'
copy_file 'browserlist'
template 'config.ru'
template 'Gemfile'
copy_file 'Guardfile'
copy_file 'Procfile'
template 'Procfile.dev'
copy_file 'Rakefile'
template 'README.md'
if heroku?
copy_file '.buildpacks'
copy_file 'Aptfile'
end
end
|
#create_rvm_gemset ⇒ Object
214
215
216
217
|
# File 'lib/pineapples/app_generator.rb', line 214
def create_rvm_gemset
say_title 'Creating project-specific RVM gemset'
shell "rvm gemset create #{app_name}"
end
|
#create_spec_files ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/pineapples/app_generator.rb', line 162
def create_spec_files
directory 'spec'
inside 'spec' do
empty_directory_with_keep_file 'controllers'
empty_directory_with_keep_file 'features'
empty_directory_with_keep_file 'factories'
empty_directory_with_keep_file 'helpers'
empty_directory_with_keep_file 'jobs'
empty_directory_with_keep_file 'mailers'
empty_directory_with_keep_file 'models'
empty_directory_with_keep_file 'policies' if pundit?
empty_directory_with_keep_file 'presenters'
empty_directory_with_keep_file 'services'
empty_directory_with_keep_file 'lib'
empty_directory_with_keep_file 'support/features'
empty_directory_with_keep_file 'support/matchers'
empty_directory_with_keep_file 'support/mixins'
empty_directory_with_keep_file 'support/shared_examples'
end
end
|
#debug? ⇒ Boolean
268
269
270
|
# File 'lib/pineapples/app_generator.rb', line 268
def debug?
@debug
end
|
#execute? ⇒ Boolean
276
277
278
|
# File 'lib/pineapples/app_generator.rb', line 276
def execute?
!pretend?
end
|
#pretend? ⇒ Boolean
272
273
274
|
# File 'lib/pineapples/app_generator.rb', line 272
def pretend?
@pretend
end
|
#run_after_bundle_callbacks ⇒ Object
262
263
264
|
# File 'lib/pineapples/app_generator.rb', line 262
def run_after_bundle_callbacks
@after_bundle_callbacks.each(&:call)
end
|
#setup_app ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/pineapples/app_generator.rb', line 201
def setup_app
create_rvm_gemset if rvm_installed? & use_rvm?
shell_with_app_gemset 'bundle install'
setup_database
setup_gems
to_new_hash_syntax!
setup_git
end
|
#setup_database ⇒ Object
219
220
221
222
223
224
|
# File 'lib/pineapples/app_generator.rb', line 219
def setup_database
say_title 'Preparing database'
shell_with_app_gemset 'bundle exec rake db:drop' if testing?
shell_with_app_gemset 'bundle exec rake db:setup'
shell_with_app_gemset 'bundle exec rake db:migrate'
end
|
#setup_gems ⇒ Object
226
227
228
229
|
# File 'lib/pineapples/app_generator.rb', line 226
def setup_gems
shell_with_app_gemset 'rails g kaminari:views default'
erb2haml 'app/views/kaminari'
end
|
#setup_git ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/pineapples/app_generator.rb', line 245
def setup_git
if !preexisting_git_repo?
say_title 'Setting up git repo'
in_app_root do
git :init
git add: '-A .'
git commit: %(-n -m "Generated Rails #{RAILS_VERSION.gsub('~> ', '')} project via pineapples gem")
git checkout: '-b staging'
git checkout: '-b dev'
if git_repo_url?
git remote: "add origin #{git_repo_url.shellescape}"
git push: '-u origin --all'
end
end
end
end
|
#start! ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/pineapples/app_generator.rb', line 68
def start!
valid_const! && check_target!
create_app_root
create_files
setup_app
rescue Pineapples::Error => error
(debug? || ENV['PINEAPPLES_DEBUG'] == '1') ? (raise error) : say(error.message.light_red)
exit 1
end
|
#testing? ⇒ Boolean
284
285
286
|
# File 'lib/pineapples/app_generator.rb', line 284
def testing?
@testing
end
|
#to_new_hash_syntax! ⇒ Object
239
240
241
242
243
|
# File 'lib/pineapples/app_generator.rb', line 239
def to_new_hash_syntax!
say_title 'Converting Ruby hash rockets to new syntax'
convert_directory_to_new_hash_syntax 'app/views/kaminari'
end
|
#verbose? ⇒ Boolean
280
281
282
|
# File 'lib/pineapples/app_generator.rb', line 280
def verbose?
@verbose
end
|