Class: RailsBestPractices::Checks::MoveModelLogicIntoModelCheck

### Home Classes Methods

### In Files

- lib/rails_best_practices/checks/move_model_logic_into_model_check.rb

### Parent

RailsBestPractices::Checks::Check

### Methods

- ::new
- #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::MoveModelLogicIntoModelCheck

Check a controller file to make sure that model logic should not exist in controller, move it into a model.

Implementation: check the count of method calling of a model, if it is more than defined called count, then it contains model logic.

### Public Class Methods

new(options = {}) click to toggle source

    # File lib/rails_best_practices/checks/move_model_logic_into_model_check.rb, line 19
    def initialize(options = {})
      super()
      @called_count = options['called_count'] || 4
    end

### Public Instance Methods

evaluate_start(node) click to toggle source

    # File lib/rails_best_practices/checks/move_model_logic_into_model_check.rb, line 24
    def evaluate_start(node)
      @variables = {}
      node.recursive_children do |child|
        case child.node_type
        when :attrasgn, :call
          call_node(child)
        end
      end

      @variables.each do |variable, count|
        add_error "move model logic into model (#{variable.to_ruby} called_count > #{@called_count})" if count > @called_count
      end
      @variables = nil
    end

interesting_files() click to toggle source

    # File lib/rails_best_practices/checks/move_model_logic_into_model_check.rb, line 15
    def interesting_files
      CONTROLLER_FILES
    end

interesting_nodes() click to toggle source

    # File lib/rails_best_practices/checks/move_model_logic_into_model_check.rb, line 11
    def interesting_nodes
      [:defn]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.