Class: RailsBestPractices::Checks::UseBeforeFilterCheck

### Home Classes Methods

### In Files

- lib/rails_best_practices/checks/use_before_filter_check.rb

### Parent

RailsBestPractices::Checks::Check

### Methods

- #evaluate_start
- #interesting_files
- #interesting_nodes

### Files

- LICENSE

### Class/Module Index

Quicksearch

- RailsBestPractices
- RailsBestPractices::Checks
- RailsBestPractices::Checks::AddModelVirtualAttributeCheck
- RailsBestPractices::Checks::AlwaysAddDbIndexCheck
- RailsBestPractices::Checks::Check
- RailsBestPractices::Checks::IsolateSeedDataCheck
- RailsBestPractices::Checks::KeepFindersOnTheirOwnModelCheck
- RailsBestPractices::Checks::LawOfDemeterCheck
- RailsBestPractices::Checks::ManyToManyCollectionCheck
- RailsBestPractices::Checks::MoveCodeIntoControllerCheck
- RailsBestPractices::Checks::MoveCodeIntoHelperCheck
- RailsBestPractices::Checks::MoveCodeIntoModelCheck
- RailsBestPractices::Checks::MoveFinderToNamedScopeCheck
- RailsBestPractices::Checks::MoveModelLogicIntoModelCheck
- RailsBestPractices::Checks::NeedlessDeepNestingCheck
- RailsBestPractices::Checks::NestedModelFormsCheck
- RailsBestPractices::Checks::NotUseDefaultRouteCheck
- RailsBestPractices::Checks::OveruseRouteCustomizationsCheck
- RailsBestPractices::Checks::ReplaceComplexCreationWithFactoryMethodCheck
- RailsBestPractices::Checks::ReplaceInstanceVariableWithLocalVariableCheck
- RailsBestPractices::Checks::UseBeforeFilterCheck
- RailsBestPractices::Checks::UseModelAssociationCheck
- RailsBestPractices::Checks::UseModelCallbackCheck
- RailsBestPractices::Checks::UseObserverCheck
- RailsBestPractices::Checks::UseScopeAccessCheck
- RailsBestPractices::Core
- RailsBestPractices::Core::CheckingVisitor
- RailsBestPractices::Core::Error
- RailsBestPractices::Core::Runner
- Enumerable
- NilClass
- Sexp
- String

No matching classes.

# RailsBestPractices::Checks::UseBeforeFilterCheck

Check a controller file to make sure to use before_filter to remove duplicate call in different action.

Implementation: Check all methods’ first call, if they are duplicate, then should use before_filter.

### Public Instance Methods

evaluate_start(node) click to toggle source

    # File lib/rails_best_practices/checks/use_before_filter_check.rb, line 18
    def evaluate_start(node)
      @methods = {}
      node.grep_nodes({:node_type => :defn}).each { |method_node| remember_method(method_node) }
      @methods.each do |first_call, method_nodes|
        if method_nodes.size > 1
          add_error "use before_filter for #{method_nodes.collect{|method_node| method_node.message_name}.join(',')}",
            node.file, method_nodes.collect{|method_node| method_node.line}.join(',')
        end
      end
    end

interesting_files() click to toggle source

    # File lib/rails_best_practices/checks/use_before_filter_check.rb, line 14
    def interesting_files
      CONTROLLER_FILES
    end

interesting_nodes() click to toggle source

    # File lib/rails_best_practices/checks/use_before_filter_check.rb, line 10
    def interesting_nodes
      [:class]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.