class RailsBestPractices::Reviews::MoveCodeIntoHelperReview

Review a view file to make sure there is no complex options_for_select message call.

See the best practice details here rails-bestpractices.com/posts/2010/07/24/move-code-into-helper/

TODO: we need a better soluation, any suggestion?

Implementation:

Review process:

check al method method_add_arg nodes to see if there is a complex options_for_select helper.

if the message of the method_add_arg node is options_for_select,
and the first argument of the method_add_arg node is array,
and the size of the array is greater than array_count defined,
then the options_for_select method should be moved into helper.

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/rails_best_practices/reviews/move_code_into_helper_review.rb, line 25
def initialize(options = {})
  super(options)
  @array_count = options['array_count'] || 3
end

Private Instance Methods

complex_select_options?(node) click to toggle source

check if the arguments of options_for_select are complex.

if the first argument is an array, and the size of array is greater than @array_count you defined, then it is complext.

# File lib/rails_best_practices/reviews/move_code_into_helper_review.rb, line 46
def complex_select_options?(node)
  node[1].message.to_s == 'options_for_select' && node.arguments.all.first.sexp_type == :array &&
    node.arguments.all.first.array_size > @array_count
end