Skip to content

Commit d1daf4c

Browse files
committed
Privatize unneededly protected methods in Railties
1 parent 6b04905 commit d1daf4c

File tree

25 files changed

+136
-135
lines changed

25 files changed

+136
-135
lines changed

railties/lib/rails/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Rails::ApplicationController < ActionController::Base # :nodoc:
22
self.view_paths = File.expand_path("../templates", __FILE__)
33
layout "application"
44

5-
protected
5+
private
66

77
def require_local!
88
unless local_request?

railties/lib/rails/command.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ def sorted_groups # :nodoc:
8282
[[ "rails", rails ]] + groups.sort.to_a
8383
end
8484

85-
protected
86-
def command_type
85+
private
86+
def command_type # :doc:
8787
@command_type ||= "command"
8888
end
8989

90-
def lookup_paths
90+
def lookup_paths # :doc:
9191
@lookup_paths ||= %w( rails/commands commands )
9292
end
9393

94-
def file_lookup_paths
94+
def file_lookup_paths # :doc:
9595
@file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_command.rb" ]
9696
end
9797
end

railties/lib/rails/command/behavior.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def subclasses
1616
@subclasses ||= []
1717
end
1818

19-
protected
19+
private
2020

2121
# This code is based directly on the Text gem implementation.
2222
# Copyright (c) 2006-2013 Paul Battley, Michael Neumann, Tim Fletcher.
2323
#
2424
# Returns a value representing the "cost" of transforming str1 into str2.
25-
def levenshtein_distance(str1, str2)
25+
def levenshtein_distance(str1, str2) # :doc:
2626
s = str1
2727
t = str2
2828
n = s.length
@@ -58,7 +58,7 @@ def levenshtein_distance(str1, str2)
5858
end
5959

6060
# Prints a list of generators.
61-
def print_list(base, namespaces) #:nodoc:
61+
def print_list(base, namespaces)
6262
return if namespaces.empty?
6363
puts "#{base.camelize}:"
6464

@@ -71,7 +71,7 @@ def print_list(base, namespaces) #:nodoc:
7171

7272
# Receives namespaces in an array and tries to find matching generators
7373
# in the load path.
74-
def lookup(namespaces) #:nodoc:
74+
def lookup(namespaces)
7575
paths = namespaces_to_paths(namespaces)
7676

7777
paths.each do |raw_path|
@@ -91,7 +91,7 @@ def lookup(namespaces) #:nodoc:
9191
end
9292

9393
# This will try to load any command in the load path to show in help.
94-
def lookup! #:nodoc:
94+
def lookup!
9595
$LOAD_PATH.each do |base|
9696
Dir[File.join(base, *file_lookup_paths)].each do |path|
9797
begin
@@ -107,7 +107,7 @@ def lookup! #:nodoc:
107107
# Convert namespaces to paths by replacing ":" for "/" and adding
108108
# an extra lookup. For example, "rails:model" should be searched
109109
# in both: "rails/model/model_generator" and "rails/model_generator".
110-
def namespaces_to_paths(namespaces) #:nodoc:
110+
def namespaces_to_paths(namespaces)
111111
paths = []
112112
namespaces.each do |namespace|
113113
pieces = namespace.split(":")

railties/lib/rails/commands/dbconsole/dbconsole_command.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ def environment
9999
Rails.respond_to?(:env) ? Rails.env : Rails::Command.environment
100100
end
101101

102-
protected
103-
def configurations
102+
private
103+
def configurations # :doc:
104104
require APP_PATH
105105
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
106106
ActiveRecord::Base.configurations
107107
end
108108

109-
def find_cmd_and_exec(commands, *args)
109+
def find_cmd_and_exec(commands, *args) # :doc:
110110
commands = Array(commands)
111111

112112
dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR)

railties/lib/rails/engine.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -643,18 +643,20 @@ def routes? #:nodoc:
643643

644644
protected
645645

646-
def load_config_initializer(initializer)
647-
ActiveSupport::Notifications.instrument("load_config_initializer.railties", initializer: initializer) do
648-
load(initializer)
649-
end
650-
end
651-
652646
def run_tasks_blocks(*) #:nodoc:
653647
super
654648
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
655649
end
656650

657-
def has_migrations? #:nodoc:
651+
private
652+
653+
def load_config_initializer(initializer) # :doc:
654+
ActiveSupport::Notifications.instrument("load_config_initializer.railties", initializer: initializer) do
655+
load(initializer)
656+
end
657+
end
658+
659+
def has_migrations?
658660
paths["db/migrate"].existent.any?
659661
end
660662

@@ -671,24 +673,22 @@ def self.find_root_with_flag(flag, root_path, default = nil) #:nodoc:
671673
Pathname.new File.realpath root
672674
end
673675

674-
def default_middleware_stack #:nodoc:
676+
def default_middleware_stack
675677
ActionDispatch::MiddlewareStack.new
676678
end
677679

678-
def _all_autoload_once_paths #:nodoc:
680+
def _all_autoload_once_paths
679681
config.autoload_once_paths
680682
end
681683

682-
def _all_autoload_paths #:nodoc:
684+
def _all_autoload_paths
683685
@_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq
684686
end
685687

686-
def _all_load_paths #:nodoc:
688+
def _all_load_paths
687689
@_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq
688690
end
689691

690-
private
691-
692692
def build_request(env)
693693
env.merge!(env_config)
694694
req = ActionDispatch::Request.new env

railties/lib/rails/generators/actions.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ def after_bundle(&block)
260260
@after_bundle_callbacks << block
261261
end
262262

263-
protected
263+
private
264264

265265
# Define log for backwards compatibility. If just one argument is sent,
266266
# invoke say, otherwise invoke say_status. Differently from say and
267267
# similarly to say_status, this method respects the quiet? option given.
268-
def log(*args)
268+
def log(*args) # :doc:
269269
if args.size == 1
270270
say args.first.to_s unless options.quiet?
271271
else
@@ -276,15 +276,15 @@ def log(*args)
276276

277277
# Runs the supplied command using either "rake ..." or "rails ..."
278278
# based on the executor parameter provided.
279-
def execute_command(executor, command, options = {})
279+
def execute_command(executor, command, options = {}) # :doc:
280280
log executor, command
281281
env = options[:env] || ENV["RAILS_ENV"] || "development"
282282
sudo = options[:sudo] && !Gem.win_platform? ? "sudo " : ""
283283
in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", verbose: false) }
284284
end
285285

286286
# Add an extension to the given name based on the platform.
287-
def extify(name)
287+
def extify(name) # :doc:
288288
if Gem.win_platform?
289289
"#{name}.bat"
290290
else
@@ -294,7 +294,7 @@ def extify(name)
294294

295295
# Surround string with single quotes if there is no quotes.
296296
# Otherwise fall back to double quotes
297-
def quote(value)
297+
def quote(value) # :doc:
298298
return value.inspect unless value.is_a? String
299299

300300
if value.include?("'")

railties/lib/rails/generators/actions/create_migration.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def existing_migration
3737
end
3838
alias :exists? :existing_migration
3939

40-
protected
40+
private
4141

42-
def on_conflict_behavior
42+
def on_conflict_behavior # :doc:
4343
options = base.options.merge(config)
4444
if identical?
4545
say_status :identical, :blue, relative_existing_migration
@@ -60,7 +60,7 @@ def on_conflict_behavior
6060
end
6161
end
6262

63-
def say_status(status, color, message = relative_destination)
63+
def say_status(status, color, message = relative_destination) # :doc:
6464
base.shell.say_status(status, message, color) if config[:verbose]
6565
end
6666
end

railties/lib/rails/generators/app_base.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ def initialize(*args)
108108
convert_database_option_for_jruby
109109
end
110110

111-
protected
111+
private
112112

113-
def gemfile_entry(name, *args)
113+
def gemfile_entry(name, *args) # :doc:
114114
options = args.extract_options!
115115
version = args.first
116116
github = options[:github]
@@ -126,7 +126,7 @@ def gemfile_entry(name, *args)
126126
self
127127
end
128128

129-
def gemfile_entries
129+
def gemfile_entries # :doc:
130130
[rails_gemfile_entry,
131131
database_gemfile_entry,
132132
webserver_gemfile_entry,
@@ -139,38 +139,38 @@ def gemfile_entries
139139
@extra_entries].flatten.find_all(&@gem_filter)
140140
end
141141

142-
def add_gem_entry_filter
142+
def add_gem_entry_filter # :doc:
143143
@gem_filter = lambda { |next_filter, entry|
144144
yield(entry) && next_filter.call(entry)
145145
}.curry[@gem_filter]
146146
end
147147

148-
def builder
148+
def builder # :doc:
149149
@builder ||= begin
150150
builder_class = get_builder_class
151151
builder_class.include(ActionMethods)
152152
builder_class.new(self)
153153
end
154154
end
155155

156-
def build(meth, *args)
156+
def build(meth, *args) # :doc:
157157
builder.send(meth, *args) if builder.respond_to?(meth)
158158
end
159159

160-
def create_root
160+
def create_root # :doc:
161161
valid_const?
162162

163163
empty_directory "."
164164
FileUtils.cd(destination_root) unless options[:pretend]
165165
end
166166

167-
def apply_rails_template
167+
def apply_rails_template # :doc:
168168
apply rails_template if rails_template
169169
rescue Thor::Error, LoadError, Errno::ENOENT => e
170170
raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
171171
end
172172

173-
def set_default_accessors!
173+
def set_default_accessors! # :doc:
174174
self.destination_root = File.expand_path(app_path, destination_root)
175175
self.rails_template = \
176176
case options[:template]
@@ -183,32 +183,32 @@ def set_default_accessors!
183183
end
184184
end
185185

186-
def database_gemfile_entry
186+
def database_gemfile_entry # :doc:
187187
return [] if options[:skip_active_record]
188188
gem_name, gem_version = gem_for_database
189189
GemfileEntry.version gem_name, gem_version,
190190
"Use #{options[:database]} as the database for Active Record"
191191
end
192192

193-
def webserver_gemfile_entry
193+
def webserver_gemfile_entry # :doc:
194194
return [] if options[:skip_puma]
195195
comment = "Use Puma as the app server"
196196
GemfileEntry.new("puma", "~> 3.0", comment)
197197
end
198198

199-
def include_all_railties?
199+
def include_all_railties? # :doc:
200200
options.values_at(:skip_active_record, :skip_action_mailer, :skip_test, :skip_sprockets, :skip_action_cable).none?
201201
end
202202

203-
def comment_if(value)
203+
def comment_if(value) # :doc:
204204
options[value] ? "# " : ""
205205
end
206206

207-
def keeps?
207+
def keeps? # :doc:
208208
!options[:skip_keeps]
209209
end
210210

211-
def sqlite3?
211+
def sqlite3? # :doc:
212212
!options[:skip_active_record] && options[:database] == "sqlite3"
213213
end
214214

0 commit comments

Comments
 (0)