Skip to content

Commit cc63348

Browse files
committed
Replace some low value dynamic delegator by handcrafted ones
Dynamic delegation make sense when there is a long list of methods etc. But for very simple cases, writing one or two methods by hand is just clearer and more efficient.
1 parent bffe05f commit cc63348

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

actioncable/lib/action_cable/channel/broadcasting.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,26 @@ def broadcasting_for(model)
2323
serialize_broadcasting([ channel_name, model ])
2424
end
2525

26-
def serialize_broadcasting(object) # :nodoc:
27-
case
28-
when object.is_a?(Array)
29-
object.map { |m| serialize_broadcasting(m) }.join(":")
30-
when object.respond_to?(:to_gid_param)
31-
object.to_gid_param
32-
else
33-
object.to_param
26+
private
27+
def serialize_broadcasting(object) # :nodoc:
28+
case
29+
when object.is_a?(Array)
30+
object.map { |m| serialize_broadcasting(m) }.join(":")
31+
when object.respond_to?(:to_gid_param)
32+
object.to_gid_param
33+
else
34+
object.to_param
35+
end
3436
end
35-
end
3637
end
3738

38-
ActiveSupport::Delegation.generate(self, [:broadcasting_for, :broadcast_to], to: :class, as: ClassMethods)
39+
def broadcasting_for(model)
40+
self.class.broadcasting_for(model)
41+
end
42+
43+
def broadcast_to(model, message)
44+
self.class.broadcast_to(model, message)
45+
end
3946
end
4047
end
4148
end

actioncable/lib/action_cable/channel/naming.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ def channel_name
1818
end
1919
end
2020

21-
ActiveSupport::Delegation.generate(self, [:channel_name], to: :class, as: ClassMethods)
21+
def channel_name
22+
self.class.channel_name
23+
end
2224
end
2325
end
2426
end

0 commit comments

Comments
 (0)