Module: RailsBestPractices

### Home Classes Methods

### In Files

- lib/rails_best_practices/checks/add_model_virtual_attribute_check.rb
- lib/rails_best_practices/checks/always_add_db_index_check.rb
- lib/rails_best_practices/checks/check.rb
- lib/rails_best_practices/checks/isolate_seed_data_check.rb
- lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
- lib/rails_best_practices/checks/law_of_demeter_check.rb
- lib/rails_best_practices/checks/many_to_many_collection_check.rb
- lib/rails_best_practices/checks/move_code_into_controller_check.rb
- lib/rails_best_practices/checks/move_code_into_helper_check.rb
- lib/rails_best_practices/checks/move_code_into_model_check.rb
- lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
- lib/rails_best_practices/checks/move_model_logic_into_model_check.rb
- lib/rails_best_practices/checks/needless_deep_nesting_check.rb
- lib/rails_best_practices/checks/nested_model_forms_check.rb
- lib/rails_best_practices/checks/not_use_default_route_check.rb
- lib/rails_best_practices/checks/overuse_route_customizations_check.rb
- lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb
- lib/rails_best_practices/checks/replace_instance_variable_with_local_variable_check.rb
- lib/rails_best_practices/checks/use_before_filter_check.rb
- lib/rails_best_practices/checks/use_model_association_check.rb
- lib/rails_best_practices/checks/use_model_callback_check.rb
- lib/rails_best_practices/checks/use_observer_check.rb
- lib/rails_best_practices/checks/use_scope_access_check.rb
- lib/rails_best_practices/core/checking_visitor.rb
- lib/rails_best_practices/core/error.rb
- lib/rails_best_practices/core/runner.rb
- lib/rails_best_practices.rb

### Namespace

- MODULE RailsBestPractices::Checks
- MODULE RailsBestPractices::Core

### Methods

- ::add_duplicate_migrations
- ::analyze_files
- ::expand_dirs_to_files
- ::ignore_files
- ::model_first_sort

### 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

### Public Class Methods

add_duplicate_migrations(files) click to toggle source

for always_add_db_index_check

    # File lib/rails_best_practices.rb, line 43
    def add_duplicate_migrations files
      migration_files = files.select { |file| file.index("db/migrate") }
      (files << migration_files).flatten
    end

analyze_files(dir = '.', options = {}) click to toggle source

    # File lib/rails_best_practices.rb, line 7
    def analyze_files(dir = '.', options = {})
      files = expand_dirs_to_files(dir)
      files = model_first_sort(files)
      files = add_duplicate_migrations(files)
      ['vendor', 'spec', 'test', 'stories'].each do |pattern|
        files = ignore_files(files, "#{pattern}/") unless options[pattern]
      end
      files
    end

expand_dirs_to_files(*dirs) click to toggle source

    # File lib/rails_best_practices.rb, line 17
    def expand_dirs_to_files *dirs
      extensions = ['rb', 'erb', 'haml', 'builder']

      dirs.flatten.map { |p|
        if File.directory? p
          Dir[File.join(p, '**', "*.{#{extensions.join(',')}}")]
        else
          p
        end
      }.flatten
    end

ignore_files(files, pattern) click to toggle source

    # File lib/rails_best_practices.rb, line 48
    def ignore_files files, pattern
      files.reject { |file| file.index(pattern) }
    end

model_first_sort(files) click to toggle source

for law_of_demeter_check

    # File lib/rails_best_practices.rb, line 30
    def model_first_sort files
      files.sort { |a, b|
        if a =~ /models\/.*rb/
          -1
        elsif b =~ /models\/.*rb/
          1
        else
          a <=> b
        end
      }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.