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
@@ -4,11 +4,10 @@ module Padrino
4
4
  # Responsible for generating route helpers and associated tests within a Padrino application.
5
5
  #
6
6
  class Helper < Thor::Group
7
-
8
7
  Padrino::Generators.add_generator(:helper, self)
9
8
 
10
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
11
- def self.banner; "padrino-gen helper [name]"; end
9
+ def self.source_root; __dir__; end
10
+ def self.banner; 'padrino-gen helper [name]'; end
12
11
 
13
12
  include Thor::Actions
14
13
  include Padrino::Generators::Actions
@@ -16,12 +15,12 @@ module Padrino
16
15
 
17
16
  desc "Description:\n\n\tpadrino-gen helper generates a new Padrino helper"
18
17
 
19
- argument :name, :desc => 'The name of your padrino helper'
20
- argument :fields, :desc => 'The fields for the helper', :default => [], :type => :array
21
- class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
22
- class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
23
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
24
- class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
18
+ argument :name, desc: 'The name of your padrino helper'
19
+ argument :fields, desc: 'The fields for the helper', default: [], type: :array
20
+ class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
21
+ class_option :app, desc: 'The application destination path', aliases: '-a', default: '/app', type: :string
22
+ class_option :destroy, aliases: '-d', default: false, type: :boolean
23
+ class_option :namespace, desc: 'The name space of your padrino project', aliases: '-n', default: '', type: :string
25
24
 
26
25
  # Show help if no ARGV given
27
26
  require_arguments!
@@ -4,10 +4,9 @@ module Padrino
4
4
  # Responsible for the generating mailers and message definitions.
5
5
  #
6
6
  class Mailer < Thor::Group
7
-
8
7
  Padrino::Generators.add_generator(:mailer, self)
9
8
 
10
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
9
+ def self.source_root; __dir__; end
11
10
  def self.banner; 'padrino-gen mailer [name]'; end
12
11
 
13
12
  include Thor::Actions
@@ -16,12 +15,12 @@ module Padrino
16
15
 
17
16
  desc "Description:\n\n\tpadrino-gen mailer generates a new Padrino mailer"
18
17
 
19
- argument :name, :desc => 'The name of your padrino mailer'
20
- argument :actions, :desc => 'The delivery actions to add to your mailer', :type => :array, :default => []
21
- class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
22
- class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
23
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
24
- class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
18
+ argument :name, desc: 'The name of your padrino mailer'
19
+ argument :actions, desc: 'The delivery actions to add to your mailer', default: [], type: :array
20
+ class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
21
+ class_option :app, desc: 'The application destination path', aliases: '-a', default: '/app', type: :string
22
+ class_option :destroy, aliases: '-d', default: false, type: :boolean
23
+ class_option :namespace, desc: 'The name space of your padrino project', aliases: '-n', default: '', type: :string
25
24
 
26
25
  # Show help if no ARGV given.
27
26
  require_arguments!
@@ -42,7 +41,7 @@ module Padrino
42
41
  @actions = actions.map(&:to_sym)
43
42
  @short_name = name.to_s.gsub(/_mailer/i, '').underscore.downcase
44
43
  @mailer_basename = @short_name.underscore
45
- template "templates/mailer.rb.tt", destination_root(app, 'mailers', "#{@mailer_basename}.rb")
44
+ template 'templates/mailer.rb.tt', destination_root(app, 'mailers', "#{@mailer_basename}.rb")
46
45
  empty_directory destination_root(app, 'views', 'mailers', @mailer_basename)
47
46
  else
48
47
  say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
@@ -6,8 +6,8 @@ module Padrino
6
6
  class Migration < Thor::Group
7
7
  Padrino::Generators.add_generator(:migration, self)
8
8
 
9
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
10
- def self.banner; "padrino-gen migration [name] [fields]"; end
9
+ def self.source_root; __dir__; end
10
+ def self.banner; 'padrino-gen migration [name] [fields]'; end
11
11
 
12
12
  include Thor::Actions
13
13
  include Padrino::Generators::Actions
@@ -15,10 +15,10 @@ module Padrino
15
15
 
16
16
  desc "Description:\n\n\tpadrino-gen migration generates a new migration file"
17
17
 
18
- argument :name, :desc => 'The name of your padrino migration'
19
- argument :columns, :desc => 'The columns for the migration', :type => :array, :default => []
20
- class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
21
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
18
+ argument :name, desc: 'The name of your padrino migration'
19
+ argument :columns, desc: 'The columns for the migration', type: :array, default: []
20
+ class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
21
+ class_option :destroy, aliases: '-d', default: false, type: :boolean
22
22
 
23
23
  # Show help if no ARGV given.
24
24
  require_arguments!
@@ -6,8 +6,8 @@ module Padrino
6
6
  class Model < Thor::Group
7
7
  Padrino::Generators.add_generator(:model, self)
8
8
 
9
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
10
- def self.banner; "padrino-gen model [name] [fields]"; end
9
+ def self.source_root; __dir__; end
10
+ def self.banner; 'padrino-gen model [name] [fields]'; end
11
11
 
12
12
  include Thor::Actions
13
13
  include Padrino::Generators::Actions
@@ -15,13 +15,13 @@ module Padrino
15
15
 
16
16
  desc "Description:\n\n\tpadrino-gen model generates a new model and migration files"
17
17
 
18
- argument :name, :desc => 'The name of your padrino model'
19
- argument :fields, :desc => 'The fields for the model', :default => [], :type => :array
20
- class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
21
- class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '.', :type => :string
22
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
23
- class_option :skip_migration, :aliases => '-s', :default => false, :type => :boolean
24
- class_option :force, :desc => 'Generate model files if app already exists', :aliases => '-f', :default => false, :type => :boolean
18
+ argument :name, desc: 'The name of your padrino model'
19
+ argument :fields, desc: 'The fields for the model', default: [], type: :array
20
+ class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
21
+ class_option :app, desc: 'The application destination path', aliases: '-a', default: '.', type: :string
22
+ class_option :destroy, aliases: '-d', default: false, type: :boolean
23
+ class_option :skip_migration, aliases: '-s', default: false, type: :boolean
24
+ class_option :force, desc: 'Generate model files if app already exists', aliases: '-f', default: false, type: :boolean
25
25
 
26
26
  # Show help if no ARGV given.
27
27
  require_arguments!
@@ -35,7 +35,7 @@ module Padrino
35
35
  include_component_module_for(:test)
36
36
  migration_name = "create_#{name.pluralize.underscore}"
37
37
  apply_default_fields fields
38
- create_model_file(name, :fields => fields, :app => app)
38
+ create_model_file(name, fields: fields, app: app)
39
39
  generate_model_test(name) if test?
40
40
  create_model_migration(migration_name, name, fields) unless options[:skip_migration]
41
41
  end
@@ -51,16 +51,15 @@ module Padrino
51
51
  return false unless correct_path?
52
52
 
53
53
  check_app_existence(app)
54
-
55
- if options[:destroy]
56
- self.behavior = :revoke
57
- else
58
- unless options[:force]
54
+ if model_name_already_exists?
55
+ if options[:destroy]
56
+ self.behavior = :revoke
57
+ elsif !options[:force]
59
58
  say "#{@camel_name} already exists."
60
- say "Please, change the name."
59
+ say 'Please, change the name.'
61
60
  return false
62
61
  end
63
- end if model_name_already_exists?
62
+ end
64
63
 
65
64
  return false if has_invalid_fields?
66
65
 
@@ -73,7 +72,7 @@ module Padrino
73
72
  def model_name_already_exists?
74
73
  @camel_name = name.to_s.underscore.camelize
75
74
 
76
- @project_name = ""
75
+ @project_name = ''
77
76
  @project_name = fetch_project_name
78
77
 
79
78
  return false unless already_exists?(@camel_name, @project_name)
@@ -86,7 +85,7 @@ module Padrino
86
85
  def check_orm
87
86
  return true if include_component_module_for(:orm)
88
87
 
89
- say "<= You need an ORM adapter for run this generator. Sorry!"
88
+ say '<= You need an ORM adapter for run this generator. Sorry!'
90
89
  raise SystemExit
91
90
  end
92
91
 
@@ -103,9 +102,9 @@ module Padrino
103
102
  # Check if the fields are valid
104
103
  #
105
104
  def has_invalid_fields?
106
- if invalids = invalid_fields(fields)
105
+ if (invalids = invalid_fields(fields))
107
106
  say 'Invalid field name:', :red
108
- say " #{invalids.join(", ")}"
107
+ say " #{invalids.join(', ')}"
109
108
  end
110
109
  end
111
110
  end
@@ -11,8 +11,8 @@ module Padrino
11
11
  PLUGIN_URL = 'https://github.com/padrino/padrino-recipes/tree/master/plugins'
12
12
  Padrino::Generators.add_generator(:plugin, self)
13
13
 
14
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
15
- def self.banner; "padrino-gen plugin [plugin_identifier] [options]"; end
14
+ def self.source_root; __dir__; end
15
+ def self.banner; 'padrino-gen plugin [plugin_identifier] [options]'; end
16
16
 
17
17
  include Thor::Actions
18
18
  include Padrino::Generators::Actions
@@ -20,11 +20,11 @@ module Padrino
20
20
 
21
21
  desc "Description:\n\n\tpadrino-gen plugin sets up a plugin within a Padrino application"
22
22
 
23
- argument :plugin_file, :desc => "The name or path to the Padrino plugin", :optional => true
23
+ argument :plugin_file, desc: 'The name or path to the Padrino plugin', optional: true
24
24
 
25
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
26
- class_option :list, :desc => "list available plugins", :aliases => '-l', :default => false, :type => :boolean
27
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
25
+ class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
26
+ class_option :list, desc: 'list available plugins', aliases: '-l', default: false, type: :boolean
27
+ class_option :destroy, aliases: '-d', default: false, type: :boolean
28
28
 
29
29
  # Show help if no ARGV given.
30
30
  require_arguments!
@@ -41,7 +41,7 @@ module Padrino
41
41
  self.behavior = :revoke if options[:destroy]
42
42
  execute_runner(:plugin, plugin_file)
43
43
  else
44
- say "You are not at the root of a Padrino application! (config/boot.rb not found)"
44
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
45
45
  end
46
46
  end
47
47
  end
@@ -51,14 +51,14 @@ module Padrino
51
51
  plugins = {}
52
52
  uri = URI.parse(PLUGIN_URL)
53
53
  http = Net::HTTP.new(uri.host, uri.port)
54
- http.use_ssl = true if uri.scheme == "https"
54
+ http.use_ssl = true if uri.scheme == 'https'
55
55
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
56
56
  http.start do
57
57
  http.request_get(uri.path) do |res|
58
58
  plugins = res.body.scan(%r{/plugins/([-\w]+)_plugin.rb}).flatten.uniq
59
59
  end
60
60
  end
61
- say "Available plugins:", :green
61
+ say 'Available plugins:', :green
62
62
  say plugins.map { |plugin| " - #{plugin}" }.join("\n")
63
63
  end
64
64
  end
@@ -3,8 +3,8 @@
3
3
  # You can mount additional applications using any of these commands below:
4
4
  #
5
5
  # Padrino.mount('blog').to('/blog')
6
- # Padrino.mount('blog', :app_class => 'BlogApp').to('/blog')
7
- # Padrino.mount('blog', :app_file => 'path/to/blog/app.rb').to('/blog')
6
+ # Padrino.mount('blog', app_class: 'BlogApp').to('/blog')
7
+ # Padrino.mount('blog', app_file: 'path/to/blog/app.rb').to('/blog')
8
8
  #
9
9
  # You can also map apps to a specified host:
10
10
  #
@@ -18,7 +18,7 @@
18
18
  # By default, this file mounts the primary app which was generated with this project.
19
19
  # However, the mounted app can be modified as needed:
20
20
  #
21
- # Padrino.mount('AppName', :app_file => 'path/to/file', :app_class => 'BlogApp').to('/')
21
+ # Padrino.mount('AppName', app_file: 'path/to/file', app_class: 'BlogApp').to('/')
22
22
  #
23
23
 
24
24
  ##
@@ -28,7 +28,7 @@
28
28
  Padrino.configure_apps do
29
29
  # enable :sessions
30
30
  set :session_secret, '<%= SecureRandom.hex(32) %>'
31
- set :protection, :except => :path_traversal
31
+ set :protection, except: :path_traversal
32
32
  set :protect_from_csrf, true
33
33
  end
34
34
 
@@ -1,6 +1,6 @@
1
1
  # Defines our constants
2
2
  RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV)
3
- PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT)
3
+ PADRINO_ROOT = File.expand_path('..', __dir__) unless defined?(PADRINO_ROOT)
4
4
 
5
5
  # Load our dependencies
6
6
  require 'bundler/setup'
@@ -28,7 +28,7 @@ Bundler.require(:default, RACK_ENV)
28
28
  # ## Configure your HTML5 data helpers
29
29
  #
30
30
  # Padrino::Helpers::TagHelpers::DATA_ATTRIBUTES.push(:dialog)
31
- # text_field :foo, :dialog => true
31
+ # text_field :foo, dialog: true
32
32
  # Generates: <input type="text" data-dialog="true" name="foo" />
33
33
  #
34
34
  # ## Add helpers to mailer
@@ -4,6 +4,6 @@
4
4
  # This file can be used to start Padrino,
5
5
  # just execute it from the command line.
6
6
 
7
- require File.expand_path("../config/boot.rb", __FILE__)
7
+ require File.expand_path('config/boot.rb', __dir__)
8
8
 
9
9
  run Padrino.application
@@ -9,8 +9,8 @@ module Padrino
9
9
  class Project < Thor::Group
10
10
  Padrino::Generators.add_generator(:project, self)
11
11
 
12
- def self.source_root; File.expand_path(File.dirname(__FILE__)); end
13
- def self.banner; "padrino-gen project [name] [options]"; end
12
+ def self.source_root; __dir__; end
13
+ def self.banner; 'padrino-gen project [name] [options]'; end
14
14
 
15
15
  include Thor::Actions
16
16
  include Padrino::Generators::Actions
@@ -19,20 +19,20 @@ module Padrino
19
19
 
20
20
  desc "Description:\n\n\tpadrino-gen project generates a new Padrino project"
21
21
 
22
- argument :name, :desc => 'The name of your padrino project'
23
-
24
- class_option :app , :desc => 'The application name', :aliases => '-n', :default => nil, :type => :string
25
- class_option :bundle, :desc => 'Run bundle install', :aliases => '-b', :default => false, :type => :boolean
26
- class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
27
- class_option :dev, :desc => 'Use padrino from a git checkout', :default => false, :type => :boolean
28
- class_option :tiny, :desc => 'Generate tiny app skeleton', :aliases => '-i', :default => false, :type => :boolean
29
- class_option :lean, :desc => 'Generate lean project without apps', :aliases => '-l', :default => false, :type => :boolean
30
- class_option :api, :desc => 'Generate minimal project for APIs', :default => false, :type => :boolean
31
- class_option :template, :desc => 'Generate project from template', :aliases => '-p', :default => nil, :type => :string
32
- class_option :gem, :desc => 'Generate project as a gem', :aliases => '-g', :default => false, :type => :boolean
33
- class_option :migration_format, :desc => 'Filename format for migrations (number, timestamp)', :default => 'number', :type => :string
34
- class_option :adapter, :desc => 'SQL adapter for ORM (sqlite, mysql, mysql2, mysql-gem, postgres)', :aliases => '-a', :default => 'sqlite', :type => :string
35
- class_option :server, :desc => 'HTTP server to use (webrick, thin, puma)', :aliases => '-s', :default => 'webrick', :type => :string
22
+ argument :name, desc: 'The name of your padrino project'
23
+
24
+ class_option :app, desc: 'The application name', aliases: '-n', default: nil, type: :string
25
+ class_option :bundle, desc: 'Run bundle install', aliases: '-b', default: false, type: :boolean
26
+ class_option :root, desc: 'The root destination', aliases: '-r', default: '.', type: :string
27
+ class_option :dev, desc: 'Use padrino from a git checkout', default: false, type: :boolean
28
+ class_option :tiny, desc: 'Generate tiny app skeleton', aliases: '-i', default: false, type: :boolean
29
+ class_option :lean, desc: 'Generate lean project without apps', aliases: '-l', default: false, type: :boolean
30
+ class_option :api, desc: 'Generate minimal project for APIs', default: false, type: :boolean
31
+ class_option :template, desc: 'Generate project from template', aliases: '-p', default: nil, type: :string
32
+ class_option :gem, desc: 'Generate project as a gem', aliases: '-g', default: false, type: :boolean
33
+ class_option :migration_format, desc: 'Filename format for migrations (number, timestamp)', default: 'number', type: :string
34
+ class_option :adapter, desc: 'SQL adapter for ORM (sqlite, mysql, mysql2, mysql-gem, postgres)', aliases: '-a', default: 'sqlite', type: :string
35
+ class_option :server, desc: 'HTTP server to use (webrick, thin, puma)', aliases: '-s', default: 'webrick', type: :string
36
36
 
37
37
  # Definitions for the available customizable components.
38
38
  defines_component_options
@@ -45,11 +45,11 @@ module Padrino
45
45
  #
46
46
  def setup_project
47
47
  valid_constant? name
48
- app = (options[:app] || "App")
48
+ app = options[:app] || 'App'
49
49
 
50
50
  @project_name = name.gsub(/\W/, '_').underscore.camelize
51
51
 
52
- fail "Constant `#{@project_name}` already exists. Please, use another name" if already_exists?(@project_name)
52
+ raise "Constant `#{@project_name}` already exists. Please, use another name" if already_exists?(@project_name)
53
53
 
54
54
  @app_name = app.gsub(/\W/, '_').camelize
55
55
  self.destination_root = File.join(options[:root], name)
@@ -63,15 +63,15 @@ module Padrino
63
63
  store_component_config('.components')
64
64
  unless options[:lean]
65
65
  app_skeleton('app', options[:tiny])
66
- append_file destination_root('config/apps.rb'), "Padrino.mount('#{@project_name}::#{@app_name}', :app_file => Padrino.root('app/app.rb')).to('/')\n"
66
+ append_file destination_root('config/apps.rb'), "Padrino.mount('#{@project_name}::#{@app_name}', app_file: Padrino.root('app/app.rb')).to('/')\n"
67
67
  end
68
68
  template 'templates/Gemfile.tt', destination_root('Gemfile')
69
69
  template 'templates/Rakefile.tt', destination_root('Rakefile')
70
70
  template 'templates/project_bin.tt', destination_root("exe/#{name}")
71
- File.chmod(0755, destination_root("exe/#{name}"))
71
+ File.chmod(0o755, destination_root("exe/#{name}"))
72
72
  if options.gem?
73
- template 'templates/gem/gemspec.tt', destination_root(name + '.gemspec')
74
- inject_into_file destination_root('Rakefile'), "require 'bundler/gem_tasks'\n", :after => "require 'bundler/setup'\n"
73
+ template 'templates/gem/gemspec.tt', destination_root("#{name}.gemspec")
74
+ inject_into_file destination_root('Rakefile'), "require 'bundler/gem_tasks'\n", after: "require 'bundler/setup'\n"
75
75
  template 'templates/gem/README.md.tt', destination_root('README.md')
76
76
  template 'templates/gem/lib/libname.tt', destination_root("lib/#{name}.rb")
77
77
  template 'templates/gem/lib/libname/version.tt', destination_root("lib/#{name}/version.rb")
@@ -87,12 +87,12 @@ module Padrino
87
87
  #
88
88
  def setup_components
89
89
  return if options[:template]
90
- @_components = options.class.new options.select{ |key,_| self.class.component_types.include?(key.to_sym) }
90
+ @_components = options.class.new(options.slice(*self.class.component_types))
91
91
  self.class.component_types.each do |comp|
92
92
  choice = @_components[comp] = resolve_valid_choice(comp)
93
93
  execute_component_setup(comp, choice)
94
94
  end
95
- store_component_config('.components', :force => true)
95
+ store_component_config('.components', force: true)
96
96
  store_component_choice(:namespace, @project_name)
97
97
  store_component_choice(:migration_format, options[:migration_format])
98
98
  end
@@ -101,35 +101,33 @@ module Padrino
101
101
  # Generates test files for tiny app skeleton.
102
102
  #
103
103
  def setup_test_files
104
- if options[:tiny] && @_components[:test] != :none
105
- test_component = @_components[:test]
106
- test_component = "rspec" if test_component == "cucumber"
107
- uppercase_test_component = test_component.upcase
108
- controller_template_name = "#{uppercase_test_component}_CONTROLLER_TEST"
109
- helper_template_name = "#{uppercase_test_component}_HELPER_TEST"
110
- return unless defined?(controller_template_name)
111
-
112
- controller_content = instance_eval(controller_template_name).gsub(/!PATH!/, "Controller").gsub(/!NAME!/, "").gsub(/!EXPANDED_PATH!/, "/")
113
- helper_content = instance_eval(helper_template_name).gsub(/!NAME!/, "#{@project_name}::#{@app_name}::#{DEFAULT_HELPER_NAME}")
114
-
115
- proc{|*args| args.map{|str| str.gsub!(/!PATH!/, recognize_path)} }.call(controller_content, helper_content)
116
-
117
- directory_name = [:rspec].include?(test_component.to_sym) ? "spec" : "test"
118
- base_path = File.join(directory_name, "app")
119
- create_file destination_root("#{base_path}/controllers/controllers_#{directory_name}.rb"), controller_content, :skip => true
120
- create_file destination_root("#{base_path}/helpers/helpers_#{directory_name}.rb"), helper_content, :skip => true
121
- helper_path = destination_root(File.join(directory_name, "#{directory_name == "spec" ? "spec_helper" : "test_config"}.rb"))
122
- gsub_file helper_path, %r{helpers/\*\*/\*\.rb}, "helpers.rb"
123
- end
104
+ return unless options[:tiny] && @_components[:test] != :none
105
+
106
+ test_component = @_components[:test]
107
+ test_component = 'rspec' if test_component == 'cucumber'
108
+ uppercase_test_component = test_component.upcase
109
+ controller_template_name = "#{uppercase_test_component}_CONTROLLER_TEST"
110
+ helper_template_name = "#{uppercase_test_component}_HELPER_TEST"
111
+ return unless defined?(controller_template_name)
112
+
113
+ controller_content = instance_eval(controller_template_name).gsub(/!PATH!/, 'Controller').gsub(/!NAME!/, '').gsub(/!EXPANDED_PATH!/, '/')
114
+ helper_content = instance_eval(helper_template_name).gsub(/!NAME!/, "#{@project_name}::#{@app_name}::#{DEFAULT_HELPER_NAME}")
115
+
116
+ proc { |*args| args.map { |str| str.gsub!(/!PATH!/, recognize_path) } }.call(controller_content, helper_content)
117
+
118
+ directory_name = [:rspec].include?(test_component.to_sym) ? 'spec' : 'test'
119
+ base_path = File.join(directory_name, 'app')
120
+ create_file destination_root("#{base_path}/controllers/controllers_#{directory_name}.rb"), controller_content, skip: true
121
+ create_file destination_root("#{base_path}/helpers/helpers_#{directory_name}.rb"), helper_content, skip: true
122
+ helper_path = destination_root(File.join(directory_name, "#{directory_name == 'spec' ? 'spec_helper' : 'test_config'}.rb"))
123
+ gsub_file helper_path, %r{helpers/\*\*/\*\.rb}, 'helpers.rb'
124
124
  end
125
125
 
126
126
  ##
127
127
  # Bundle all required components using bundler and Gemfile.
128
128
  #
129
129
  def bundle_dependencies
130
- if options[:bundle]
131
- run_bundler
132
- end
130
+ run_bundler if options[:bundle]
133
131
  end
134
132
 
135
133
  ##
@@ -141,8 +139,8 @@ module Padrino
141
139
  say "#{name} is ready for development!", :green
142
140
  say '=' * 65, :green
143
141
  say "$ cd #{options[:root]}/#{name}"
144
- say "$ bundle --binstubs" unless options[:bundle]
145
- say "=" * 65, :green
142
+ say '$ bundle --binstubs' unless options[:bundle]
143
+ say '=' * 65, :green
146
144
  say
147
145
  end
148
146
 
@@ -151,7 +149,7 @@ module Padrino
151
149
  #
152
150
  def git_author_name
153
151
  git_author_name = `git config user.name`.chomp rescue ''
154
- git_author_name.empty? ? "TODO: Write your name" : git_author_name
152
+ git_author_name.empty? ? 'TODO: Write your name' : git_author_name
155
153
  end
156
154
 
157
155
  ##
@@ -159,7 +157,7 @@ module Padrino
159
157
  #
160
158
  def git_author_email
161
159
  git_author_email = `git config user.email`.chomp rescue ''
162
- git_author_email.empty? ? "TODO: Write your email address" : git_author_email
160
+ git_author_email.empty? ? 'TODO: Write your email address' : git_author_email
163
161
  end
164
162
  end
165
163
  end
@@ -8,20 +8,19 @@ module Padrino
8
8
  # common actions for modifying a project or application.
9
9
  #
10
10
  module Runner
11
-
12
11
  # Generates project scaffold based on a given template file.
13
12
  #
14
13
  # @param [Hash] options
15
14
  # Options to use to generate the project.
16
15
  #
17
16
  # @example
18
- # project :test => :shoulda, :orm => :activerecord, :renderer => "haml"
17
+ # project test: :shoulda, orm: :activerecord, renderer: "haml"
19
18
  #
20
- def project(options={})
21
- components = options.sort_by { |k, v| k.to_s }.map { |component, value| "--#{component}=#{value}" }
22
- params = [name, *components].push("-r=#{destination_root("../")}")
23
- say "=> Executing: padrino-gen project #{params.join(" ")}", :magenta
24
- Padrino.bin_gen(*params.unshift("project"))
19
+ def project(options = {})
20
+ components = options.sort_by { |k, _v| k.to_s }.map { |component, value| "--#{component}=#{value}" }
21
+ params = [name, *components].push("-r=#{destination_root('../')}")
22
+ say "=> Executing: padrino-gen project #{params.join(' ')}", :magenta
23
+ Padrino.bin_gen(*params.unshift('project'))
25
24
  end
26
25
 
27
26
  ##
@@ -37,10 +36,10 @@ module Padrino
37
36
  # generate :controller, "posts get:index get:new post:new"
38
37
  # generate :migration, "AddEmailToUser email:string"
39
38
  #
40
- def generate(type, arguments="")
41
- params = arguments.split(" ").push("-r=#{destination_root}")
39
+ def generate(type, arguments = '')
40
+ params = arguments.split(' ').push("-r=#{destination_root}")
42
41
  params.push("--app=#{@_app_name}") if @_app_name
43
- say "=> Executing: padrino-gen #{type} #{params.join(" ")}", :magenta
42
+ say "=> Executing: padrino-gen #{type} #{params.join(' ')}", :magenta
44
43
  Padrino.bin_gen(*params.unshift(type))
45
44
  end
46
45
 
@@ -54,7 +53,7 @@ module Padrino
54
53
  # rake "custom task1 task2"
55
54
  #
56
55
  def rake(command)
57
- Padrino.bin("rake", command, "-c=#{destination_root}")
56
+ Padrino.bin('rake', command, "-c=#{destination_root}")
58
57
  end
59
58
 
60
59
  ##
@@ -74,11 +73,12 @@ module Padrino
74
73
  def app(name)
75
74
  say "=> Executing: padrino-gen app #{name} -r=#{destination_root}", :magenta
76
75
  Padrino.bin_gen(:app, name.to_s, "-r=#{destination_root}")
77
- if block_given?
78
- @_app_name = name
79
- yield
80
- @_app_name = nil
81
- end
76
+ return unless block_given?
77
+
78
+ @_app_name = name
79
+ yield
80
+ ensure
81
+ @_app_name = nil
82
82
  end
83
83
 
84
84
  ##
@@ -96,7 +96,7 @@ module Padrino
96
96
  #
97
97
  def git(*args)
98
98
  FileUtils.cd(destination_root) do
99
- cmd = "git %s" % args.join(' ')
99
+ cmd = format('git %s', args.join(' '))
100
100
  say cmd, :green
101
101
  system cmd
102
102
  end
@@ -122,21 +122,22 @@ module Padrino
122
122
  def execute_runner(kind, template_file)
123
123
  # Determine resolved template path
124
124
  template_file = template_file.to_s
125
- template_path = case
126
- when template_file =~ %r{^https?://} && template_file !~ /gist/
125
+ template_path =
126
+ if template_file =~ %r{^https?://} && template_file !~ /gist/
127
127
  template_file
128
- when template_file =~ /gist/ && template_file !~ /raw/
129
- raw_link, _ = *URI.open(template_file) { |io| io.read.scan(/<a\s+href\s?\=\"(.*?)\"\>raw/) }
128
+ elsif template_file =~ /gist/ && template_file !~ /raw/
129
+ raw_link, = *URI.open(template_file) { |io| io.read.scan(/<a\s+href\s?="(.*?)">raw/) }
130
130
  raw_link ? "https://gist.github.com#{raw_link[0]}" : template_file
131
- when File.extname(template_file).empty? # referencing official plugin (i.e hoptoad)
131
+ elsif File.extname(template_file).empty? # referencing official plugin (i.e hoptoad)
132
132
  "https://raw.github.com/padrino/padrino-recipes/master/#{kind.to_s.pluralize}/#{template_file}_#{kind}.rb"
133
133
  else # local file on system
134
134
  File.expand_path(template_file)
135
135
  end
136
+
136
137
  begin
137
138
  self.apply(template_path)
138
- rescue => error
139
- say("The template at #{template_path} could not be loaded: #{error.message}", :red)
139
+ rescue StandardError => e
140
+ say("The template at #{template_path} could not be loaded: #{e.message}", :red)
140
141
  end
141
142
  end
142
143
  end