Sha256: 0519fa005550f74f196cc8b163990552033b00693bf3dc6c37ffcdf58a5e281d

Contents?: true

Size: 1001 Bytes

Versions: 10

Compression:

Stored size: 1001 Bytes

Contents

# encoding: utf-8
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 first argument of options_for_select is an array and contains more than two nodes, then it should be moved into helper.
    class MoveCodeIntoHelperCheck < Check
    
      def interesting_nodes
        [:call]
      end
    
      def interesting_files
        VIEW_FILES
      end

      def initialize(options = {})
        super()
        @array_count = options['array_count'] || 3
      end

      def evaluate_start(node)
        add_error "move code into helper (array_count >= #{@array_count})" if complex_select_options?(node)
      end
      
      private
      
      def complex_select_options?(node)
        :options_for_select == node.message and :array == node.arguments[1].node_type and node.arguments[1].size > @array_count
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rails_best_practices-0.5.6 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.5.5 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.5.3 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.5.2 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.5.1 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.5.0 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.4.6 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.4.5 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.4.4 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.4.3 lib/rails_best_practices/checks/move_code_into_helper_check.rb