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
@@ -13,21 +13,21 @@ module Padrino
13
13
  # Array of column names and property type.
14
14
  # @param [Hash] options
15
15
  # Additional migration options, e.g
16
- # { :base => "....text...", :up => "..text...",
17
- # :down => "..text...", column_format => "t.column :#{field}, :#{kind}" }
16
+ # { base: '....text...', up: '..text...',
17
+ # down: '..text...', column_format: "t.column :#{field}, :#{kind}" }
18
18
  # @example
19
- # output_model_migration("AddPerson", "person", ["name:string", "age:integer"],
20
- # :base => AR_MIGRATION,
21
- # :column_format => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
22
- # :up => AR_MODEL_UP_MG, :down => AR_MODEL_DOWN_MG)
19
+ # output_model_migration('AddPerson', 'person', ["name:string", "age:integer"],
20
+ # base: AR_MIGRATION,
21
+ # column_format: Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
22
+ # up: AR_MODEL_UP_MG, down: AR_MODEL_DOWN_MG)
23
23
  #
24
- def output_model_migration(filename, name, columns, options={})
24
+ def output_model_migration(filename, name, columns, options = {})
25
25
  if behavior == :revoke
26
26
  remove_migration(filename)
27
27
  else
28
28
  return if migration_exist?(filename)
29
29
  model_name = name.to_s.pluralize
30
- field_tuples = columns.map { |value| value.split(":") }
30
+ field_tuples = columns.map { |value| value.split(':') }
31
31
  field_tuples.map! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] }
32
32
  column_declarations = field_tuples.map(&options[:column_format]).join("\n ")
33
33
  contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, options[:up]).gsub(/!DOWN!\n/m, options[:down])
@@ -35,8 +35,8 @@ module Padrino
35
35
  contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.underscore.camelize)
36
36
  migration_number = current_migration_number
37
37
  contents = contents.gsub(/!FIELDS!/, column_declarations).gsub(/!VERSION!/, migration_number)
38
- migration_filename = "#{format("%03d", migration_number)}_#{filename.underscore}.rb"
39
- create_file(destination_root('db/migrate/', migration_filename), contents, :skip => true)
38
+ migration_filename = "#{format('%03d', migration_number)}_#{filename.underscore}.rb"
39
+ create_file(destination_root('db/migrate/', migration_filename), contents, skip: true)
40
40
  end
41
41
  end
42
42
 
@@ -51,17 +51,17 @@ module Padrino
51
51
  # Array of column names and property type.
52
52
  # @param [Hash] options
53
53
  # Additional migration options, e.g
54
- # { :base "...text...", :change_format => "...text...",
55
- # :add => proc { |field, kind| "add_column :#{table_name}, :#{field}, :#{kind}" },
56
- # :remove => proc { |field, kind| "remove_column :#{table_name}, :#{field}" }
54
+ # { base:..text...", change_format: "...text...",
55
+ # add: proc { |field, kind| "add_column :#{table_name}, :#{field}, :#{kind}" },
56
+ # remove: proc { |field, kind| "remove_column :#{table_name}, :#{field}" }
57
57
  # @example
58
58
  # output_migration_file(migration_name, name, columns,
59
- # :base => AR_MIGRATION, :change_format => AR_CHANGE_MG,
60
- # :add => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
61
- # :remove => Proc.new { |field, kind| "t.remove :#{field}" }
59
+ # base: AR_MIGRATION, change_format: AR_CHANGE_MG,
60
+ # add: Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
61
+ # remove: Proc.new { |field, kind| "t.remove :#{field}" }
62
62
  # )
63
63
  #
64
- def output_migration_file(filename, name, columns, options={})
64
+ def output_migration_file(filename, name, columns, options = {})
65
65
  if behavior == :revoke
66
66
  remove_migration(name)
67
67
  else
@@ -69,7 +69,7 @@ module Padrino
69
69
  change_format = options[:change_format]
70
70
  migration_scan = filename.underscore.camelize.scan(/(Add|Remove).*?(?:(?:To|From).+?)*(?:To|From)((?:To|From)?.*?)$/).flatten
71
71
  direction, table_name = migration_scan[0].downcase, migration_scan[1].downcase.pluralize if migration_scan.any?
72
- tuples = direction ? columns.map { |value| value.split(":") } : []
72
+ tuples = direction ? columns.map { |value| value.split(':') } : []
73
73
  tuples.map! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] }
74
74
  add_columns = tuples.map(&options[:add]).join("\n ")
75
75
  remove_columns = tuples.map(&options[:remove]).join("\n ")
@@ -80,8 +80,8 @@ module Padrino
80
80
  contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.underscore.camelize)
81
81
  migration_number = current_migration_number
82
82
  contents.gsub!(/!VERSION!/, migration_number)
83
- migration_filename = "#{format("%03d", migration_number)}_#{filename.underscore}.rb"
84
- create_file(destination_root('db/migrate/', migration_filename), contents, :skip => true)
83
+ migration_filename = "#{format('%03d', migration_number)}_#{filename.underscore}.rb"
84
+ create_file(destination_root('db/migrate/', migration_filename), contents, skip: true)
85
85
  end
86
86
  end
87
87
 
@@ -89,9 +89,9 @@ module Padrino
89
89
  # Returns the number of the latest(most current) migration file.
90
90
  #
91
91
  def return_last_migration_number
92
- Dir[destination_root('db/migrate/*.rb')].map { |f|
92
+ Dir[destination_root('db/migrate/*.rb')].map do |f|
93
93
  File.basename(f).match(/^(\d+)/)[0].to_i
94
- }.max.to_i || 0
94
+ end.max.to_i || 0
95
95
  end
96
96
 
97
97
  ##
@@ -99,7 +99,7 @@ module Padrino
99
99
  #
100
100
  def current_migration_number
101
101
  if fetch_component_choice(:migration_format).to_s == 'timestamp'
102
- Time.now.utc.strftime("%Y%m%d%H%M%S")
102
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
103
103
  else
104
104
  return_last_migration_number + 1
105
105
  end.to_s
@@ -112,7 +112,7 @@ module Padrino
112
112
  # File name of the migration file.
113
113
  #
114
114
  def migration_exist?(filename)
115
- Dir[destination_root("db/migrate/*_#{filename.underscore}.rb")].size > 0
115
+ Dir[destination_root("db/migrate/*_#{filename.underscore}.rb")].any?
116
116
  end
117
117
 
118
118
  ##
@@ -122,13 +122,13 @@ module Padrino
122
122
  # File name of the migration.
123
123
  #
124
124
  def remove_migration(name)
125
- migration_path = Dir[destination_root('db/migrate/*.rb')].find do |f|
125
+ migration_path = Dir[destination_root('db/migrate/*.rb')].find do |f|
126
126
  File.basename(f) =~ /#{name.to_s.underscore}/
127
127
  end
128
128
  return unless migration_path
129
- if behavior == :revoke
130
- create_file migration_path # we use create to reverse the operation of a revoke
131
- end
129
+
130
+ # we use create to reverse the operation of a revoke
131
+ create_file(migration_path) if behavior == :revoke
132
132
  end
133
133
 
134
134
  ##
@@ -141,10 +141,10 @@ module Padrino
141
141
  #
142
142
  # @example
143
143
  # insert_test_suite_setup('...CLASS_NAME...')
144
- # => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @app_name), :after => "set :environment, :test")
144
+ # => inject_into_file('test/test_config.rb', TEST.gsub(/CLASS_NAME/, @app_name), after: 'set :environment, :test')
145
145
  #
146
- def insert_test_suite_setup(suite_text, options={})
147
- options = { :path => "test/test_config.rb" }.update(options)
146
+ def insert_test_suite_setup(suite_text, options = {})
147
+ options = { path: 'test/test_config.rb' }.update(options)
148
148
  create_file(options[:path], suite_text.gsub(/CLASS_NAME/, "#{@project_name}::#{@app_name}"))
149
149
  end
150
150
 
@@ -158,13 +158,13 @@ module Padrino
158
158
  #
159
159
  # @example
160
160
  # insert_mocking_include('Mocha::API'):
161
- # => inject_into_file("test/test_config.rb", " include Mocha::API\n", :after => /class.*?\n/)
161
+ # => inject_into_file('test/test_config.rb', " include Mocha::API\n", after: /class.*?\n/)
162
162
  #
163
- def insert_mocking_include(library_name, options={})
164
- options = { :indent => 2, :after => /class.*?\n/, :path => "test/test_config.rb" }.update(options)
163
+ def insert_mocking_include(library_name, options = {})
164
+ options = { indent: 2, after: /class.*?\n/, path: 'test/test_config.rb' }.update(options)
165
165
  return unless File.exist?(destination_root(options[:path]))
166
166
  include_text = indent_spaces(2) + "include #{library_name}\n"
167
- inject_into_file(options[:path], include_text, :after => options[:after])
167
+ inject_into_file(options[:path], include_text, after: options[:after])
168
168
  end
169
169
 
170
170
  ##
@@ -187,20 +187,20 @@ module Padrino
187
187
  # controller_actions("get:index", "post:test")
188
188
  #
189
189
  def controller_actions(fields)
190
- field_tuples = fields.map { |value| value.split(":") }
190
+ field_tuples = fields.map { |value| value.split(':') }
191
191
  action_declarations = field_tuples.map do |request, name|
192
192
  "#{request} :#{name} do\n\nend\n"
193
193
  end
194
- action_declarations.join("\n").gsub(/^/, " " * 2).gsub(/^\s*$/, "")
194
+ action_declarations.join("\n").gsub(/^/, ' ' * 2).gsub(/^\s*$/, '')
195
195
  end
196
196
 
197
197
  def create_helper_files(app, name)
198
- @helper_name = "#{name.to_s.underscore.camelize}Helper"
198
+ @helper_name = "#{name.to_s.underscore.camelize}Helper"
199
199
  template 'templates/helper.rb.tt', destination_root(app, 'helpers', "#{name.to_s.underscore}_helper.rb")
200
- if test?
201
- include_component_module_for(:test)
202
- generate_helper_test(@helper_name, @project_name, @app_name)
203
- end
200
+ return unless test?
201
+
202
+ include_component_module_for(:test)
203
+ generate_helper_test(@helper_name, @project_name, @app_name)
204
204
  end
205
205
  end
206
206
  end
@@ -1,10 +1,10 @@
1
1
  def setup_mock
2
- require_dependencies 'mocha', :group => 'test', :require => false
3
- case options[:test].to_s
4
- when 'rspec'
5
- inject_into_file 'spec/spec_helper.rb', " conf.mock_with :mocha\n", :after => "RSpec.configure do |conf|\n"
6
- else
7
- inject_into_file 'test/test_config.rb', "require 'mocha/api'\n", :after => "require File.expand_path(File.dirname(__FILE__) + \"/../config/boot\")\n"
8
- insert_mocking_include "Mocha::API"
2
+ require_dependencies 'mocha', group: 'test', require: false
3
+
4
+ if options[:test].to_s == 'rspec'
5
+ inject_into_file 'spec/spec_helper.rb', " conf.mock_with :mocha\n", after: "RSpec.configure do |conf|\n"
6
+ else
7
+ inject_into_file 'test/test_config.rb', "require 'mocha/api'\n", after: "require_relative '../config/boot')\n"
8
+ insert_mocking_include 'Mocha::API'
9
9
  end
10
10
  end
@@ -1,11 +1,11 @@
1
1
  def setup_mock
2
- require_dependencies 'rr', :require => false, :group => 'test'
2
+ require_dependencies 'rr', require: false, group: 'test'
3
3
  case options[:test].to_s
4
- when 'rspec'
5
- inject_into_file 'spec/spec_helper.rb', "require 'rr'\n", :after => "\"/../config/boot\")\n"
6
- when 'minitest'
7
- insert_mocking_include "RR::Adapters::MiniTest", :path => "test/test_config.rb"
8
- else
9
- insert_mocking_include "RR::Adapters::TestUnit", :path => "test/test_config.rb"
4
+ when 'rspec'
5
+ inject_into_file 'spec/spec_helper.rb', "require 'rr'\n", after: "'../config/boot'\n"
6
+ when 'minitest'
7
+ insert_mocking_include 'RR::Adapters::MiniTest', path: 'test/test_config.rb'
8
+ else
9
+ insert_mocking_include 'RR::Adapters::TestUnit', path: 'test/test_config.rb'
10
10
  end
11
11
  end
@@ -1,114 +1,114 @@
1
- AR = (<<-AR) unless defined?(AR)
2
- ##
3
- # You can use other adapters like:
4
- #
5
- # ActiveRecord::Base.configurations = {
6
- # :development => {
7
- # :adapter => 'mysql2',
8
- # :encoding => 'utf8',
9
- # :reconnect => true,
10
- # :database => 'your_database',
11
- # :pool => 5,
12
- # :username => 'root',
13
- # :password => '',
14
- # :host => 'localhost',
15
- # :socket => '/tmp/mysql.sock'
16
- # }
17
- # }
18
- #
19
- ActiveRecord::Base.configurations = {
20
- :development => {
21
- !DB_DEVELOPMENT!
22
- },
23
- :production => {
24
- !DB_PRODUCTION!
25
- },
26
- :test => {
27
- !DB_TEST!
1
+ AR = <<~AR unless defined?(AR)
2
+ ##
3
+ # You can use other adapters like:
4
+ #
5
+ # ActiveRecord::Base.configurations = {
6
+ # development: {
7
+ # adapter: 'mysql2',
8
+ # encoding: 'utf8',
9
+ # reconnect: true,
10
+ # database: 'your_database',
11
+ # pool: 5,
12
+ # username: 'root',
13
+ # password: '',
14
+ # host: 'localhost',
15
+ # socket: '/tmp/mysql.sock'
16
+ # }
17
+ # }
18
+ #
19
+ ActiveRecord::Base.configurations = {
20
+ development: {
21
+ !DB_DEVELOPMENT!
22
+ },
23
+ production: {
24
+ !DB_PRODUCTION!
25
+ },
26
+ test: {
27
+ !DB_TEST!
28
+ }
28
29
  }
29
- }
30
30
 
31
- # Setup our logger
32
- ActiveRecord::Base.logger = logger
31
+ # Setup our logger
32
+ ActiveRecord::Base.logger = logger
33
33
 
34
- if ActiveRecord::VERSION::MAJOR.to_i < 4
35
- # Raise exception on mass assignment protection for Active Record models.
36
- ActiveRecord::Base.mass_assignment_sanitizer = :strict
34
+ if ActiveRecord::VERSION::MAJOR.to_i < 4
35
+ # Raise exception on mass assignment protection for Active Record models.
36
+ ActiveRecord::Base.mass_assignment_sanitizer = :strict
37
37
 
38
- # Log the query plan for queries taking more than this (works
39
- # with SQLite, MySQL, and PostgreSQL).
40
- ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
41
- end
38
+ # Log the query plan for queries taking more than this (works
39
+ # with SQLite, MySQL, and PostgreSQL).
40
+ ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
41
+ end
42
42
 
43
- # Doesn't include Active Record class name as root for JSON serialized output.
44
- ActiveRecord::Base.include_root_in_json = false
43
+ # Doesn't include Active Record class name as root for JSON serialized output.
44
+ ActiveRecord::Base.include_root_in_json = false
45
45
 
46
- # Store the full class name (including module namespace) in STI type column.
47
- ActiveRecord::Base.store_full_sti_class = true
46
+ # Store the full class name (including module namespace) in STI type column.
47
+ ActiveRecord::Base.store_full_sti_class = true
48
48
 
49
- # Use ISO 8601 format for JSON serialized times and dates.
50
- ActiveSupport.use_standard_json_time_format = true
49
+ # Use ISO 8601 format for JSON serialized times and dates.
50
+ ActiveSupport.use_standard_json_time_format = true
51
51
 
52
- # Don't escape HTML entities in JSON, leave that for the #json_escape helper
53
- # if you're including raw JSON in an HTML page.
54
- ActiveSupport.escape_html_entities_in_json = false
52
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper
53
+ # if you're including raw JSON in an HTML page.
54
+ ActiveSupport.escape_html_entities_in_json = false
55
55
 
56
- # Now we can establish connection with our db.
57
- if ActiveRecord::VERSION::MAJOR.to_i < 6
58
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
59
- else
60
- ActiveRecord::Base.establish_connection(Padrino.env)
61
- end
56
+ # Now we can establish connection with our db.
57
+ if ActiveRecord::VERSION::MAJOR.to_i < 6
58
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
59
+ else
60
+ ActiveRecord::Base.establish_connection(Padrino.env)
61
+ end
62
62
  AR
63
63
 
64
- MYSQL = (<<-MYSQL) unless defined?(MYSQL)
65
- :adapter => 'mysql',
66
- :encoding => 'utf8',
67
- :reconnect => true,
68
- :database => !DB_NAME!,
69
- :pool => 5,
70
- :username => 'root',
71
- :password => '',
72
- :host => 'localhost',
73
- :socket => '/tmp/mysql.sock'
64
+ MYSQL = <<-MYSQL.chomp unless defined?(MYSQL)
65
+ adapter: 'mysql',
66
+ encoding: 'utf8',
67
+ reconnect: true,
68
+ database: !DB_NAME!,
69
+ pool: 5,
70
+ username: 'root',
71
+ password: '',
72
+ host: 'localhost',
73
+ socket: '/tmp/mysql.sock'
74
74
  MYSQL
75
75
 
76
- MYSQL2 = (<<-MYSQL2) unless defined?(MYSQL2)
77
- :adapter => 'mysql2',
78
- :encoding => 'utf8',
79
- :reconnect => true,
80
- :database => !DB_NAME!,
81
- :pool => 5,
82
- :username => 'root',
83
- :password => '',
84
- :host => 'localhost',
85
- :socket => '/tmp/mysql.sock'
76
+ MYSQL2 = <<-MYSQL2.chomp unless defined?(MYSQL2)
77
+ adapter: 'mysql2',
78
+ encoding: 'utf8',
79
+ reconnect: true,
80
+ database: !DB_NAME!,
81
+ pool: 5,
82
+ username: 'root',
83
+ password: '',
84
+ host: 'localhost',
85
+ socket: '/tmp/mysql.sock'
86
86
  MYSQL2
87
87
 
88
- POSTGRES = (<<-POSTGRES) unless defined?(POSTGRES)
89
- :adapter => 'postgresql',
90
- :database => !DB_NAME!,
91
- :username => 'root',
92
- :password => '',
93
- :host => 'localhost',
94
- :port => 5432
88
+ POSTGRES = <<-POSTGRES.chomp unless defined?(POSTGRES)
89
+ adapter: 'postgresql',
90
+ database: !DB_NAME!,
91
+ username: 'root',
92
+ password: '',
93
+ host: 'localhost',
94
+ port: 5432
95
95
  POSTGRES
96
96
 
97
- SQLITE = (<<-SQLITE) unless defined?(SQLITE)
98
- :adapter => 'sqlite3',
99
- :database => !DB_NAME!
97
+ SQLITE = <<-SQLITE.chomp unless defined?(SQLITE)
98
+ adapter: 'sqlite3',
99
+ database: !DB_NAME!
100
100
  SQLITE
101
101
 
102
- CONNECTION_POOL_MIDDLEWARE = <<-MIDDLEWARE
103
- class ConnectionPoolManagement
104
- def initialize(app)
105
- @app = app
106
- end
102
+ CONNECTION_POOL_MIDDLEWARE = <<~MIDDLEWARE
103
+ class ConnectionPoolManagement
104
+ def initialize(app)
105
+ @app = app
106
+ end
107
107
 
108
- def call(env)
109
- ActiveRecord::Base.connection_pool.with_connection { @app.call(env) }
108
+ def call(env)
109
+ ActiveRecord::Base.connection_pool.with_connection { @app.call(env) }
110
+ end
110
111
  end
111
- end
112
112
  MIDDLEWARE
113
113
 
114
114
  def setup_orm
@@ -118,109 +118,111 @@ def setup_orm
118
118
  begin
119
119
  case adapter ||= options[:adapter]
120
120
  when 'mysql-gem'
121
- ar.sub! /!DB_DEVELOPMENT!/, MYSQL.sub(/!DB_NAME!/,"'#{db}_development'")
122
- ar.sub! /!DB_PRODUCTION!/, MYSQL.sub(/!DB_NAME!/,"'#{db}_production'")
123
- ar.sub! /!DB_TEST!/, MYSQL.sub(/!DB_NAME!/,"'#{db}_test'")
124
- require_dependencies 'mysql', :version => "~> 2.8.1"
121
+ ar.sub!(/!DB_DEVELOPMENT!/, MYSQL.sub(/!DB_NAME!/, "'#{db}_development'"))
122
+ ar.sub!(/!DB_PRODUCTION!/, MYSQL.sub(/!DB_NAME!/, "'#{db}_production'"))
123
+ ar.sub!(/!DB_TEST!/, MYSQL.sub(/!DB_NAME!/, "'#{db}_test'"))
124
+ require_dependencies 'mysql', version: '~> 2.8.1'
125
125
  when 'mysql', 'mysql2'
126
- ar.sub! /!DB_DEVELOPMENT!/, MYSQL2.sub(/!DB_NAME!/,"'#{db}_development'")
127
- ar.sub! /!DB_PRODUCTION!/, MYSQL2.sub(/!DB_NAME!/,"'#{db}_production'")
128
- ar.sub! /!DB_TEST!/, MYSQL2.sub(/!DB_NAME!/,"'#{db}_test'")
126
+ ar.sub!(/!DB_DEVELOPMENT!/, MYSQL2.sub(/!DB_NAME!/, "'#{db}_development'"))
127
+ ar.sub!(/!DB_PRODUCTION!/, MYSQL2.sub(/!DB_NAME!/, "'#{db}_production'"))
128
+ ar.sub!(/!DB_TEST!/, MYSQL2.sub(/!DB_NAME!/, "'#{db}_test'"))
129
129
  require_dependencies 'mysql2'
130
130
  when 'postgres'
131
- ar.sub! /!DB_DEVELOPMENT!/, POSTGRES.sub(/!DB_NAME!/,"'#{db}_development'")
132
- ar.sub! /!DB_PRODUCTION!/, POSTGRES.sub(/!DB_NAME!/,"'#{db}_production'")
133
- ar.sub! /!DB_TEST!/, POSTGRES.sub(/!DB_NAME!/,"'#{db}_test'")
131
+ ar.sub!(/!DB_DEVELOPMENT!/, POSTGRES.sub(/!DB_NAME!/, "'#{db}_development'"))
132
+ ar.sub!(/!DB_PRODUCTION!/, POSTGRES.sub(/!DB_NAME!/, "'#{db}_production'"))
133
+ ar.sub!(/!DB_TEST!/, POSTGRES.sub(/!DB_NAME!/, "'#{db}_test'"))
134
134
  require_dependencies 'pg'
135
135
  when 'sqlite'
136
- ar.sub! /!DB_DEVELOPMENT!/, SQLITE.sub(/!DB_NAME!/,"Padrino.root('db', '#{db}_development.db')")
137
- ar.sub! /!DB_PRODUCTION!/, SQLITE.sub(/!DB_NAME!/,"Padrino.root('db', '#{db}_production.db')")
138
- ar.sub! /!DB_TEST!/, SQLITE.sub(/!DB_NAME!/,"Padrino.root('db', '#{db}_test.db')")
136
+ ar.sub!(/!DB_DEVELOPMENT!/, SQLITE.sub(/!DB_NAME!/, "Padrino.root('db', '#{db}_development.db')"))
137
+ ar.sub!(/!DB_PRODUCTION!/, SQLITE.sub(/!DB_NAME!/, "Padrino.root('db', '#{db}_production.db')"))
138
+ ar.sub!(/!DB_TEST!/, SQLITE.sub(/!DB_NAME!/, "Padrino.root('db', '#{db}_test.db')"))
139
139
  require_dependencies 'sqlite3'
140
140
  else
141
141
  say "Failed to generate `config/database.rb` for ORM adapter `#{options[:adapter]}`", :red
142
- fail ArgumentError
142
+ raise ArgumentError
143
143
  end
144
144
  rescue ArgumentError
145
- adapter = ask("Please, choose a proper adapter:", :limited_to => %w[mysql mysql2 mysql-gem postgres sqlite])
145
+ adapter = ask('Please, choose a proper adapter:', limited_to: %w[mysql mysql2 mysql-gem postgres sqlite])
146
146
  retry
147
147
  end
148
148
 
149
- require_dependencies 'activerecord', :require => 'active_record', :version => ">= 3.1"
150
- create_file("config/database.rb", ar)
149
+ require_dependencies 'activerecord', require: 'active_record', version: '>= 3.1'
150
+ create_file('config/database.rb', ar)
151
151
  middleware :connection_pool_management, CONNECTION_POOL_MIDDLEWARE
152
152
  end
153
153
 
154
- AR_MODEL = (<<-MODEL) unless defined?(AR_MODEL)
155
- class !NAME! < ActiveRecord::Base
154
+ AR_MODEL = <<~MODEL unless defined?(AR_MODEL)
155
+ class !NAME! < ActiveRecord::Base
156
156
 
157
- end
157
+ end
158
158
  MODEL
159
159
 
160
- # options => { :fields => ["title:string", "body:string"], :app => 'app' }
161
- def create_model_file(name, options={})
160
+ # options => { fields: ['title:string', 'body:string'], app: 'app' }
161
+ def create_model_file(name, options = {})
162
162
  model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
163
163
  model_contents = AR_MODEL.sub(/!NAME!/, name.to_s.underscore.camelize)
164
- create_file(model_path, model_contents,:skip => true)
164
+ create_file(model_path, model_contents, skip: true)
165
165
  end
166
166
 
167
167
  if defined?(ActiveRecord::Migration) && ActiveRecord::Migration.respond_to?(:[])
168
- AR_MIGRATION = (<<-MIGRATION) unless defined?(AR_MIGRATION)
169
- class !FILECLASS! < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]
170
- def self.up
171
- !UP!
172
- end
173
-
174
- def self.down
175
- !DOWN!
176
- end
177
- end
178
- MIGRATION
168
+ AR_MIGRATION = <<~MIGRATION unless defined?(AR_MIGRATION)
169
+ class !FILECLASS! < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]
170
+ def self.up
171
+ !UP!
172
+ end
173
+
174
+ def self.down
175
+ !DOWN!
176
+ end
177
+ end
178
+ MIGRATION
179
179
  else
180
- AR_MIGRATION = (<<-MIGRATION) unless defined?(AR_MIGRATION)
181
- class !FILECLASS! < ActiveRecord::Migration
182
- def self.up
183
- !UP!
184
- end
185
-
186
- def self.down
187
- !DOWN!
188
- end
189
- end
190
- MIGRATION
180
+ AR_MIGRATION = <<~MIGRATION unless defined?(AR_MIGRATION)
181
+ class !FILECLASS! < ActiveRecord::Migration
182
+ def self.up
183
+ !UP!
184
+ end
185
+
186
+ def self.down
187
+ !DOWN!
188
+ end
189
+ end
190
+ MIGRATION
191
191
  end
192
192
 
193
- AR_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/,' ') unless defined?(AR_MODEL_UP_MG)
194
- create_table :!TABLE! do |t|
195
- !FIELDS!
196
- t.timestamps null: false
197
- end
193
+ AR_MODEL_UP_MG = <<~MIGRATION.gsub(/^/, ' ') unless defined?(AR_MODEL_UP_MG)
194
+ create_table :!TABLE! do |t|
195
+ !FIELDS!
196
+ t.timestamps null: false
197
+ end
198
198
  MIGRATION
199
199
 
200
- AR_MODEL_DOWN_MG = (<<-MIGRATION) unless defined?(AR_MODEL_DOWN_MG)
201
- drop_table :!TABLE!
200
+ AR_MODEL_DOWN_MG = <<~MIGRATION unless defined?(AR_MODEL_DOWN_MG)
201
+ drop_table :!TABLE!
202
202
  MIGRATION
203
203
 
204
204
  def create_model_migration(migration_name, name, columns)
205
- output_model_migration(migration_name, name, columns,
206
- :base => AR_MIGRATION,
207
- :column_format => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
208
- :up => AR_MODEL_UP_MG,
209
- :down => AR_MODEL_DOWN_MG
205
+ output_model_migration(
206
+ migration_name, name, columns,
207
+ base: AR_MIGRATION,
208
+ column_format: proc { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
209
+ up: AR_MODEL_UP_MG,
210
+ down: AR_MODEL_DOWN_MG
210
211
  )
211
212
  end
212
213
 
213
- AR_CHANGE_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(AR_CHANGE_MG)
214
- change_table :!TABLE! do |t|
215
- !COLUMNS!
216
- end
214
+ AR_CHANGE_MG = <<~MIGRATION.gsub(/^/, ' ') unless defined?(AR_CHANGE_MG)
215
+ change_table :!TABLE! do |t|
216
+ !COLUMNS!
217
+ end
217
218
  MIGRATION
218
219
 
219
220
  def create_migration_file(migration_name, name, columns)
220
- output_migration_file(migration_name, name, columns,
221
- :base => AR_MIGRATION,
222
- :change_format => AR_CHANGE_MG,
223
- :add => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
224
- :remove => Proc.new { |field, kind| "t.remove :#{field}" }
221
+ output_migration_file(
222
+ migration_name, name, columns,
223
+ base: AR_MIGRATION,
224
+ change_format: AR_CHANGE_MG,
225
+ add: proc { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
226
+ remove: proc { |field, _kind| "t.remove :#{field}" }
225
227
  )
226
228
  end