Class: Sqreen::Rules::BindingAccessorMetrics

Inherits:
RuleCB show all
Defined in:
lib/sqreen/rules/binding_accessor_metrics.rb

Overview

Publish metrics about data taken from the binding accessor

Defined Under Namespace

Classes: NoExpressions

Constant Summary collapse

PRE_CB =
'pre'.freeze
POST_CB =
'post'.freeze
FAILING_CB =
'failing'.freeze

Constants inherited from RuleCB

RuleCB::DEFAULT_PAYLOAD

Constants included from CallCountable

CallCountable::COUNT_CALLS, CallCountable::FAILING, CallCountable::POST, CallCountable::PRE

Constants inherited from CB

CB::DEFAULT_PRIORITY

Instance Attribute Summary

Attributes inherited from RuleCB

#block, #payload_tpl, #test

Attributes included from CallCountable

#call_count_interval, #call_counts

Attributes inherited from FrameworkCB

#framework

Attributes inherited from CB

#klass, #method, #overtimeable

Instance Method Summary collapse

Methods inherited from RuleCB

#advise_action, #overtime!, #priority, #record_event, #record_exception, #rule_name, #rulespack_id

Methods included from CallCountable

#count_callback_calls, #failing_with_count, #post_with_count, #pre_with_count

Methods included from Conditionable

#condition_callbacks, #failing_with_conditions, #post_with_conditions, #pre_with_conditions

Methods inherited from FrameworkCB

#record_observation, #whitelisted?

Methods inherited from CB

#framework, #overtime!, #priority, #to_s, #whitelisted?

Constructor Details

#initialize(klass, method, rule_hash) ⇒ BindingAccessorMetrics

Returns a new instance of BindingAccessorMetrics.



21
22
23
24
25
# File 'lib/sqreen/rules/binding_accessor_metrics.rb', line 21

def initialize(klass, method, rule_hash)
  super(klass, method, rule_hash)
  @expr = {}
  build_expressions(rule_hash[Attrs::CALLBACKS])
end

Instance Method Details

#failing(exception, inst, args, _budget = nil, &_block) ⇒ Object



55
56
57
58
59
# File 'lib/sqreen/rules/binding_accessor_metrics.rb', line 55

def failing(exception, inst, args, _budget = nil, &_block)
  return unless failing?

  add_metrics(FAILING_CB, inst, args, exception)
end

#failing?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/sqreen/rules/binding_accessor_metrics.rb', line 39

def failing?
  @expr[FAILING_CB]
end

#post(rv, inst, args, _budget = nil, &_block) ⇒ Object



49
50
51
52
53
# File 'lib/sqreen/rules/binding_accessor_metrics.rb', line 49

def post(rv, inst, args, _budget = nil, &_block)
  return unless post?

  add_metrics(POST_CB, inst, args, rv)
end

#post?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/sqreen/rules/binding_accessor_metrics.rb', line 35

def post?
  @expr[POST_CB]
end

#pre(inst, args, _budget = nil, &_block) ⇒ Object



43
44
45
46
47
# File 'lib/sqreen/rules/binding_accessor_metrics.rb', line 43

def pre(inst, args, _budget = nil, &_block)
  return unless pre?

  add_metrics(PRE_CB, inst, args)
end

#pre?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/sqreen/rules/binding_accessor_metrics.rb', line 31

def pre?
  @expr[PRE_CB]
end