padrino-gen 0.16.0.pre4 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/bin/padrino-gen +4 -4
  4. data/lib/padrino-gen/command.rb +2 -2
  5. data/lib/padrino-gen/generators/actions.rb +68 -64
  6. data/lib/padrino-gen/generators/app/app.rb.tt +6 -6
  7. data/lib/padrino-gen/generators/app.rb +19 -19
  8. data/lib/padrino-gen/generators/cli.rb +16 -19
  9. data/lib/padrino-gen/generators/component.rb +18 -19
  10. data/lib/padrino-gen/generators/components/actions.rb +42 -42
  11. data/lib/padrino-gen/generators/components/mocks/mocha.rb +7 -7
  12. data/lib/padrino-gen/generators/components/mocks/rr.rb +7 -7
  13. data/lib/padrino-gen/generators/components/orms/activerecord.rb +158 -156
  14. data/lib/padrino-gen/generators/components/orms/couchrest.rb +33 -33
  15. data/lib/padrino-gen/generators/components/orms/datamapper.rb +108 -103
  16. data/lib/padrino-gen/generators/components/orms/dynamoid.rb +40 -40
  17. data/lib/padrino-gen/generators/components/orms/minirecord.rb +114 -114
  18. data/lib/padrino-gen/generators/components/orms/mongoid.rb +65 -65
  19. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +20 -20
  20. data/lib/padrino-gen/generators/components/orms/mongomatic.rb +63 -59
  21. data/lib/padrino-gen/generators/components/orms/ohm.rb +49 -47
  22. data/lib/padrino-gen/generators/components/orms/ripple.rb +45 -45
  23. data/lib/padrino-gen/generators/components/orms/sequel.rb +51 -46
  24. data/lib/padrino-gen/generators/components/renderers/erb.rb +1 -1
  25. data/lib/padrino-gen/generators/components/renderers/liquid.rb +1 -1
  26. data/lib/padrino-gen/generators/components/scripts/dojo.rb +6 -6
  27. data/lib/padrino-gen/generators/components/scripts/extcore.rb +6 -6
  28. data/lib/padrino-gen/generators/components/scripts/jquery.rb +6 -6
  29. data/lib/padrino-gen/generators/components/scripts/mootools.rb +6 -6
  30. data/lib/padrino-gen/generators/components/scripts/prototype.rb +8 -8
  31. data/lib/padrino-gen/generators/components/stylesheets/compass.rb +1 -1
  32. data/lib/padrino-gen/generators/components/stylesheets/less.rb +4 -4
  33. data/lib/padrino-gen/generators/components/tests/bacon.rb +66 -66
  34. data/lib/padrino-gen/generators/components/tests/cucumber.rb +61 -61
  35. data/lib/padrino-gen/generators/components/tests/minitest.rb +70 -70
  36. data/lib/padrino-gen/generators/components/tests/rspec.rb +74 -74
  37. data/lib/padrino-gen/generators/components/tests/shoulda.rb +72 -72
  38. data/lib/padrino-gen/generators/components/tests/testunit.rb +69 -69
  39. data/lib/padrino-gen/generators/controller.rb +16 -17
  40. data/lib/padrino-gen/generators/helper.rb +8 -9
  41. data/lib/padrino-gen/generators/mailer.rb +8 -9
  42. data/lib/padrino-gen/generators/migration.rb +6 -6
  43. data/lib/padrino-gen/generators/model.rb +20 -21
  44. data/lib/padrino-gen/generators/plugin.rb +9 -9
  45. data/lib/padrino-gen/generators/project/config/apps.rb.tt +4 -4
  46. data/lib/padrino-gen/generators/project/config/boot.rb +2 -2
  47. data/lib/padrino-gen/generators/project/config.ru +1 -1
  48. data/lib/padrino-gen/generators/project.rb +49 -51
  49. data/lib/padrino-gen/generators/runner.rb +25 -24
  50. data/lib/padrino-gen/generators/task.rb +7 -8
  51. data/lib/padrino-gen/generators/templates/Gemfile.tt +5 -5
  52. data/lib/padrino-gen/generators/templates/controller.rb.tt +3 -3
  53. data/lib/padrino-gen/generators/templates/mailer.rb.tt +15 -15
  54. data/lib/padrino-gen/generators/templates/project_bin.tt +1 -1
  55. data/lib/padrino-gen/generators/templates/task.rb.tt +1 -1
  56. data/lib/padrino-gen/padrino-tasks/activerecord.rb +152 -160
  57. data/lib/padrino-gen/padrino-tasks/database.rb +2 -2
  58. data/lib/padrino-gen/padrino-tasks/datamapper.rb +31 -31
  59. data/lib/padrino-gen/padrino-tasks/minirecord.rb +3 -3
  60. data/lib/padrino-gen/padrino-tasks/mongoid.rb +39 -41
  61. data/lib/padrino-gen/padrino-tasks/mongomapper.rb +18 -14
  62. data/lib/padrino-gen/padrino-tasks/sequel.rb +28 -28
  63. data/lib/padrino-gen/padrino-tasks/sql-helpers.rb +45 -45
  64. data/lib/padrino-gen.rb +4 -4
  65. data/padrino-gen.gemspec +19 -19
  66. data/test/fixtures/admin_template.rb +5 -5
  67. data/test/fixtures/database_template.rb +19 -22
  68. data/test/fixtures/example_template.rb +8 -8
  69. data/test/fixtures/git_template.rb +2 -2
  70. data/test/fixtures/plugin_template.rb +3 -3
  71. data/test/fixtures/rake_template.rb +5 -5
  72. data/test/helper.rb +23 -21
  73. data/test/test_app_generator.rb +13 -13
  74. data/test/test_cli.rb +4 -5
  75. data/test/test_component_generator.rb +17 -17
  76. data/test/test_controller_generator.rb +62 -63
  77. data/test/test_generator.rb +6 -6
  78. data/test/test_helper_generator.rb +23 -24
  79. data/test/test_mailer_generator.rb +7 -7
  80. data/test/test_migration_generator.rb +31 -31
  81. data/test/test_model_generator.rb +80 -80
  82. data/test/test_plugin_generator.rb +35 -36
  83. data/test/test_project_generator.rb +171 -169
  84. data/test/test_sql_helpers.rb +49 -50
  85. data/test/test_task_generator.rb +13 -13
  86. metadata +10 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c16d8b651e1f5faa5fd244d55d2c73d09d0252029189aae3a2f1a278d15388fc
4
- data.tar.gz: 89df07375d0094ddeaee23c69403d739f5162b440147f1061113f4f31f1ceab7
3
+ metadata.gz: 0ef1607122ad5b56fe5ba1bdc2db945c80d3cc1220f92ef13b7b470155891bf0
4
+ data.tar.gz: bdec4526dc3a7ce15e61c90c16654b443ba426538c17d9a382b61eed2eea1ec5
5
5
  SHA512:
6
- metadata.gz: 1bd268fffe75c20acce67e286adc98be8b57e288ee69d5426220ecab77fd4792127f9eb77f9e27d0e0ec857ad0067950f9b3e50f6dd0ff6e48ba7a64a0d014b6
7
- data.tar.gz: 897f766bb9e89d595073134cdfaee219ea6504dd24f36616abff28a9155834ea714e6f2d30a9cdf0c15b2ef35f1b4f17c3fb951dbf57ccbc98d72e2b75a54b1c
6
+ metadata.gz: 9fe392bbf78f7a083179eb9a205c0a1214cbcc7209cd65836de5dc8d7a354bd1ea9a0311d129c74a6aca392b0bfde3fe2837a84bc94ee3f26c8334e01565e960
7
+ data.tar.gz: e9f430ef47d913add05e65a5557a55d45f138388e5050705bd5a5659d6b61a2449c1b4216e58ad4bce22aaf65a7fa57a7fde6a1968de0b31f45d01b20ff7f376
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
1
+ require_relative '../gem_rake_helper'
data/bin/padrino-gen CHANGED
@@ -2,12 +2,12 @@
2
2
  require 'padrino-core/cli/binstub'
3
3
  Padrino.replace_with_binstub('padrino-gen')
4
4
 
5
- padrino_gen_path = File.expand_path('../../lib', __FILE__)
6
- $:.unshift(padrino_gen_path) if File.directory?(padrino_gen_path) && !$:.include?(padrino_gen_path)
5
+ padrino_gen_path = File.expand_path('../lib', __dir__)
6
+ $LOAD_PATH.unshift(padrino_gen_path) if File.directory?(padrino_gen_path) && !$LOAD_PATH.include?(padrino_gen_path)
7
7
 
8
8
  # We try to load the vendored padrino-core if exist (useful also for --dev mode)
9
- padrino_core_path = File.expand_path('../../../padrino-core/lib', __FILE__)
10
- $:.unshift(padrino_core_path) if File.directory?(padrino_core_path) && !$:.include?(padrino_core_path)
9
+ padrino_core_path = File.expand_path('../../padrino-core/lib', __dir__)
10
+ $LOAD_PATH.unshift(padrino_core_path) if File.directory?(padrino_core_path) && !$LOAD_PATH.include?(padrino_core_path)
11
11
 
12
12
  require 'padrino-gen'
13
13
  require 'padrino-gen/generators/cli'
@@ -12,7 +12,7 @@ module Padrino
12
12
  # Padrino.bin_gen(:app, name.to_s, "-r=#{destination_root}")
13
13
  #
14
14
  def self.bin_gen(*args)
15
- @_padrino_gen_bin ||= [Padrino.ruby_command, File.expand_path("../../../bin/padrino-gen", __FILE__)]
16
- system *@_padrino_gen_bin, *args
15
+ @_padrino_gen_bin ||= [Padrino.ruby_command, File.expand_path('../../bin/padrino-gen', __dir__)]
16
+ system(*@_padrino_gen_bin, *args)
17
17
  end
18
18
  end
@@ -3,11 +3,13 @@ require 'pathname'
3
3
  module Padrino
4
4
  module Generators
5
5
  # Raised when an application does not have a resolved root path.
6
- class AppRootNotFound < RuntimeError; end
6
+ class AppRootNotFound < RuntimeError; end
7
+
7
8
  ##
8
9
  # Default helper name for use in tiny app skeleton generator.
9
10
  #
10
- DEFAULT_HELPER_NAME = "Helper".freeze
11
+ DEFAULT_HELPER_NAME = 'Helper'.freeze
12
+
11
13
  ##
12
14
  # Common actions needed to support project and component generation.
13
15
  #
@@ -15,6 +17,7 @@ module Padrino
15
17
  def self.included(base)
16
18
  base.extend(ClassMethods)
17
19
  end
20
+
18
21
  ##
19
22
  # Avoids editing destination file if it does not exist.
20
23
  #
@@ -36,7 +39,7 @@ module Padrino
36
39
  # execute_component_setup(:mock, 'rr')
37
40
  #
38
41
  def execute_component_setup(component, choice)
39
- return true && say_status(:skipping, "#{component} component...") if choice.to_s == 'none'
42
+ return say_status(:skipping, "#{component} component...") if choice.to_s == 'none'
40
43
  say_status(:applying, "#{choice} (#{component})...")
41
44
  apply_component_for(choice, component)
42
45
  send("setup_#{component}") if respond_to?("setup_#{component}")
@@ -54,8 +57,8 @@ module Padrino
54
57
  # apply_component_for('rr', :mock)
55
58
  #
56
59
  def apply_component_for(choice, component)
57
- # I need to override Thor#apply because for unknow reason :verbose => false break tasks.
58
- path = File.expand_path(File.dirname(__FILE__) + "/components/#{component.to_s.pluralize}/#{choice}.rb")
60
+ # I need to override Thor#apply because for unknown reason verbose: false break tasks.
61
+ path = File.expand_path(__dir__ + "/components/#{component.to_s.pluralize}/#{choice}.rb")
59
62
  say_status :apply, "#{component.to_s.pluralize}/#{choice}"
60
63
  shell.padding += 1
61
64
  instance_eval(File.read(path))
@@ -75,8 +78,8 @@ module Padrino
75
78
  # include_component_module_for(:mock)
76
79
  # include_component_module_for(:mock, 'rr')
77
80
  #
78
- def include_component_module_for(component, choice=nil)
79
- choice = fetch_component_choice(component) unless choice
81
+ def include_component_module_for(component, choice = nil)
82
+ choice ||= fetch_component_choice(component)
80
83
  return false if choice.to_s == 'none'
81
84
  apply_component_for(choice, component)
82
85
  end
@@ -113,7 +116,7 @@ module Padrino
113
116
  path = destination_root('.components')
114
117
  config = retrieve_component_config(path)
115
118
  config[key] = value
116
- create_file(path, :force => true) { config.to_yaml }
119
+ create_file(path, force: true) { config.to_yaml }
117
120
  value
118
121
  end
119
122
 
@@ -127,7 +130,7 @@ module Padrino
127
130
  #
128
131
  # @example
129
132
  # retrieve_component_config(...)
130
- # # => { :mock => 'rr', :test => 'rspec', ... }
133
+ # # => { mock: 'rr', test: 'rspec', ... }
131
134
  #
132
135
  def retrieve_component_config(target)
133
136
  YAML.load_file(target)
@@ -149,7 +152,7 @@ module Padrino
149
152
  choice = options[component]
150
153
  until valid_choice?(component, choice)
151
154
  say("Option for --#{component} '#{choice}' is not available.", :red)
152
- choice = ask("Please enter a valid option for #{component}:", :limited_to => choices)
155
+ choice = ask("Please enter a valid option for #{component}:", limited_to: choices)
153
156
  end
154
157
  choice
155
158
  end
@@ -184,9 +187,9 @@ module Padrino
184
187
  def store_component_config(destination, opts = {})
185
188
  components = @_components || options
186
189
  create_file(destination, opts) do
187
- self.class.component_types.inject({}) { |result, comp|
188
- result[comp] = components[comp].to_s; result
189
- }.to_yaml
190
+ self.class.component_types.each_with_object({}) do |comp, result|
191
+ result[comp] = components[comp].to_s
192
+ end.to_yaml
190
193
  end
191
194
  end
192
195
 
@@ -217,7 +220,7 @@ module Padrino
217
220
  #
218
221
  def already_exists?(name, project_name = nil)
219
222
  project_name = project_name ? (Object.const_get(project_name) rescue nil) : nil
220
- Object.const_defined?(name) || (project_name && project_name.const_defined?(name))
223
+ Object.const_defined?(name) || project_name&.const_defined?(name)
221
224
  end
222
225
 
223
226
  ##
@@ -232,7 +235,7 @@ module Padrino
232
235
  # invalid_fields ['foo:bar', 'hello:world']
233
236
  #
234
237
  def invalid_fields(fields)
235
- results = fields.select { |field| field.split(":").first =~ /\W/ }
238
+ results = fields.select { |field| field.split(':').first =~ /\W/ }
236
239
  results.empty? ? nil : results
237
240
  end
238
241
 
@@ -258,20 +261,21 @@ module Padrino
258
261
  # @example
259
262
  # fetch_project_name
260
263
  #
261
- def fetch_project_name(app='app')
262
- app_path = destination_root(app, 'app.rb')
264
+ def fetch_project_name(app = 'app')
265
+ _app_path = destination_root(app, 'app.rb')
263
266
  @project_name = fetch_component_choice(:namespace) if @project_name.empty?
264
267
  @project_name ||= begin
265
- say "Autodetecting project namespace using folder name.", :red
266
- say ""
267
268
  detected_namespace = File.basename(destination_root('.')).gsub(/\W/, '_').camelize
268
- say(<<-WARNING, :red)
269
- From v0.11.0 on, applications should have a `namespace` setting
270
- in their .components file. Please include a line like the following
271
- in your .components file:
272
- WARNING
269
+
270
+ say 'Autodetecting project namespace using folder name.', :red
271
+ say ''
272
+ say <<~WARNING, :red
273
+ From v0.11.0 on, applications should have a `namespace` setting
274
+ in their .components file. Please include a line like the following
275
+ in your .components file:
276
+ WARNING
273
277
  say "\t:namespace: #{detected_namespace}", :yellow
274
- say ""
278
+ say ''
275
279
 
276
280
  detected_namespace
277
281
  end
@@ -288,7 +292,7 @@ WARNING
288
292
  # @example
289
293
  # fetch_app_name('subapp')
290
294
  #
291
- def fetch_app_name(app='app')
295
+ def fetch_app_name(app = 'app')
292
296
  app_path = destination_root(app, 'app.rb')
293
297
  @app_name ||= File.read(app_path).scan(/class\s(.*?)\s</).flatten[0]
294
298
  end
@@ -303,8 +307,8 @@ WARNING
303
307
  #
304
308
  # @example
305
309
  # require_dependencies('active_record')
306
- # require_dependencies('mocha', 'bacon', :group => 'test')
307
- # require_dependencies('json', :version => ">=1.2.3")
310
+ # require_dependencies('mocha', 'bacon', group: 'test')
311
+ # require_dependencies('json', version: ">=1.2.3")
308
312
  #
309
313
  def require_dependencies(*gem_names)
310
314
  options = gem_names.last.is_a?(Hash) ? gem_names.pop : {}
@@ -321,17 +325,17 @@ WARNING
321
325
  #
322
326
  # @example
323
327
  # insert_into_gemfile(name)
324
- # insert_into_gemfile(name, :group => 'test', :require => 'foo')
325
- # insert_into_gemfile(name, :group => 'test', :version => ">1.2.3")
328
+ # insert_into_gemfile(name, group: 'test', require: 'foo')
329
+ # insert_into_gemfile(name, group: 'test', version: ">1.2.3")
326
330
  #
327
- def insert_into_gemfile(name, options={})
331
+ def insert_into_gemfile(name, options = {})
328
332
  after_pattern = options[:group] ? "#{options[:group].to_s.capitalize} requirements\n" : "Component requirements\n"
329
333
  version = options.delete(:version)
330
- gem_options = options.map { |k, v| k.to_s == 'require' && [true,false].include?(v) ? ":#{k} => #{v}" : ":#{k} => '#{v}'" }.join(", ")
334
+ gem_options = options.map { |k, v| k.to_s == 'require' && [true, false].include?(v) ? "#{k}: #{v}" : "#{k}: '#{v}'" }.join(', ')
331
335
  write_option = gem_options.empty? ? '' : ", #{gem_options}"
332
336
  write_version = version ? ", '#{version}'" : ''
333
337
  include_text = "gem '#{name}'" << write_version << write_option << "\n"
334
- inject_into_file('Gemfile', include_text, :after => after_pattern)
338
+ inject_into_file('Gemfile', include_text, after: after_pattern)
335
339
  end
336
340
 
337
341
  ##
@@ -346,7 +350,7 @@ WARNING
346
350
  # insert_hook("DataMapper.finalize", :after_load)
347
351
  #
348
352
  def insert_hook(include_text, where)
349
- inject_into_file('config/boot.rb', " #{include_text}\n", :after => "Padrino.#{where} do\n")
353
+ inject_into_file('config/boot.rb', " #{include_text}\n", after: "Padrino.#{where} do\n")
350
354
  end
351
355
 
352
356
  ##
@@ -358,9 +362,9 @@ WARNING
358
362
  # @example
359
363
  # insert_middleware(ActiveRecord::ConnectionAdapters::ConnectionManagement)
360
364
  #
361
- def insert_middleware(include_text, app=nil)
365
+ def insert_middleware(include_text, app = nil)
362
366
  name = app || (options[:name] ? @app_name.downcase : 'app')
363
- inject_into_file("#{name}/app.rb", " use #{include_text}\n", :after => "Padrino::Application\n")
367
+ inject_into_file("#{name}/app.rb", " use #{include_text}\n", after: "Padrino::Application\n")
364
368
  end
365
369
 
366
370
  ##
@@ -375,11 +379,11 @@ WARNING
375
379
  # initializer(:test, "some stuff here")
376
380
  # #=> generates 'lib/test_init.rb'
377
381
  #
378
- def initializer(name, data=nil)
382
+ def initializer(name, data = nil)
379
383
  @_init_name, @_init_data = name, data
380
384
  register = data ? " register #{name.to_s.underscore.camelize}Initializer\n" : " register #{name}\n"
381
- inject_into_file destination_root("/app/app.rb"), register, :after => "Padrino::Application\n"
382
- template "templates/initializer.rb.tt", destination_root("/config/initializers/#{name}.rb") if data
385
+ inject_into_file destination_root('/app/app.rb'), register, after: "Padrino::Application\n"
386
+ template 'templates/initializer.rb.tt', destination_root("/config/initializers/#{name}.rb") if data
383
387
  end
384
388
 
385
389
  ##
@@ -409,8 +413,8 @@ WARNING
409
413
  #
410
414
  def require_contrib(contrib)
411
415
  insert_into_gemfile 'padrino-contrib'
412
- contrib = "require '" + File.join("padrino-contrib", contrib) + "'\n"
413
- inject_into_file destination_root("/config/boot.rb"), contrib, :before => "\nPadrino.load!"
416
+ contrib = "require '#{File.join('padrino-contrib', contrib)}'\n"
417
+ inject_into_file destination_root('/config/boot.rb'), contrib, before: "\nPadrino.load!"
414
418
  end
415
419
 
416
420
  ##
@@ -445,14 +449,14 @@ WARNING
445
449
  # check_app_existence 'app'
446
450
  #
447
451
  def check_app_existence(app)
448
- unless File.exist?(destination_root(app))
449
- say
450
- say "================================================================="
451
- say "Unable to locate '#{app.underscore.camelize}' application "
452
- say "================================================================="
453
- say
454
- raise SystemExit
455
- end
452
+ return if File.exist?(destination_root(app))
453
+
454
+ say
455
+ say '================================================================='
456
+ say "Unable to locate '#{app.underscore.camelize}' application "
457
+ say '================================================================='
458
+ say
459
+ raise SystemExit
456
460
  end
457
461
 
458
462
  ##
@@ -467,7 +471,7 @@ WARNING
467
471
  # app_skeleton 'some_app'
468
472
  # app_skeleton 'sub_app', true
469
473
  #
470
- def app_skeleton(app, tiny=false)
474
+ def app_skeleton(app, tiny = false)
471
475
  directory('app/', destination_root(app))
472
476
  if tiny
473
477
  template 'templates/controller.rb.tt', destination_root(app, 'controllers.rb')
@@ -497,9 +501,9 @@ WARNING
497
501
  #
498
502
  def valid_constant?(name)
499
503
  if name =~ /^\d/
500
- fail ::NameError, "Constant name #{name} cannot start with numbers"
504
+ raise ::NameError, "Constant name #{name} cannot start with numbers"
501
505
  elsif name =~ /^\W/
502
- fail ::NameError, "Constant name #{name} cannot start with non-word character"
506
+ raise ::NameError, "Constant name #{name} cannot start with non-word character"
503
507
  end
504
508
  end
505
509
 
@@ -515,7 +519,7 @@ WARNING
515
519
  #
516
520
  def validate_namespace(name)
517
521
  valid_constant? name
518
- name.match(/^[[:alnum:]_]+$/) || fail(::NameError, "Namespace '#{name}' must consist only of alphanumeric characters or '_'")
522
+ name.match(/^[[:alnum:]_]+$/) || raise(::NameError, "Namespace '#{name}' must consist only of alphanumeric characters or '_'")
519
523
  end
520
524
 
521
525
  ##
@@ -554,13 +558,13 @@ WARNING
554
558
  # Additional parameters for component choice.
555
559
  #
556
560
  # @example
557
- # component_option :test, "Testing framework", :aliases => '-t', :choices => [:bacon, :shoulda]
561
+ # component_option :test, 'Testing framework', aliases: '-t', choices: [:bacon, :shoulda]
558
562
  #
559
563
  def component_option(name, caption, options = {})
560
- (@component_types ||= []) << name # TODO use ordered hash and combine with choices below
561
- (@available_choices ||= Hash.new)[name] = options[:choices]
564
+ (@component_types ||= []) << name # TODO: use ordered hash and combine with choices below
565
+ (@available_choices ||= {})[name] = options[:choices]
562
566
  description = "The #{caption} component (#{options[:choices].join(', ')}, none)"
563
- class_option name, :default => options[:default] || options[:choices].first, :aliases => options[:aliases], :desc => description
567
+ class_option name, default: options[:default] || options[:choices].first, aliases: options[:aliases], desc: description
564
568
  end
565
569
 
566
570
  ##
@@ -568,15 +572,15 @@ WARNING
568
572
  #
569
573
  def defines_component_options(options = {})
570
574
  [
571
- [ :orm, 'database engine', { :aliases => '-d', :default => :none }],
572
- [ :test, 'testing framework', { :aliases => '-t', :default => :none }],
573
- [ :mock, 'mocking library', { :aliases => '-m', :default => :none }],
574
- [ :script, 'javascript library', { :aliases => '-s', :default => :none }],
575
- [ :renderer, 'template engine', { :aliases => '-e', :default => :none }],
576
- [ :stylesheet, 'stylesheet engine', { :aliases => '-c', :default => :none }]
575
+ [:orm, 'database engine', { aliases: '-d', default: :none }],
576
+ [:test, 'testing framework', { aliases: '-t', default: :none }],
577
+ [:mock, 'mocking library', { aliases: '-m', default: :none }],
578
+ [:script, 'javascript library', { aliases: '-s', default: :none }],
579
+ [:renderer, 'template engine', { aliases: '-e', default: :none }],
580
+ [:stylesheet, 'stylesheet engine', { aliases: '-c', default: :none }]
577
581
  ].each do |name, caption, opts|
578
582
  opts[:default] = '' if options[:default] == false
579
- component_option name, caption, opts.merge(:choices => Dir["#{File.dirname(__FILE__)}/components/#{name.to_s.pluralize}/*.rb"].map{|lib| File.basename(lib, '.rb').to_sym})
583
+ component_option name, caption, opts.merge(choices: Dir["#{__dir__}/components/#{name.to_s.pluralize}/*.rb"].map { |lib| File.basename(lib, '.rb').to_sym })
580
584
  end
581
585
  end
582
586
 
@@ -16,14 +16,14 @@ module <%= @project_name %>
16
16
  #
17
17
  # set :cache, Padrino::Cache.new(:LRUHash) # Keeps cached values in memory
18
18
  # set :cache, Padrino::Cache.new(:Memcached) # Uses default server at localhost
19
- # set :cache, Padrino::Cache.new(:Memcached, :server => '127.0.0.1:11211', :exception_retry_limit => 1)
20
- # set :cache, Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
19
+ # set :cache, Padrino::Cache.new(:Memcached, server: '127.0.0.1:11211', exception_retry_limit: 1)
20
+ # set :cache, Padrino::Cache.new(:Memcached, backend: memcached_or_dalli_instance)
21
21
  # set :cache, Padrino::Cache.new(:Redis) # Uses default server at localhost
22
- # set :cache, Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
23
- # set :cache, Padrino::Cache.new(:Redis, :backend => redis_instance)
22
+ # set :cache, Padrino::Cache.new(:Redis, host: '127.0.0.1', port: 6379, db: 0)
23
+ # set :cache, Padrino::Cache.new(:Redis, backend: redis_instance)
24
24
  # set :cache, Padrino::Cache.new(:Mongo) # Uses default server at localhost
25
- # set :cache, Padrino::Cache.new(:Mongo, :backend => mongo_client_instance)
26
- # set :cache, Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
25
+ # set :cache, Padrino::Cache.new(:Mongo, backend: mongo_client_instance)
26
+ # set :cache, Padrino::Cache.new(:File, dir: Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
27
27
  #
28
28
 
29
29
  ##
@@ -1,27 +1,25 @@
1
1
  module Padrino
2
2
  module Generators
3
-
4
3
  ##
5
4
  # Responsible for applications within a Padrino project. Creates and mounts
6
5
  # the application and gives the user related information.
7
6
  #
8
7
  class App < Thor::Group
9
-
10
8
  Padrino::Generators.add_generator(:app, self)
11
9
 
12
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
13
- def self.banner; "padrino-gen app [name]"; end
10
+ def self.source_root; __dir__; end
11
+ def self.banner; 'padrino-gen app [name]'; end
14
12
 
15
13
  include Thor::Actions
16
14
  include Padrino::Generators::Actions
17
15
 
18
16
  desc "Description:\n\n\tpadrino-gen app generates a new Padrino application"
19
- argument :name, :desc => 'The name of your padrino application'
20
- class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
21
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
22
- class_option :tiny, :desc => 'Generate tiny app skeleton', :aliases => '-i', :default => false, :type => :boolean
23
- class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
24
- class_option :force, :desc => 'Generate app files if app already exists', :aliases => '-f', :default => false, :type => :boolean
17
+ argument :name, desc: 'The name of your padrino application'
18
+ class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
19
+ class_option :destroy, aliases: '-d', default: false, type: :boolean
20
+ class_option :tiny, desc: 'Generate tiny app skeleton', aliases: '-i', default: false, type: :boolean
21
+ class_option :namespace, desc: 'The name space of your padrino project', aliases: '-n', default: '', type: :string
22
+ class_option :force, desc: 'Generate app files if app already exists', aliases: '-f', default: false, type: :boolean
25
23
 
26
24
  # Show help if no ARGV given
27
25
  require_arguments!
@@ -34,32 +32,34 @@ module Padrino
34
32
  underscore_name = name.gsub(/\W/, '_')
35
33
  @app_folder = underscore_name.underscore
36
34
  @app_name = underscore_name.camelize
35
+
37
36
  if in_app_root?
38
37
  @project_name = options[:namespace].underscore.camelize
39
38
  @project_name = fetch_project_name(@app_folder) if @project_name.empty?
40
39
 
41
- if options[:destroy]
42
- self.behavior = :revoke
43
- else
44
- unless options[:force]
40
+ if already_exists?(@app_name, @project_name)
41
+ if options[:destroy]
42
+ self.behavior = :revoke
43
+ elsif !options[:force]
45
44
  say "#{@app_name} already exists."
46
- say "Please, change the name."
45
+ say 'Please, change the name.'
47
46
  return
48
47
  end
49
- end if already_exists?(@app_name, @project_name)
48
+ end
50
49
 
51
50
  lowercase_app_folder = @app_folder.downcase
52
51
  app_skeleton(lowercase_app_folder, options[:tiny])
53
52
  empty_directory destination_root("public/#{lowercase_app_folder}")
54
53
 
55
- mount_command = "\nPadrino.mount('#{@project_name}::#{@app_name}', :app_file => Padrino.root('#{lowercase_app_folder}/app.rb')).to('/#{lowercase_app_folder}')\n"
56
- if File.read(destination_root('config/apps.rb')).match(/^Padrino.mount.*\.to\('\/'\)$/)
57
- inject_into_file destination_root('config/apps.rb'), mount_command, :before => /^Padrino.mount.*\.to\('\/'\)$/
54
+ mount_command = "\nPadrino.mount('#{@project_name}::#{@app_name}', app_file: Padrino.root('#{lowercase_app_folder}/app.rb')).to('/#{lowercase_app_folder}')\n"
55
+ if File.read(destination_root('config/apps.rb')).match(%r{^Padrino.mount.*\.to\('/'\)$})
56
+ inject_into_file destination_root('config/apps.rb'), mount_command, before: %r{^Padrino.mount.*\.to\('/'\)$}
58
57
  else
59
58
  append_file destination_root('config/apps.rb'), mount_command
60
59
  end
61
60
 
62
61
  return if self.behavior == :revoke
62
+
63
63
  say
64
64
  say '=' * 65, :green
65
65
  say "Your #{@app_name} application has been installed."
@@ -7,33 +7,30 @@ module Padrino
7
7
  # +Padrino::Generators.load_components!+ for handle 3rd party generators.
8
8
  #
9
9
  class Cli < Thor::Group
10
-
11
10
  include Thor::Actions
12
11
 
13
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
14
- class_option :help, :type => :boolean, :desc => "Show help usage"
12
+ class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
13
+ class_option :help, type: :boolean, desc: 'Show help usage'
15
14
 
16
15
  ##
17
16
  # We need to try to load boot because some of our app dependencies maybe have
18
17
  # custom generators, so is necessary know who are.
19
18
  #
20
19
  def load_boot
21
- begin
22
- ENV['PADRINO_LOG_LEVEL'] ||= 'test'
23
- ENV['BUNDLE_GEMFILE'] = File.join(options[:root], 'Gemfile') if options[:root]
24
- boot = options[:root] ? File.join(options[:root], 'config/boot.rb') : 'config/boot.rb'
25
- if File.exist?(boot)
26
- require File.expand_path(boot)
27
- else
28
- require 'padrino-support'
29
- end
30
- rescue StandardError => e
31
- puts "=> Problem loading #{boot}"
32
- puts ["=> #{e.message}", *e.backtrace].join("\n ")
33
- ensure
34
- ENV.delete('BUNDLE_GEMFILE')
35
- ENV.delete('PADRINO_LOG_LEVEL')
20
+ ENV['PADRINO_LOG_LEVEL'] ||= 'test'
21
+ ENV['BUNDLE_GEMFILE'] = File.join(options[:root], 'Gemfile') if options[:root]
22
+ boot = options[:root] ? File.join(options[:root], 'config/boot.rb') : 'config/boot.rb'
23
+ if File.exist?(boot)
24
+ require File.expand_path(boot)
25
+ else
26
+ require 'padrino-support'
36
27
  end
28
+ rescue StandardError => e
29
+ puts "=> Problem loading #{boot}"
30
+ puts ["=> #{e.message}", *e.backtrace].join("\n ")
31
+ ensure
32
+ ENV.delete('BUNDLE_GEMFILE')
33
+ ENV.delete('PADRINO_LOG_LEVEL')
37
34
  end
38
35
 
39
36
  ##
@@ -49,7 +46,7 @@ module Padrino
49
46
  args = ARGV.empty? && generator_class.require_arguments? ? ['-h'] : ARGV
50
47
  generator_class.start(args)
51
48
  else
52
- puts "Please specify generator to use (#{Padrino::Generators.mappings.keys.join(", ")})"
49
+ puts "Please specify generator to use (#{Padrino::Generators.mappings.keys.join(', ')})"
53
50
  end
54
51
  end
55
52
  end
@@ -1,15 +1,13 @@
1
1
  module Padrino
2
2
  module Generators
3
-
4
3
  ##
5
4
  # Responsible for add components within a Padrino project.
6
5
  #
7
6
  class Component < Thor::Group
8
-
9
7
  Padrino::Generators.add_generator(:component, self)
10
8
 
11
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
12
- def self.banner; "padrino-gen component [options]"; end
9
+ def self.source_root; __dir__; end
10
+ def self.banner; 'padrino-gen component [options]'; end
13
11
 
14
12
  include Thor::Actions
15
13
  include Padrino::Generators::Actions
@@ -17,11 +15,11 @@ module Padrino
17
15
 
18
16
  desc "Description:\n\n\tpadrino-gen component add components into a Padrino project"
19
17
 
20
- class_option :app, :desc => 'The application name', :aliases => '-n', :default => nil, :type => :string
21
- class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
22
- class_option :adapter, :desc => 'SQL adapter for ORM (sqlite, mysql, mysql2, mysql-gem, postgres)', :aliases => '-a', :default => 'sqlite', :type => :string
18
+ class_option :app, desc: 'The application name', aliases: '-n', default: nil, type: :string
19
+ class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
20
+ class_option :adapter, desc: 'SQL adapter for ORM (sqlite, mysql, mysql2, mysql-gem, postgres)', aliases: '-a', default: 'sqlite', type: :string
23
21
 
24
- defines_component_options :default => false
22
+ defines_component_options default: false
25
23
 
26
24
  ##
27
25
  # For each component, retrieve a valid choice and then execute the associated generator.
@@ -29,17 +27,17 @@ module Padrino
29
27
  def setup_components
30
28
  self.destination_root = options[:root]
31
29
  if in_app_root?
32
- @_components = options.class.new options.select{ |key,_| self.class.component_types.include?(key.to_sym) }
33
- @app_name = (options[:app] || "App").gsub(/\W/, '_').camelize
30
+ @_components = options.class.new(options.slice(*self.class.component_types))
31
+ @app_name = (options[:app] || 'App').gsub(/\W/, '_').camelize
34
32
  if @_components.values.delete_if(&:empty?).empty?
35
- self.class.start(["-h"])
33
+ self.class.start(['-h'])
36
34
  say
37
- say "Current Selected Components:"
35
+ say 'Current Selected Components:'
38
36
  list = []
39
37
  self.class.component_types.each do |comp|
40
38
  list << [comp, fetch_component_choice(comp)]
41
39
  end
42
- print_table(list, :indent => 2)
40
+ print_table(list, indent: 2)
43
41
  exit
44
42
  end
45
43
 
@@ -48,20 +46,21 @@ module Padrino
48
46
 
49
47
  choice = @_components[comp] = resolve_valid_choice(comp)
50
48
  existing = fetch_component_choice(comp)
51
- if existing != 'none' && existing != choice
52
- next unless yes?("Switch #{comp} to '#{choice}' from '#{existing}' ?[yes/no]:")
53
- end
49
+ ask = existing != 'none' && existing != choice
50
+ next if ask && !yes?("Switch #{comp} to '#{choice}' from '#{existing}' ?[yes/no]:")
51
+
54
52
  @project_name = fetch_component_choice(:namespace)
55
53
  if comp.to_s == 'test' && !already_exists?(@app_name, @project_name)
56
54
  say "#{@project_name}::#{@app_name} does not exist."
57
- say "Please, change app name."
55
+ say 'Please, change app name.'
58
56
  next
59
57
  end
58
+
60
59
  execute_component_setup(comp, choice)
61
60
  store_component_choice(comp, choice)
62
61
  if comp.to_s == 'orm' && choice.to_s != 'none'
63
- inject_into_file destination_root('Rakefile'), "PadrinoTasks.use(:database)\n", :before => "PadrinoTasks.init"
64
- inject_into_file destination_root('Rakefile'), "PadrinoTasks.use(#{choice.to_sym.inspect})\n", :before => "PadrinoTasks.init"
62
+ inject_into_file destination_root('Rakefile'), "PadrinoTasks.use(:database)\n", before: 'PadrinoTasks.init'
63
+ inject_into_file destination_root('Rakefile'), "PadrinoTasks.use(#{choice.to_sym.inspect})\n", before: 'PadrinoTasks.init'
65
64
  end
66
65
  end
67
66
  else