Sha256: 052a698d1ee57c382d540b77bd59898f337af1595ca3484f147b4a4641315cb2

Contents?: true

Size: 941 Bytes

Versions: 3

Compression:

Stored size: 941 Bytes

Contents

require 'simplabs/excellent/checks/base'

module Simplabs

  module Excellent

    module Checks

      module Rails

        # This check reports +ActiveRecord+ models that define a custom +initialize+ method. Since +ActiveRecord+ does not always call +new+ to
        # create instances, these custom +initialize+ methods might not always be called, which makes the behavior of the application very hard to
        # understand.
        #
        # ==== Applies to
        #
        # * +ActiveRecord+ models
        class CustomInitializeMethodCheck < Base

          def initialize #:nodoc:
            super
            @interesting_nodes = [:class]
          end

          def evaluate(context) #:nodoc:
            add_warning(context, '{{class}} defines initialize method.', { :class => context.full_name }) if context.active_record_model? && !context.defines_initializer?
          end

        end

      end

    end

  end

end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
simplabs-excellent-1.5.2 lib/simplabs/excellent/checks/rails/custom_initialize_method_check.rb
simplabs-excellent-1.5.3 lib/simplabs/excellent/checks/rails/custom_initialize_method_check.rb
excellent-1.5.4 lib/simplabs/excellent/checks/rails/custom_initialize_method_check.rb