Sha256: 025659919de64d9d5e4bf37eb9500c51736359d8b77e15e56474a480f2774eda

Contents?: true

Size: 983 Bytes

Versions: 19

Compression:

Stored size: 983 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 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

19 entries across 19 versions & 1 rubygems

Version Path
rails_best_practices-0.4.2 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.4.1 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.4.0 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.27 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.26 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.25 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.24 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.23 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.22 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.21 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.20 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.19 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.18 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.17 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.16 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.15 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.14 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.13 lib/rails_best_practices/checks/move_code_into_helper_check.rb
rails_best_practices-0.3.12 lib/rails_best_practices/checks/move_code_into_helper_check.rb