Sha256: 45acfdbb8c34834c710a6229768a41302b6d39b22575a78160916f89fda80b17

Contents?: true

Size: 797 Bytes

Versions: 14

Compression:

Stored size: 797 Bytes

Contents

require 'rails_best_practices/checks/check'

module RailsBestPractices
  module Checks
    # Check a view file to make sure there is no complex options_for_select message call.
    #
    # Implementation: Check if arguments of options_for_select message call contain more than 2 method call, then move it into helper.
    class MoveCodeIntoHelperCheck < Check
    
      def interesting_nodes
        [:call]
      end
    
      def interesting_files
        VIEW_FILES
      end

      def evaluate_start(node)
        add_error "move code into helper" if complex_select_options?(node)
      end
      
      private
      
      def complex_select_options?(node)
        :options_for_select == node.message and node.arguments.grep_nodes(:node_type => :call).size > 2
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rails_best_practices-0.3.11 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.10 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.9 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.8 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.7 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.6 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.5 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.4 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.3 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.2 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.1 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.0 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.2.16 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.2.15 lib/rails_best_practices/checks/move_code_into_helper_check.rb