Parent

Files

RailsBestPractices::Checks::ReplaceComplexCreationWithFactoryMethodCheck

Check a controller file to make sure that complex model creation should not exist in controller, move it to model factory method

Implementation: check the count of variable attribute assignment calling before saving, if more than defined attribute assignment count, then it’s a complex creation.

Public Class Methods

new(options = {}) click to toggle source
# File lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb, line 19
def initialize(options = {})
  super()
  @attrasgn_count = options['attribute_assignment_count'] || 2
end

Public Instance Methods

evaluate_start(node) click to toggle source
# File lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb, line 24
def evaluate_start(node)
  @variables = {}
  node.recursive_children do |child|
    case child.node_type
    when :attrasgn
      attribute_assignment(child)
    when :call
      call_assignment(child)
    else
    end
  end
  @variables = nil
end
interesting_files() click to toggle source
# File lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb, line 15
def interesting_files
  CONTROLLER_FILES
end
interesting_nodes() click to toggle source
# File lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb, line 11
def interesting_nodes
  [:defn]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.