Skip to content

Commit a43e770

Browse files
committed
Privatize unneededly protected methods in Active Support
1 parent 4db99eb commit a43e770

File tree

15 files changed

+46
-56
lines changed

15 files changed

+46
-56
lines changed

activesupport/lib/active_support/cache.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,12 @@ def clear
471471
raise NotImplementedError.new("#{self.class.name} does not support clear")
472472
end
473473

474-
protected
474+
private
475475
# Adds the namespace defined in the options to a pattern designed to
476476
# match keys. Implementations that support delete_matched should call
477477
# this method to translate a pattern that matches names into one that
478478
# matches namespaced keys.
479-
def key_matcher(pattern, options)
479+
def key_matcher(pattern, options) # :doc:
480480
prefix = options[:namespace].is_a?(Proc) ? options[:namespace].call : options[:namespace]
481481
if prefix
482482
source = pattern.source
@@ -493,23 +493,22 @@ def key_matcher(pattern, options)
493493

494494
# Reads an entry from the cache implementation. Subclasses must implement
495495
# this method.
496-
def read_entry(key, options) # :nodoc:
496+
def read_entry(key, options)
497497
raise NotImplementedError.new
498498
end
499499

500500
# Writes an entry to the cache implementation. Subclasses must implement
501501
# this method.
502-
def write_entry(key, entry, options) # :nodoc:
502+
def write_entry(key, entry, options)
503503
raise NotImplementedError.new
504504
end
505505

506506
# Deletes an entry from the cache implementation. Subclasses must
507507
# implement this method.
508-
def delete_entry(key, options) # :nodoc:
508+
def delete_entry(key, options)
509509
raise NotImplementedError.new
510510
end
511511

512-
private
513512
# Merges the default options with ones specific to a method call.
514513
def merged_options(call_options)
515514
if call_options

activesupport/lib/active_support/cache/file_store.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def delete_matched(matcher, options = nil)
6666
end
6767
end
6868

69-
protected
69+
private
7070

7171
def read_entry(key, options)
7272
if File.exist?(key)
@@ -98,7 +98,6 @@ def delete_entry(key, options)
9898
end
9999
end
100100

101-
private
102101
# Lock a file for a block so only one process can modify it at a time.
103102
def lock_file(file_name, &block)
104103
if File.exist?(file_name)

activesupport/lib/active_support/cache/mem_cache_store.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Cache
2626
class MemCacheStore < Store
2727
# Provide support for raw values in the local cache strategy.
2828
module LocalCacheWithRaw # :nodoc:
29-
protected
29+
private
3030
def read_entry(key, options)
3131
entry = super
3232
if options[:raw] && local_cache && entry
@@ -35,7 +35,7 @@ def read_entry(key, options)
3535
entry
3636
end
3737

38-
def write_entry(key, entry, options) # :nodoc:
38+
def write_entry(key, entry, options)
3939
if options[:raw] && local_cache
4040
raw_entry = Entry.new(entry.value.to_s)
4141
raw_entry.expires_at = entry.expires_at
@@ -143,14 +143,14 @@ def stats
143143
@data.stats
144144
end
145145

146-
protected
146+
private
147147
# Read an entry from the cache.
148-
def read_entry(key, options) # :nodoc:
148+
def read_entry(key, options)
149149
rescue_error_with(nil) { deserialize_entry(@data.get(key, options)) }
150150
end
151151

152152
# Write an entry to the cache.
153-
def write_entry(key, entry, options) # :nodoc:
153+
def write_entry(key, entry, options)
154154
method = options && options[:unless_exist] ? :add : :set
155155
value = options[:raw] ? entry.value.to_s : entry
156156
expires_in = options[:expires_in].to_i
@@ -164,12 +164,10 @@ def write_entry(key, entry, options) # :nodoc:
164164
end
165165

166166
# Delete an entry from the cache.
167-
def delete_entry(key, options) # :nodoc:
167+
def delete_entry(key, options)
168168
rescue_error_with(false) { @data.delete(key) }
169169
end
170170

171-
private
172-
173171
# Memcache keys are binaries. So we need to force their encoding to binary
174172
# before applying the regular expression to ensure we are escaping all
175173
# characters properly.

activesupport/lib/active_support/cache/memory_store.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ def synchronize(&block) # :nodoc:
104104
@monitor.synchronize(&block)
105105
end
106106

107-
protected
107+
private
108108

109109
PER_ENTRY_OVERHEAD = 240
110110

111-
def cached_size(key, entry) # :nodoc:
111+
def cached_size(key, entry)
112112
key.to_s.bytesize + entry.size + PER_ENTRY_OVERHEAD
113113
end
114114

115-
def read_entry(key, options) # :nodoc:
115+
def read_entry(key, options)
116116
entry = @data[key]
117117
synchronize do
118118
if entry
@@ -124,7 +124,7 @@ def read_entry(key, options) # :nodoc:
124124
entry
125125
end
126126

127-
def write_entry(key, entry, options) # :nodoc:
127+
def write_entry(key, entry, options)
128128
entry.dup_value!
129129
synchronize do
130130
old_entry = @data[key]
@@ -141,7 +141,7 @@ def write_entry(key, entry, options) # :nodoc:
141141
end
142142
end
143143

144-
def delete_entry(key, options) # :nodoc:
144+
def delete_entry(key, options)
145145
synchronize do
146146
@key_access.delete(key)
147147
entry = @data.delete(key)
@@ -150,8 +150,6 @@ def delete_entry(key, options) # :nodoc:
150150
end
151151
end
152152

153-
private
154-
155153
def modify_value(name, amount, options)
156154
synchronize do
157155
options = merged_options(options)

activesupport/lib/active_support/cache/null_store.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def decrement(name, amount = 1, options = nil)
2525
def delete_matched(matcher, options = nil)
2626
end
2727

28-
protected
29-
def read_entry(key, options) # :nodoc:
28+
private
29+
def read_entry(key, options)
3030
end
3131

32-
def write_entry(key, entry, options) # :nodoc:
32+
def write_entry(key, entry, options)
3333
true
3434
end
3535

36-
def delete_entry(key, options) # :nodoc:
36+
def delete_entry(key, options)
3737
false
3838
end
3939
end

activesupport/lib/active_support/cache/strategy/local_cache.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,26 @@ def decrement(name, amount = 1, options = nil) # :nodoc:
105105
value
106106
end
107107

108-
protected
109-
def read_entry(key, options) # :nodoc:
108+
private
109+
def read_entry(key, options)
110110
if cache = local_cache
111111
cache.fetch_entry(key) { super }
112112
else
113113
super
114114
end
115115
end
116116

117-
def write_entry(key, entry, options) # :nodoc:
117+
def write_entry(key, entry, options)
118118
local_cache.write_entry(key, entry, options) if local_cache
119119
super
120120
end
121121

122-
def delete_entry(key, options) # :nodoc:
122+
def delete_entry(key, options)
123123
local_cache.delete_entry(key, options) if local_cache
124124
super
125125
end
126126

127-
def write_cache_value(name, value, options) # :nodoc:
127+
def write_cache_value(name, value, options)
128128
name = normalize_key(name, options)
129129
cache = local_cache
130130
cache.mute do
@@ -136,8 +136,6 @@ def write_cache_value(name, value, options) # :nodoc:
136136
end
137137
end
138138

139-
private
140-
141139
def local_cache_key
142140
@local_cache_key ||= "#{self.class.name.underscore}_local_cache_#{object_id}".gsub(/[\/-]/, "_").to_sym
143141
end

activesupport/lib/active_support/duration.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ def iso8601(precision: nil)
159159

160160
delegate :<=>, to: :value
161161

162-
protected
162+
private
163163

164-
def sum(sign, time = ::Time.current) #:nodoc:
164+
def sum(sign, time = ::Time.current)
165165
parts.inject(time) do |t, (type, number)|
166166
if t.acts_like?(:time) || t.acts_like?(:date)
167167
if type == :seconds
@@ -179,8 +179,6 @@ def sum(sign, time = ::Time.current) #:nodoc:
179179
end
180180
end
181181

182-
private
183-
184182
def method_missing(method, *args, &block)
185183
value.send(method, *args, &block)
186184
end

activesupport/lib/active_support/hash_with_indifferent_access.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,12 @@ def to_hash
280280
_new_hash
281281
end
282282

283-
protected
284-
def convert_key(key)
283+
private
284+
def convert_key(key) # :doc:
285285
key.kind_of?(Symbol) ? key.to_s : key
286286
end
287287

288-
def convert_value(value, options = {})
288+
def convert_value(value, options = {}) # :doc:
289289
if value.is_a? Hash
290290
if options[:for] == :to_hash
291291
value.to_hash
@@ -302,7 +302,7 @@ def convert_value(value, options = {})
302302
end
303303
end
304304

305-
def set_defaults(target)
305+
def set_defaults(target) # :doc:
306306
if default_proc
307307
target.default_proc = default_proc.dup
308308
else

activesupport/lib/active_support/inflector/methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def ordinalize(number)
361361
#
362362
# const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"
363363
# const_regexp("::") # => "::"
364-
def const_regexp(camel_cased_word) #:nodoc:
364+
def const_regexp(camel_cased_word)
365365
parts = camel_cased_word.split("::".freeze)
366366

367367
return Regexp.escape(camel_cased_word) if parts.blank?

activesupport/lib/active_support/log_subscriber.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def finish(name, id, payload)
8585
logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
8686
end
8787

88-
protected
88+
private
8989

9090
%w(info debug warn error fatal unknown).each do |level|
9191
class_eval <<-METHOD, __FILE__, __LINE__ + 1
@@ -99,7 +99,7 @@ def #{level}(progname = nil, &block)
9999
# option is set to +true+, it also adds bold to the string. This is based
100100
# on the Highline implementation and will automatically append CLEAR to the
101101
# end of the returned String.
102-
def color(text, color, bold = false)
102+
def color(text, color, bold = false) # :doc:
103103
return text unless colorize_logging
104104
color = self.class.const_get(color.upcase) if color.is_a?(Symbol)
105105
bold = bold ? BOLD : ""

0 commit comments

Comments
 (0)