Class: RailsBestPractices::Checks::UseObserverCheck

### Home Classes Methods

### In Files

- lib/rails_best_practices/checks/use_observer_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::UseObserverCheck

Check a model file to make sure mail deliver method is in observer not callback.

Implementation: Record :after_create callback Check method define, if it is a callback and call deliver_xxx message in method body, then it should use observer.

### Public Class Methods

new() click to toggle source

    # File lib/rails_best_practices/checks/use_observer_check.rb, line 20
    def initialize
      super
      @callbacks = []
    end

### Public Instance Methods

evaluate_start(node) click to toggle source

    # File lib/rails_best_practices/checks/use_observer_check.rb, line 25
    def evaluate_start(node)
      if :after_create == node.message
        remember_callbacks(node)
      elsif :defn == node.node_type and @callbacks.include?(node.message_name.to_s)
        add_error "use observer" if use_observer?(node)
      end
    end

interesting_files() click to toggle source

    # File lib/rails_best_practices/checks/use_observer_check.rb, line 16
    def interesting_files
      MODLE_FILES
    end

interesting_nodes() click to toggle source

    # File lib/rails_best_practices/checks/use_observer_check.rb, line 12
    def interesting_nodes
      [:defn, :call]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.