railties 5.0.7.2 → 5.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +77 -567
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +3 -3
- data/README.rdoc +1 -1
- data/exe/rails +2 -2
- data/lib/rails.rb +18 -18
- data/lib/rails/all.rb +1 -1
- data/lib/rails/api/generator.rb +28 -0
- data/lib/rails/api/task.rb +54 -42
- data/lib/rails/app_loader.rb +9 -9
- data/lib/rails/application.rb +30 -35
- data/lib/rails/application/bootstrap.rb +13 -7
- data/lib/rails/application/configuration.rb +30 -53
- data/lib/rails/application/default_middleware_stack.rb +3 -5
- data/lib/rails/application/finisher.rb +16 -7
- data/lib/rails/application/routes_reloader.rb +16 -1
- data/lib/rails/application_controller.rb +10 -10
- data/lib/rails/backtrace_cleaner.rb +5 -5
- data/lib/rails/cli.rb +7 -5
- data/lib/rails/code_statistics.rb +16 -17
- data/lib/rails/code_statistics_calculator.rb +3 -3
- data/lib/rails/command.rb +111 -0
- data/lib/rails/command/actions.rb +42 -0
- data/lib/rails/command/base.rb +149 -0
- data/lib/rails/command/behavior.rb +123 -0
- data/lib/rails/command/environment_argument.rb +34 -0
- data/lib/rails/commands.rb +2 -4
- data/lib/rails/commands/application/application_command.rb +29 -0
- data/lib/rails/commands/console/console_command.rb +89 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
- data/lib/rails/commands/destroy/destroy_command.rb +21 -0
- data/lib/rails/commands/generate/generate_command.rb +23 -0
- data/lib/rails/commands/help/USAGE +15 -0
- data/lib/rails/commands/help/help_command.rb +13 -0
- data/lib/rails/commands/new/new_command.rb +15 -0
- data/lib/rails/commands/plugin/plugin_command.rb +43 -0
- data/lib/rails/commands/rake/rake_command.rb +49 -0
- data/lib/rails/commands/runner/USAGE +17 -0
- data/lib/rails/commands/runner/runner_command.rb +46 -0
- data/lib/rails/commands/secrets/USAGE +52 -0
- data/lib/rails/commands/secrets/secrets_command.rb +36 -0
- data/lib/rails/commands/server/server_command.rb +177 -0
- data/lib/rails/commands/test/test_command.rb +20 -0
- data/lib/rails/commands/version/version_command.rb +9 -0
- data/lib/rails/configuration.rb +7 -7
- data/lib/rails/console/app.rb +4 -4
- data/lib/rails/dev_caching.rb +8 -8
- data/lib/rails/engine.rb +62 -63
- data/lib/rails/engine/commands.rb +6 -13
- data/lib/rails/engine/configuration.rb +2 -2
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators.rb +229 -313
- data/lib/rails/generators/actions.rb +20 -21
- data/lib/rails/generators/actions/create_migration.rb +24 -25
- data/lib/rails/generators/active_model.rb +3 -3
- data/lib/rails/generators/app_base.rb +123 -93
- data/lib/rails/generators/base.rb +32 -33
- data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/erb.rb +14 -14
- data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/generated_attribute.rb +27 -27
- data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/migration.rb +8 -8
- data/lib/rails/generators/model_helpers.rb +2 -2
- data/lib/rails/generators/named_base.rb +56 -56
- data/lib/rails/generators/rails/app/app_generator.rb +98 -81
- data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
- data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
- data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
- data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
- data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
- data/lib/rails/generators/rails/app/templates/gitignore +5 -1
- data/lib/rails/generators/rails/app/templates/package.json +5 -0
- data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
- data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
- data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
- data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
- data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
- data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
- data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/rails/model/model_generator.rb +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
- data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
- data/lib/rails/generators/rails/system_test/USAGE +10 -0
- data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
- data/lib/rails/generators/rails/task/task_generator.rb +1 -2
- data/lib/rails/generators/resource_helpers.rb +13 -10
- data/lib/rails/generators/test_case.rb +5 -6
- data/lib/rails/generators/test_unit.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
- data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
- data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
- data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
- data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
- data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
- data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
- data/lib/rails/generators/testing/assertions.rb +4 -4
- data/lib/rails/generators/testing/behaviour.rb +20 -21
- data/lib/rails/info.rb +20 -20
- data/lib/rails/info_controller.rb +15 -15
- data/lib/rails/initializable.rb +6 -2
- data/lib/rails/mailers_controller.rb +11 -11
- data/lib/rails/paths.rb +4 -5
- data/lib/rails/plugin/test.rb +7 -0
- data/lib/rails/rack/logger.rb +44 -46
- data/lib/rails/railtie.rb +41 -38
- data/lib/rails/railtie/configurable.rb +6 -6
- data/lib/rails/railtie/configuration.rb +1 -1
- data/lib/rails/ruby_version_check.rb +1 -1
- data/lib/rails/secrets.rb +111 -0
- data/lib/rails/source_annotation_extractor.rb +15 -9
- data/lib/rails/tasks.rb +3 -2
- data/lib/rails/tasks/annotations.rake +3 -3
- data/lib/rails/tasks/dev.rake +2 -2
- data/lib/rails/tasks/engine.rake +4 -4
- data/lib/rails/tasks/framework.rake +4 -18
- data/lib/rails/tasks/initializers.rake +1 -1
- data/lib/rails/tasks/log.rake +14 -10
- data/lib/rails/tasks/middleware.rake +1 -1
- data/lib/rails/tasks/misc.rake +10 -10
- data/lib/rails/tasks/restart.rake +4 -4
- data/lib/rails/tasks/routes.rake +3 -12
- data/lib/rails/tasks/statistics.rake +3 -3
- data/lib/rails/tasks/tmp.rake +7 -7
- data/lib/rails/tasks/yarn.rake +11 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
- data/lib/rails/test_help.rb +28 -10
- data/lib/rails/test_unit/line_filtering.rb +69 -3
- data/lib/rails/test_unit/minitest_plugin.rb +139 -0
- data/lib/rails/test_unit/railtie.rb +2 -1
- data/lib/rails/test_unit/reporter.rb +3 -8
- data/lib/rails/test_unit/test_requirer.rb +28 -0
- data/lib/rails/test_unit/testing.rake +19 -14
- data/lib/rails/version.rb +1 -1
- data/lib/rails/welcome_controller.rb +1 -1
- metadata +53 -30
- data/lib/minitest/rails_plugin.rb +0 -49
- data/lib/rails/commands/application.rb +0 -17
- data/lib/rails/commands/commands_tasks.rb +0 -180
- data/lib/rails/commands/console.rb +0 -68
- data/lib/rails/commands/console_helper.rb +0 -34
- data/lib/rails/commands/dbconsole.rb +0 -173
- data/lib/rails/commands/destroy.rb +0 -11
- data/lib/rails/commands/generate.rb +0 -13
- data/lib/rails/commands/plugin.rb +0 -23
- data/lib/rails/commands/rake_proxy.rb +0 -41
- data/lib/rails/commands/runner.rb +0 -71
- data/lib/rails/commands/server.rb +0 -163
- data/lib/rails/commands/test.rb +0 -10
- data/lib/rails/engine/commands_tasks.rb +0 -118
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
- data/lib/rails/rack/debugger.rb +0 -3
- data/lib/rails/test_unit/runner.rb +0 -141
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/concern"
|
2
|
+
require "rails/generators/actions/create_migration"
|
3
3
|
|
4
4
|
module Rails
|
5
5
|
module Generators
|
@@ -35,11 +35,11 @@ module Rails
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def set_migration_assigns!(destination)
|
38
|
-
destination = File.expand_path(destination,
|
38
|
+
destination = File.expand_path(destination, destination_root)
|
39
39
|
|
40
40
|
migration_dir = File.dirname(destination)
|
41
41
|
@migration_number = self.class.next_migration_number(migration_dir)
|
42
|
-
@migration_file_name = File.basename(destination,
|
42
|
+
@migration_file_name = File.basename(destination, ".rb")
|
43
43
|
@migration_class_name = @migration_file_name.camelize
|
44
44
|
end
|
45
45
|
|
@@ -52,16 +52,16 @@ module Rails
|
|
52
52
|
#
|
53
53
|
# migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb"
|
54
54
|
def migration_template(source, destination, config = {})
|
55
|
-
source
|
55
|
+
source = File.expand_path(find_in_source_paths(source.to_s))
|
56
56
|
|
57
57
|
set_migration_assigns!(destination)
|
58
|
-
context = instance_eval(
|
58
|
+
context = instance_eval("binding")
|
59
59
|
|
60
60
|
dir, base = File.split(destination)
|
61
|
-
numbered_destination = File.join(dir, ["%migration_number%", base].join(
|
61
|
+
numbered_destination = File.join(dir, ["%migration_number%", base].join("_"))
|
62
62
|
|
63
63
|
create_migration numbered_destination, nil, config do
|
64
|
-
ERB.new(::File.binread(source), nil,
|
64
|
+
ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators/active_model"
|
2
2
|
|
3
3
|
module Rails
|
4
4
|
module Generators
|
@@ -8,7 +8,7 @@ module Rails
|
|
8
8
|
mattr_accessor :skip_warn
|
9
9
|
|
10
10
|
def self.included(base) #:nodoc:
|
11
|
-
base.class_option :force_plural, type: :boolean, default: false, desc:
|
11
|
+
base.class_option :force_plural, type: :boolean, default: false, desc: "Forces the use of the given model name"
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(args, *_options)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "active_support/core_ext/module/introspection"
|
2
|
+
require "rails/generators/base"
|
3
|
+
require "rails/generators/generated_attribute"
|
4
4
|
|
5
5
|
module Rails
|
6
6
|
module Generators
|
@@ -14,7 +14,7 @@ module Rails
|
|
14
14
|
# Unfreeze name in case it's given as a frozen string
|
15
15
|
args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen?
|
16
16
|
super
|
17
|
-
assign_names!(
|
17
|
+
assign_names!(name)
|
18
18
|
parse_attributes! if respond_to?(:attributes)
|
19
19
|
end
|
20
20
|
|
@@ -28,53 +28,57 @@ module Rails
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def js_template(source, destination)
|
31
|
-
template(source +
|
31
|
+
template(source + ".js", destination + ".js")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
# TODO Change this to private once we've dropped Ruby 2.2 support.
|
36
|
+
# Workaround for Ruby 2.2 "private attribute?" warning.
|
35
37
|
protected
|
36
38
|
attr_reader :file_name
|
37
39
|
|
40
|
+
private
|
41
|
+
|
38
42
|
# FIXME: We are avoiding to use alias because a bug on thor that make
|
39
43
|
# this method public and add it to the task list.
|
40
|
-
def singular_name
|
44
|
+
def singular_name # :doc:
|
41
45
|
file_name
|
42
46
|
end
|
43
47
|
|
44
48
|
# Wrap block with namespace of current application
|
45
49
|
# if namespace exists and is not skipped
|
46
|
-
def module_namespacing(&block)
|
50
|
+
def module_namespacing(&block) # :doc:
|
47
51
|
content = capture(&block)
|
48
52
|
content = wrap_with_namespace(content) if namespaced?
|
49
53
|
concat(content)
|
50
54
|
end
|
51
55
|
|
52
|
-
def indent(content, multiplier = 2)
|
56
|
+
def indent(content, multiplier = 2) # :doc:
|
53
57
|
spaces = " " * multiplier
|
54
|
-
content.each_line.map {|line| line.blank? ? line : "#{spaces}#{line}" }.join
|
58
|
+
content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join
|
55
59
|
end
|
56
60
|
|
57
|
-
def wrap_with_namespace(content)
|
61
|
+
def wrap_with_namespace(content) # :doc:
|
58
62
|
content = indent(content).chomp
|
59
63
|
"module #{namespace.name}\n#{content}\nend\n"
|
60
64
|
end
|
61
65
|
|
62
|
-
def inside_template
|
66
|
+
def inside_template # :doc:
|
63
67
|
@inside_template = true
|
64
68
|
yield
|
65
69
|
ensure
|
66
70
|
@inside_template = false
|
67
71
|
end
|
68
72
|
|
69
|
-
def inside_template?
|
73
|
+
def inside_template? # :doc:
|
70
74
|
@inside_template
|
71
75
|
end
|
72
76
|
|
73
|
-
def namespace
|
77
|
+
def namespace # :doc:
|
74
78
|
Rails::Generators.namespace
|
75
79
|
end
|
76
80
|
|
77
|
-
def namespaced?
|
81
|
+
def namespaced? # :doc:
|
78
82
|
!options[:skip_namespace] && namespace
|
79
83
|
end
|
80
84
|
|
@@ -82,132 +86,128 @@ module Rails
|
|
82
86
|
@namespace_dirs ||= namespace.name.split("::").map(&:underscore)
|
83
87
|
end
|
84
88
|
|
85
|
-
def file_path
|
86
|
-
@file_path ||= (class_path + [file_name]).join(
|
89
|
+
def file_path # :doc:
|
90
|
+
@file_path ||= (class_path + [file_name]).join("/")
|
87
91
|
end
|
88
92
|
|
89
|
-
def class_path
|
93
|
+
def class_path # :doc:
|
90
94
|
inside_template? || !namespaced? ? regular_class_path : namespaced_class_path
|
91
95
|
end
|
92
96
|
|
93
|
-
def regular_class_path
|
97
|
+
def regular_class_path # :doc:
|
94
98
|
@class_path
|
95
99
|
end
|
96
100
|
|
97
|
-
def
|
98
|
-
@namespaced_file_path ||= namespaced_class_path.join("/")
|
99
|
-
end
|
100
|
-
|
101
|
-
def namespaced_class_path
|
101
|
+
def namespaced_class_path # :doc:
|
102
102
|
@namespaced_class_path ||= namespace_dirs + @class_path
|
103
103
|
end
|
104
104
|
|
105
|
-
def namespaced_path
|
105
|
+
def namespaced_path # :doc:
|
106
106
|
@namespaced_path ||= namespace_dirs.join("/")
|
107
107
|
end
|
108
108
|
|
109
|
-
def class_name
|
110
|
-
(class_path + [file_name]).map!(&:camelize).join(
|
109
|
+
def class_name # :doc:
|
110
|
+
(class_path + [file_name]).map!(&:camelize).join("::")
|
111
111
|
end
|
112
112
|
|
113
|
-
def human_name
|
113
|
+
def human_name # :doc:
|
114
114
|
@human_name ||= singular_name.humanize
|
115
115
|
end
|
116
116
|
|
117
|
-
def plural_name
|
117
|
+
def plural_name # :doc:
|
118
118
|
@plural_name ||= singular_name.pluralize
|
119
119
|
end
|
120
120
|
|
121
|
-
def i18n_scope
|
122
|
-
@i18n_scope ||= file_path.tr(
|
121
|
+
def i18n_scope # :doc:
|
122
|
+
@i18n_scope ||= file_path.tr("/", ".")
|
123
123
|
end
|
124
124
|
|
125
|
-
def table_name
|
125
|
+
def table_name # :doc:
|
126
126
|
@table_name ||= begin
|
127
127
|
base = pluralize_table_names? ? plural_name : singular_name
|
128
|
-
(class_path + [base]).join(
|
128
|
+
(class_path + [base]).join("_")
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
def uncountable?
|
132
|
+
def uncountable? # :doc:
|
133
133
|
singular_name == plural_name
|
134
134
|
end
|
135
135
|
|
136
|
-
def index_helper
|
136
|
+
def index_helper # :doc:
|
137
137
|
uncountable? ? "#{plural_table_name}_index" : plural_table_name
|
138
138
|
end
|
139
139
|
|
140
|
-
def show_helper
|
140
|
+
def show_helper # :doc:
|
141
141
|
"#{singular_table_name}_url(@#{singular_table_name})"
|
142
142
|
end
|
143
143
|
|
144
|
-
def edit_helper
|
144
|
+
def edit_helper # :doc:
|
145
145
|
"edit_#{show_helper}"
|
146
146
|
end
|
147
147
|
|
148
|
-
def new_helper
|
148
|
+
def new_helper # :doc:
|
149
149
|
"new_#{singular_table_name}_url"
|
150
150
|
end
|
151
151
|
|
152
|
-
def singular_table_name
|
152
|
+
def singular_table_name # :doc:
|
153
153
|
@singular_table_name ||= (pluralize_table_names? ? table_name.singularize : table_name)
|
154
154
|
end
|
155
155
|
|
156
|
-
def plural_table_name
|
156
|
+
def plural_table_name # :doc:
|
157
157
|
@plural_table_name ||= (pluralize_table_names? ? table_name : table_name.pluralize)
|
158
158
|
end
|
159
159
|
|
160
|
-
def plural_file_name
|
160
|
+
def plural_file_name # :doc:
|
161
161
|
@plural_file_name ||= file_name.pluralize
|
162
162
|
end
|
163
163
|
|
164
|
-
def fixture_file_name
|
164
|
+
def fixture_file_name # :doc:
|
165
165
|
@fixture_file_name ||= (pluralize_table_names? ? plural_file_name : file_name)
|
166
166
|
end
|
167
167
|
|
168
|
-
def route_url
|
169
|
-
@route_url ||= class_path.collect {|dname| "/" + dname }.join + "/" + plural_file_name
|
168
|
+
def route_url # :doc:
|
169
|
+
@route_url ||= class_path.collect { |dname| "/" + dname }.join + "/" + plural_file_name
|
170
170
|
end
|
171
171
|
|
172
|
-
def url_helper_prefix
|
173
|
-
@url_helper_prefix ||= (class_path + [file_name]).join(
|
172
|
+
def url_helper_prefix # :doc:
|
173
|
+
@url_helper_prefix ||= (class_path + [file_name]).join("_")
|
174
174
|
end
|
175
175
|
|
176
176
|
# Tries to retrieve the application name or simply return application.
|
177
|
-
def application_name
|
177
|
+
def application_name # :doc:
|
178
178
|
if defined?(Rails) && Rails.application
|
179
|
-
Rails.application.class.name.split(
|
179
|
+
Rails.application.class.name.split("::").first.underscore
|
180
180
|
else
|
181
181
|
"application"
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
|
-
def assign_names!(name)
|
186
|
-
@class_path = name.include?(
|
185
|
+
def assign_names!(name)
|
186
|
+
@class_path = name.include?("/") ? name.split("/") : name.split("::")
|
187
187
|
@class_path.map!(&:underscore)
|
188
188
|
@file_name = @class_path.pop
|
189
189
|
end
|
190
190
|
|
191
191
|
# Convert attributes array into GeneratedAttribute objects.
|
192
|
-
def parse_attributes!
|
192
|
+
def parse_attributes!
|
193
193
|
self.attributes = (attributes || []).map do |attr|
|
194
194
|
Rails::Generators::GeneratedAttribute.parse(attr)
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
-
def attributes_names
|
198
|
+
def attributes_names # :doc:
|
199
199
|
@attributes_names ||= attributes.each_with_object([]) do |a, names|
|
200
200
|
names << a.column_name
|
201
|
-
names <<
|
201
|
+
names << "password_confirmation" if a.password_digest?
|
202
202
|
names << "#{a.name}_type" if a.polymorphic?
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
|
-
def pluralize_table_names?
|
206
|
+
def pluralize_table_names? # :doc:
|
207
207
|
!defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names
|
208
208
|
end
|
209
209
|
|
210
|
-
def mountable_engine?
|
210
|
+
def mountable_engine? # :doc:
|
211
211
|
defined?(ENGINE_ROOT) && namespaced?
|
212
212
|
end
|
213
213
|
|
@@ -221,9 +221,9 @@ module Rails
|
|
221
221
|
# If the generator is invoked with class name Admin, it will check for
|
222
222
|
# the presence of "AdminDecorator".
|
223
223
|
#
|
224
|
-
def self.check_class_collision(options={})
|
224
|
+
def self.check_class_collision(options = {}) # :doc:
|
225
225
|
define_method :check_class_collision do
|
226
|
-
name = if
|
226
|
+
name = if respond_to?(:controller_class_name) # for ScaffoldBase
|
227
227
|
controller_class_name
|
228
228
|
else
|
229
229
|
class_name
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators/app_base"
|
2
2
|
|
3
3
|
module Rails
|
4
4
|
module ActionMethods # :nodoc:
|
@@ -53,14 +53,20 @@ module Rails
|
|
53
53
|
template "gitignore", ".gitignore"
|
54
54
|
end
|
55
55
|
|
56
|
+
def version_control
|
57
|
+
if !options[:skip_git] && !options[:pretend]
|
58
|
+
run "git init"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
56
62
|
def app
|
57
|
-
directory
|
63
|
+
directory "app"
|
58
64
|
|
59
|
-
keep_file
|
60
|
-
empty_directory_with_keep_file
|
65
|
+
keep_file "app/assets/images"
|
66
|
+
empty_directory_with_keep_file "app/assets/javascripts/channels" unless options[:skip_action_cable]
|
61
67
|
|
62
|
-
keep_file
|
63
|
-
keep_file
|
68
|
+
keep_file "app/controllers/concerns"
|
69
|
+
keep_file "app/models/concerns"
|
64
70
|
end
|
65
71
|
|
66
72
|
def bin
|
@@ -89,24 +95,24 @@ module Rails
|
|
89
95
|
end
|
90
96
|
|
91
97
|
def config_when_updating
|
92
|
-
cookie_serializer_config_exist = File.exist?(
|
93
|
-
action_cable_config_exist = File.exist?(
|
94
|
-
rack_cors_config_exist = File.exist?(
|
98
|
+
cookie_serializer_config_exist = File.exist?("config/initializers/cookies_serializer.rb")
|
99
|
+
action_cable_config_exist = File.exist?("config/cable.yml")
|
100
|
+
rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
|
95
101
|
|
96
102
|
config
|
97
103
|
|
98
|
-
gsub_file
|
104
|
+
gsub_file "config/environments/development.rb", /^(\s+)config\.file_watcher/, '\1# config.file_watcher'
|
99
105
|
|
100
106
|
unless cookie_serializer_config_exist
|
101
|
-
gsub_file
|
107
|
+
gsub_file "config/initializers/cookies_serializer.rb", /json(?!,)/, "marshal"
|
102
108
|
end
|
103
109
|
|
104
110
|
unless action_cable_config_exist
|
105
|
-
template
|
111
|
+
template "config/cable.yml"
|
106
112
|
end
|
107
113
|
|
108
114
|
unless rack_cors_config_exist
|
109
|
-
remove_file
|
115
|
+
remove_file "config/initializers/cors.rb"
|
110
116
|
end
|
111
117
|
end
|
112
118
|
|
@@ -119,13 +125,13 @@ module Rails
|
|
119
125
|
end
|
120
126
|
|
121
127
|
def lib
|
122
|
-
empty_directory
|
123
|
-
empty_directory_with_keep_file
|
124
|
-
empty_directory_with_keep_file
|
128
|
+
empty_directory "lib"
|
129
|
+
empty_directory_with_keep_file "lib/tasks"
|
130
|
+
empty_directory_with_keep_file "lib/assets"
|
125
131
|
end
|
126
132
|
|
127
133
|
def log
|
128
|
-
empty_directory_with_keep_file
|
134
|
+
empty_directory_with_keep_file "log"
|
129
135
|
end
|
130
136
|
|
131
137
|
def public_directory
|
@@ -133,15 +139,21 @@ module Rails
|
|
133
139
|
end
|
134
140
|
|
135
141
|
def test
|
136
|
-
empty_directory_with_keep_file
|
137
|
-
empty_directory_with_keep_file
|
138
|
-
empty_directory_with_keep_file
|
139
|
-
empty_directory_with_keep_file
|
140
|
-
empty_directory_with_keep_file
|
141
|
-
empty_directory_with_keep_file
|
142
|
-
empty_directory_with_keep_file
|
143
|
-
|
144
|
-
template
|
142
|
+
empty_directory_with_keep_file "test/fixtures"
|
143
|
+
empty_directory_with_keep_file "test/fixtures/files"
|
144
|
+
empty_directory_with_keep_file "test/controllers"
|
145
|
+
empty_directory_with_keep_file "test/mailers"
|
146
|
+
empty_directory_with_keep_file "test/models"
|
147
|
+
empty_directory_with_keep_file "test/helpers"
|
148
|
+
empty_directory_with_keep_file "test/integration"
|
149
|
+
|
150
|
+
template "test/test_helper.rb"
|
151
|
+
end
|
152
|
+
|
153
|
+
def system_test
|
154
|
+
empty_directory_with_keep_file "test/system"
|
155
|
+
|
156
|
+
template "test/application_system_test_case.rb"
|
145
157
|
end
|
146
158
|
|
147
159
|
def tmp
|
@@ -151,19 +163,12 @@ module Rails
|
|
151
163
|
end
|
152
164
|
|
153
165
|
def vendor
|
154
|
-
|
155
|
-
vendor_stylesheets
|
156
|
-
end
|
166
|
+
empty_directory_with_keep_file "vendor"
|
157
167
|
|
158
|
-
|
159
|
-
|
160
|
-
empty_directory_with_keep_file 'vendor/assets/javascripts'
|
168
|
+
unless options[:skip_yarn]
|
169
|
+
template "package.json"
|
161
170
|
end
|
162
171
|
end
|
163
|
-
|
164
|
-
def vendor_stylesheets
|
165
|
-
empty_directory_with_keep_file 'vendor/assets/stylesheets'
|
166
|
-
end
|
167
172
|
end
|
168
173
|
|
169
174
|
module Generators
|
@@ -182,20 +187,21 @@ module Rails
|
|
182
187
|
class_option :api, type: :boolean,
|
183
188
|
desc: "Preconfigure smaller stack for API only apps"
|
184
189
|
|
190
|
+
class_option :skip_bundle, type: :boolean, aliases: "-B", default: false,
|
191
|
+
desc: "Don't run bundle install"
|
192
|
+
|
185
193
|
def initialize(*args)
|
186
194
|
super
|
187
195
|
|
188
|
-
unless app_path
|
189
|
-
raise Error, "Application name should be provided in arguments. For details run: rails --help"
|
190
|
-
end
|
191
|
-
|
192
196
|
if !options[:skip_active_record] && !DATABASES.include?(options[:database])
|
193
197
|
raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}."
|
194
198
|
end
|
195
199
|
|
196
|
-
# Force sprockets to be skipped when generating API only apps.
|
200
|
+
# Force sprockets and yarn to be skipped when generating API only apps.
|
197
201
|
# Can't modify options hash as it's frozen by default.
|
198
|
-
|
202
|
+
if options[:api]
|
203
|
+
self.options = options.merge(skip_sprockets: true, skip_javascript: true, skip_yarn: true).freeze
|
204
|
+
end
|
199
205
|
end
|
200
206
|
|
201
207
|
public_task :set_default_accessors!
|
@@ -205,8 +211,9 @@ module Rails
|
|
205
211
|
build(:readme)
|
206
212
|
build(:rakefile)
|
207
213
|
build(:configru)
|
208
|
-
build(:gitignore)
|
209
|
-
build(:gemfile)
|
214
|
+
build(:gitignore) unless options[:skip_git]
|
215
|
+
build(:gemfile) unless options[:skip_gemfile]
|
216
|
+
build(:version_control)
|
210
217
|
end
|
211
218
|
|
212
219
|
def create_app_files
|
@@ -241,6 +248,7 @@ module Rails
|
|
241
248
|
end
|
242
249
|
|
243
250
|
def create_db_files
|
251
|
+
return if options[:skip_active_record]
|
244
252
|
build(:db)
|
245
253
|
end
|
246
254
|
|
@@ -260,68 +268,74 @@ module Rails
|
|
260
268
|
build(:test) unless options[:skip_test]
|
261
269
|
end
|
262
270
|
|
271
|
+
def create_system_test_files
|
272
|
+
build(:system_test) unless options[:skip_system_test] || options[:skip_test] || options[:api]
|
273
|
+
end
|
274
|
+
|
263
275
|
def create_tmp_files
|
264
276
|
build(:tmp)
|
265
277
|
end
|
266
278
|
|
267
279
|
def create_vendor_files
|
268
280
|
build(:vendor)
|
281
|
+
|
282
|
+
if options[:skip_yarn]
|
283
|
+
remove_file "package.json"
|
284
|
+
end
|
269
285
|
end
|
270
286
|
|
271
287
|
def delete_app_assets_if_api_option
|
272
288
|
if options[:api]
|
273
|
-
remove_dir
|
274
|
-
remove_dir
|
275
|
-
remove_dir
|
276
|
-
remove_dir 'vendor/assets'
|
289
|
+
remove_dir "app/assets"
|
290
|
+
remove_dir "lib/assets"
|
291
|
+
remove_dir "tmp/cache/assets"
|
277
292
|
end
|
278
293
|
end
|
279
294
|
|
280
295
|
def delete_app_helpers_if_api_option
|
281
296
|
if options[:api]
|
282
|
-
remove_dir
|
283
|
-
remove_dir
|
297
|
+
remove_dir "app/helpers"
|
298
|
+
remove_dir "test/helpers"
|
284
299
|
end
|
285
300
|
end
|
286
301
|
|
287
302
|
def delete_application_layout_file_if_api_option
|
288
303
|
if options[:api]
|
289
|
-
remove_file
|
304
|
+
remove_file "app/views/layouts/application.html.erb"
|
290
305
|
end
|
291
306
|
end
|
292
307
|
|
293
308
|
def delete_public_files_if_api_option
|
294
309
|
if options[:api]
|
295
|
-
remove_file
|
296
|
-
remove_file
|
297
|
-
remove_file
|
298
|
-
remove_file
|
299
|
-
remove_file
|
300
|
-
remove_file
|
310
|
+
remove_file "public/404.html"
|
311
|
+
remove_file "public/422.html"
|
312
|
+
remove_file "public/500.html"
|
313
|
+
remove_file "public/apple-touch-icon-precomposed.png"
|
314
|
+
remove_file "public/apple-touch-icon.png"
|
315
|
+
remove_file "public/favicon.ico"
|
301
316
|
end
|
302
317
|
end
|
303
318
|
|
304
319
|
def delete_js_folder_skipping_javascript
|
305
320
|
if options[:skip_javascript]
|
306
|
-
remove_dir
|
321
|
+
remove_dir "app/assets/javascripts"
|
307
322
|
end
|
308
323
|
end
|
309
324
|
|
310
325
|
def delete_assets_initializer_skipping_sprockets
|
311
326
|
if options[:skip_sprockets]
|
312
|
-
remove_file
|
327
|
+
remove_file "config/initializers/assets.rb"
|
313
328
|
end
|
314
329
|
end
|
315
330
|
|
316
331
|
def delete_application_record_skipping_active_record
|
317
332
|
if options[:skip_active_record]
|
318
|
-
remove_file
|
333
|
+
remove_file "app/models/application_record.rb"
|
319
334
|
end
|
320
335
|
end
|
321
336
|
|
322
337
|
def delete_action_mailer_files_skipping_action_mailer
|
323
338
|
if options[:skip_action_mailer]
|
324
|
-
remove_file "app/mailers/application_mailer.rb"
|
325
339
|
remove_file "app/views/layouts/mailer.html.erb"
|
326
340
|
remove_file "app/views/layouts/mailer.text.erb"
|
327
341
|
remove_dir "app/mailers"
|
@@ -331,49 +345,52 @@ module Rails
|
|
331
345
|
|
332
346
|
def delete_action_cable_files_skipping_action_cable
|
333
347
|
if options[:skip_action_cable]
|
334
|
-
remove_file
|
335
|
-
remove_file
|
336
|
-
remove_dir
|
348
|
+
remove_file "config/cable.yml"
|
349
|
+
remove_file "app/assets/javascripts/cable.js"
|
350
|
+
remove_dir "app/channels"
|
337
351
|
end
|
338
352
|
end
|
339
353
|
|
340
354
|
def delete_non_api_initializers_if_api_option
|
341
355
|
if options[:api]
|
342
|
-
remove_file
|
343
|
-
remove_file 'config/initializers/cookies_serializer.rb'
|
356
|
+
remove_file "config/initializers/cookies_serializer.rb"
|
344
357
|
end
|
345
358
|
end
|
346
359
|
|
347
360
|
def delete_api_initializers
|
348
361
|
unless options[:api]
|
349
|
-
remove_file
|
362
|
+
remove_file "config/initializers/cors.rb"
|
350
363
|
end
|
351
364
|
end
|
352
365
|
|
366
|
+
def delete_bin_yarn_if_skip_yarn_option
|
367
|
+
remove_file "bin/yarn" if options[:skip_yarn]
|
368
|
+
end
|
369
|
+
|
353
370
|
def finish_template
|
354
371
|
build(:leftovers)
|
355
372
|
end
|
356
373
|
|
357
374
|
public_task :apply_rails_template, :run_bundle
|
358
|
-
public_task :generate_spring_binstubs
|
375
|
+
public_task :run_webpack, :generate_spring_binstubs
|
359
376
|
|
360
377
|
def run_after_bundle_callbacks
|
361
378
|
@after_bundle_callbacks.each(&:call)
|
362
379
|
end
|
363
380
|
|
364
|
-
protected
|
365
|
-
|
366
381
|
def self.banner
|
367
|
-
"rails new #{
|
382
|
+
"rails new #{arguments.map(&:usage).join(' ')} [options]"
|
368
383
|
end
|
369
384
|
|
385
|
+
private
|
386
|
+
|
370
387
|
# Define file as an alias to create_file for backwards compatibility.
|
371
388
|
def file(*args, &block)
|
372
389
|
create_file(*args, &block)
|
373
390
|
end
|
374
391
|
|
375
392
|
def app_name
|
376
|
-
@app_name ||= (defined_app_const_base? ? defined_app_name : File.basename(destination_root)).tr('\\',
|
393
|
+
@app_name ||= (defined_app_const_base? ? defined_app_name : File.basename(destination_root)).tr('\\', "").tr(". ", "_")
|
377
394
|
end
|
378
395
|
|
379
396
|
def defined_app_name
|
@@ -388,7 +405,7 @@ module Rails
|
|
388
405
|
alias :defined_app_const_base? :defined_app_const_base
|
389
406
|
|
390
407
|
def app_const_base
|
391
|
-
@app_const_base ||= defined_app_const_base || app_name.gsub(/\W/,
|
408
|
+
@app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, "_").squeeze("_").camelize
|
392
409
|
end
|
393
410
|
alias :camelized :app_const_base
|
394
411
|
|
@@ -423,7 +440,7 @@ module Rails
|
|
423
440
|
"/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
|
424
441
|
"/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
|
425
442
|
"/opt/lampp/var/mysql/mysql.sock" # xampp for linux
|
426
|
-
].find { |f| File.exist?(f) } unless
|
443
|
+
].find { |f| File.exist?(f) } unless Gem.win_platform?
|
427
444
|
end
|
428
445
|
|
429
446
|
def get_builder_class
|
@@ -451,14 +468,14 @@ module Rails
|
|
451
468
|
end
|
452
469
|
|
453
470
|
def self.default_rc_file
|
454
|
-
File.expand_path(
|
471
|
+
File.expand_path("~/.railsrc")
|
455
472
|
end
|
456
473
|
|
457
474
|
private
|
458
475
|
|
459
476
|
def handle_version_request!(argument)
|
460
|
-
if [
|
461
|
-
require
|
477
|
+
if ["--version", "-v"].include?(argument)
|
478
|
+
require "rails/version"
|
462
479
|
puts "Rails #{Rails::VERSION::STRING}"
|
463
480
|
exit(0)
|
464
481
|
end
|
@@ -468,20 +485,20 @@ module Rails
|
|
468
485
|
if argument == "new"
|
469
486
|
yield
|
470
487
|
else
|
471
|
-
[
|
488
|
+
["--help"] + argv.drop(1)
|
472
489
|
end
|
473
490
|
end
|
474
491
|
|
475
492
|
def handle_rails_rc!(argv)
|
476
|
-
if argv.find { |arg| arg ==
|
477
|
-
argv.reject { |arg| arg ==
|
493
|
+
if argv.find { |arg| arg == "--no-rc" }
|
494
|
+
argv.reject { |arg| arg == "--no-rc" }
|
478
495
|
else
|
479
496
|
railsrc(argv) { |rc_argv, rc| insert_railsrc_into_argv!(rc_argv, rc) }
|
480
497
|
end
|
481
498
|
end
|
482
499
|
|
483
500
|
def railsrc(argv)
|
484
|
-
if (customrc = argv.index{ |x| x.include?("--rc=") })
|
501
|
+
if (customrc = argv.index { |x| x.include?("--rc=") })
|
485
502
|
fname = File.expand_path(argv[customrc].gsub(/--rc=/, ""))
|
486
503
|
yield(argv.take(customrc) + argv.drop(customrc + 1), fname)
|
487
504
|
else
|