module Cordon::Watchlist

Public Class Methods

incursion_report() click to toggle source
# File lib/cordon/watchlist.rb, line 17
      def incursion_report
        report = <<-EOF.strip
=======================
Cordon Incursion Report
=======================
        EOF
        n = incursions.length
        max_width = n.to_s.length

        incursions_by_method = Hash.new { |hash, key| hash[key] = [] }
        incursions.each do |incursion|
          incursions_by_method[incursion.method_descriptor] << incursion
        end

        incursions_by_method.to_a.sort.each do |method_descriptor, incursions|
          report << "\n\n#{method_descriptor}\n#{'-' * method_descriptor.length}"
          incursions.each do |incursion|
            report << "\n" + incursion.backtrace.first.to_s
          end
        end
        report << "\n"
        report
      end
incursions() click to toggle source
# File lib/cordon/watchlist.rb, line 13
def incursions
  @incursions ||= []
end
invoke_method(instance, subject, method, *args, &b) click to toggle source
Calls superclass method
# File lib/cordon/watchlist.rb, line 8
def invoke_method(instance, subject, method, *args, &b)
  record_incursion(subject, method, args)
  super
end

Protected Class Methods

record_incursion(subject, method, args) click to toggle source
# File lib/cordon/watchlist.rb, line 43
def record_incursion(subject, method, args)
  raise Cordon::Violation.from_invocation(subject, method, args)
rescue Cordon::Violation => e
  incursions << e
end