Class: RuboCop::Cop::AnyCable::InstanceVars

Inherits:
Cop
  • Object
show all
Defined in:
lib/anycable/rails/compatibility/rubocop/cops/anycable/instance_vars.rb

Overview

Checks for instance variable usage inside subscriptions.

Examples:

# bad
class MyChannel < ApplicationCable::Channel
  def subscribed
    @post = Post.find(params[:id])
    stream_from @post
  end
end

# good
class MyChannel < ApplicationCable::Channel
  def subscribed
    post = Post.find(params[:id])
    stream_from post
  end
end

Constant Summary collapse

MSG =
"Channel instance variables are not supported in AnyCable"

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



30
31
32
33
34
# File 'lib/anycable/rails/compatibility/rubocop/cops/anycable/instance_vars.rb', line 30

def on_class(node)
  find_nested_ivars(node) do |nested_ivar|
    add_offense(nested_ivar)
  end
end