Sha256: e94f4132fa0f366dcfd978d4cb6a342ca35359e5e6d558efdad14aa54448843c

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8
require 'rails_best_practices/reviews/review'

module RailsBestPractices
  module Reviews
    # Review a partail view file to make sure there is no instance variable.
    #
    # See the best practice details here http://rails-bestpractices.com/posts/27-replace-instance-variable-with-local-variable.
    #
    # Implementation:
    #
    # Review process:
    #   check all instance variable in partial view files,
    #   if exist, then they should be replaced with local variable
    class ReplaceInstanceVariableWithLocalVariableReview < Review
      interesting_nodes :var_ref, :vcall
      interesting_files PARTIAL_VIEW_FILES

      def url
        "http://rails-bestpractices.com/posts/27-replace-instance-variable-with-local-variable"
      end

      # check ivar node in partial view file,
      # it is an instance variable, and should be replaced with local variable.
      def start_var_ref(node)
        if node.to_s.start_with?('@')
          add_error "replace instance variable with local variable"
        end
      end

      # check ivar node in partial view file,
      # it is an instance variable, and should be replaced with local variable.
      def start_vcall(node)
        if node.to_s.start_with?('@')
          add_error "replace instance variable with local variable"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
rails_best_practices-gorgeouscode-1.0.0 lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb
rails_best_practices-1.9.1 lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb
rails_best_practices-1.9.0 lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb