Module: RailsBestPractices::Core::Check::Exceptable

Defined in:
lib/rails_best_practices/core/check.rb

Overview

Helper to check except methods.

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/rails_best_practices/core/check.rb', line 409

def self.included(base)
  base.class_eval do
    def except_methods
      @except_methods + internal_except_methods
    end

    # check if the method is in the except methods list.
    def excepted?(method)
      except_methods.any? do |except_method|
        class_name, method_name = except_method.split('#')
        (class_name == '*' && method_name == method.method_name) ||
          (method_name == '*' && class_name == method.class_name) ||
          (method_name == '*' && class_name == Prepares.klasses.find { |klass| klass.class_name == method.class_name }.try(:extend_class_name)) ||
          (class_name == method.class_name && method_name == method.method_name)
      end
    end

    def internal_except_methods
      raise NoMethodError.new "no method internal_except_methods"
    end
  end
end