mirror of https://github.com/rails/rails
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.
This commit is contained in:
parent
bffe05f246
commit
cc63348160
|
@ -23,19 +23,26 @@ module ActionCable
|
|||
serialize_broadcasting([ channel_name, model ])
|
||||
end
|
||||
|
||||
def serialize_broadcasting(object) # :nodoc:
|
||||
case
|
||||
when object.is_a?(Array)
|
||||
object.map { |m| serialize_broadcasting(m) }.join(":")
|
||||
when object.respond_to?(:to_gid_param)
|
||||
object.to_gid_param
|
||||
else
|
||||
object.to_param
|
||||
private
|
||||
def serialize_broadcasting(object) # :nodoc:
|
||||
case
|
||||
when object.is_a?(Array)
|
||||
object.map { |m| serialize_broadcasting(m) }.join(":")
|
||||
when object.respond_to?(:to_gid_param)
|
||||
object.to_gid_param
|
||||
else
|
||||
object.to_param
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ActiveSupport::Delegation.generate(self, [:broadcasting_for, :broadcast_to], to: :class, as: ClassMethods)
|
||||
def broadcasting_for(model)
|
||||
self.class.broadcasting_for(model)
|
||||
end
|
||||
|
||||
def broadcast_to(model, message)
|
||||
self.class.broadcast_to(model, message)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,9 @@ module ActionCable
|
|||
end
|
||||
end
|
||||
|
||||
ActiveSupport::Delegation.generate(self, [:channel_name], to: :class, as: ClassMethods)
|
||||
def channel_name
|
||||
self.class.channel_name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue