Skip to content

Commit 91fa2b7

Browse files
committed
Privatize unneededly protected methods in Action Cable
1 parent 102ee40 commit 91fa2b7

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

actioncable/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module ApplicationCable
5151
self.current_user = find_verified_user
5252
end
5353

54-
protected
54+
private
5555
def find_verified_user
5656
if current_user = User.find_by(id: cookies.signed[:user_id])
5757
current_user

actioncable/lib/action_cable/channel/base.rb

+13-14
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ def action_methods
122122
end
123123
end
124124

125-
protected
125+
private
126126
# action_methods are cached and there is sometimes need to refresh
127127
# them. ::clear_action_methods! allows you to do that, so next time
128128
# you run action_methods, they will be recalculated.
129-
def clear_action_methods!
129+
def clear_action_methods! # :doc:
130130
@action_methods = nil
131131
end
132132

133133
# Refresh the cached action_methods when a new action_method is added.
134-
def method_added(name)
134+
def method_added(name) # :doc:
135135
super
136136
clear_action_methods!
137137
end
@@ -189,22 +189,22 @@ def unsubscribe_from_channel # :nodoc:
189189
end
190190
end
191191

192-
protected
192+
private
193193
# Called once a consumer has become a subscriber of the channel. Usually the place to setup any streams
194194
# you want this channel to be sending to the subscriber.
195-
def subscribed
195+
def subscribed # :doc:
196196
# Override in subclasses
197197
end
198198

199199
# Called once a consumer has cut its cable connection. Can be used for cleaning up connections or marking
200200
# users as offline or the like.
201-
def unsubscribed
201+
def unsubscribed # :doc:
202202
# Override in subclasses
203203
end
204204

205205
# Transmit a hash of data to the subscriber. The hash will automatically be wrapped in a JSON envelope with
206206
# the proper channel identifier marked as the recipient.
207-
def transmit(data, via: nil)
207+
def transmit(data, via: nil) # :doc:
208208
logger.info "#{self.class.name} transmitting #{data.inspect.truncate(300)}".tap { |m| m << " (via #{via})" if via }
209209

210210
payload = { channel_class: self.class.name, data: data, via: via }
@@ -213,33 +213,32 @@ def transmit(data, via: nil)
213213
end
214214
end
215215

216-
def ensure_confirmation_sent
216+
def ensure_confirmation_sent # :doc:
217217
return if subscription_rejected?
218218
@defer_subscription_confirmation_counter.decrement
219219
transmit_subscription_confirmation unless defer_subscription_confirmation?
220220
end
221221

222-
def defer_subscription_confirmation!
222+
def defer_subscription_confirmation! # :doc:
223223
@defer_subscription_confirmation_counter.increment
224224
end
225225

226-
def defer_subscription_confirmation?
226+
def defer_subscription_confirmation? # :doc:
227227
@defer_subscription_confirmation_counter.value > 0
228228
end
229229

230-
def subscription_confirmation_sent?
230+
def subscription_confirmation_sent? # :doc:
231231
@subscription_confirmation_sent
232232
end
233233

234-
def reject
234+
def reject # :doc:
235235
@reject_subscription = true
236236
end
237237

238-
def subscription_rejected?
238+
def subscription_rejected? # :doc:
239239
@reject_subscription
240240
end
241241

242-
private
243242
def delegate_connection_identifiers
244243
connection.identifiers.each do |identifier|
245244
define_singleton_method(identifier) do

actioncable/lib/action_cable/connection/base.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Connection
2222
# # Any cleanup work needed when the cable connection is cut.
2323
# end
2424
#
25-
# protected
25+
# private
2626
# def find_verified_user
2727
# User.find_by_identity(cookies.signed[:identity_id]) ||
2828
# reject_unauthorized_connection
@@ -136,23 +136,23 @@ def on_close(reason, code) # :nodoc:
136136
# TODO Change this to private once we've dropped Ruby 2.2 support.
137137
# Workaround for Ruby 2.2 "private attribute?" warning.
138138
protected
139+
attr_reader :websocket
140+
attr_reader :message_buffer
141+
142+
private
139143
# The request that initiated the WebSocket connection is available here. This gives access to the environment, cookies, etc.
140-
def request
144+
def request # :doc:
141145
@request ||= begin
142146
environment = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
143147
ActionDispatch::Request.new(environment || env)
144148
end
145149
end
146150

147151
# The cookies of the request that initiated the WebSocket connection. Useful for performing authorization checks.
148-
def cookies
152+
def cookies # :doc:
149153
request.cookie_jar
150154
end
151155

152-
attr_reader :websocket
153-
attr_reader :message_buffer
154-
155-
private
156156
def encode(cable_message)
157157
@coder.encode cable_message
158158
end

actioncable/lib/action_cable/connection/tagged_logger_proxy.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def tag(logger)
3131
end
3232
end
3333

34-
protected
35-
def log(type, message)
34+
private
35+
def log(type, message) # :doc:
3636
tag(@logger) { @logger.send type, message }
3737
end
3838
end

actioncable/lib/rails/generators/channel/channel_generator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def create_channel_file
2323
generate_application_cable_files
2424
end
2525

26-
protected
26+
private
2727
def file_name
2828
@_file_name ||= super.gsub(/_channel/i, "")
2929
end

0 commit comments

Comments
 (0)