class RuboCop::Cop::AnyCable::InstanceVars
end
end
stream_from post
post = Post.find(params)
def subscribed
class MyChannel < ApplicationCable::Channel
# good
end
end
stream_from @post
@post = Post.find(params)
def subscribed
class MyChannel < ApplicationCable::Channel
# bad
@example
Checks for instance variable usage inside subscriptions.
def find_nested_ivars(node, &block)
def find_nested_ivars(node, &block) node.each_child_node do |child| if child.ivasgn_type? || child.ivar_type? yield(child) elsif child.children.any? find_nested_ivars(child, &block) end end end
def on_class(node)
def on_class(node) find_nested_ivars(node) do |nested_ivar| add_offense(nested_ivar) end end