vendor/bundle/ruby/2.3.0/gems/sqreen-1.10.5/lib/sqreen/call_countable.rb
# Hook the necessary callback function
# The module being decorated is expected to have a
# record_observation & rulespack_id & rule_name method available (like RuleCallback)
#
# @param count [Hash] hash of callback names => count
Hook the necessary callback function
The module being decorated is expected to have a
record_observation & rulespack_id & rule_name method available (like RuleCallback)
Hook the necessary callback function The module being decorated is expected to have a record_observation & rulespack_id & rule_name method available ( like RuleCallback )
def count_callback_calls(count)
      base = self.class
      @call_count_interval = 0
      return if count.to_i == 0
      @call_counts = {}
      @call_count_interval = count
      @call_count_names = {}
      %w(pre post failing).each do |cb|
        next unless base.method_defined?(cb)
        @call_counts[cb] = 0
        @call_count_names[cb] = "#{rulespack_id}/#{rule_name}/#{cb}".freeze
        defd = base.instance_variable_defined?("@call_count_hooked_#{cb}")
        next if defd && base.instance_variable_get("@call_count_hooked_#{cb}")
        base.send(:alias_method, "#{cb}_without_count", cb)
        base.send(:alias_method, cb, "#{cb}_with_count")
        base.instance_variable_set("@call_count_hooked_#{cb}", true)
      end
    end
def count_callback_calls ( count ) base = self . class @call_count_interval = 0 return if count . to_i == 0 @call_counts = { } @call_count_interval = count @call_count_names = { } %w( pre post failing ) . each do | cb | next unless base . method_defined? ( cb ) @call_counts [ cb ] = 0 @call_count_names [ cb ] = "#{rulespack_id}/#{rule_name}/#{cb}" . freeze defd = base . instance_variable_defined? ( "@call_count_hooked_#{cb}" ) next if defd && base . instance_variable_get ( "@call_count_hooked_#{cb}" ) base . send ( :alias_method , "#{cb}_without_count" , cb ) base . send ( :alias_method , cb , "#{cb}_with_count" ) base . instance_variable_set ( "@call_count_hooked_#{cb}" , true ) end end
Hook the necessary callback function
The module being decorated is expected to have a
record_observation & rulespack_id & rule_name method available (like RuleCallback)
Hook the necessary callback function The module being decorated is expected to have a record_observation & rulespack_id & rule_name method available ( like RuleCallback )
count
hash of callback names => count
hash of callback names = > count