Class: Sqreen::Rules::BindingAccessorCounter
- Inherits:
-
RuleCB
- Object
- CB
- FrameworkCB
- RuleCB
- Sqreen::Rules::BindingAccessorCounter
- Defined in:
- lib/sqreen/rules/count_http_codes.rb
Overview
Count 1 for each things located by the binding accessor
Constant Summary
Constants inherited from RuleCB
Constants included from CallCountable
CallCountable::COUNT_CALLS, CallCountable::FAILING, CallCountable::POST, CallCountable::PRE
Constants inherited from CB
Instance Attribute Summary
Attributes inherited from RuleCB
Attributes included from CallCountable
#call_count_interval, #call_counts
Attributes inherited from FrameworkCB
Attributes inherited from CB
#klass, #method, #overtimeable
Instance Method Summary collapse
-
#initialize(klass, method, rule_hash) ⇒ BindingAccessorCounter
constructor
A new instance of BindingAccessorCounter.
- #post(rv, inst, args, _budget = nil, &_block) ⇒ Object
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
#failing?, #framework, #overtime!, #post?, #pre?, #priority, #to_s, #whitelisted?
Constructor Details
#initialize(klass, method, rule_hash) ⇒ BindingAccessorCounter
Returns a new instance of BindingAccessorCounter.
29 30 31 32 33 34 35 |
# File 'lib/sqreen/rules/count_http_codes.rb', line 29 def initialize(klass, method, rule_hash) super(klass, method, rule_hash) @accessors = @data['values'].map do |expr| BindingAccessor.new(expr, true) end @metric_category = rule_hash[Attrs::METRICS].first['name'] end |
Instance Method Details
#post(rv, inst, args, _budget = nil, &_block) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/sqreen/rules/count_http_codes.rb', line 37 def post(rv, inst, args, _budget = nil, &_block) return unless rv.is_a?(Array) && !rv.empty? key = @accessors.map do |accessor| accessor.resolve(binding, framework, inst, args, @data, rv) end record_observation(@metric_category, SafeJSON.dump(key), 1) advise_action(nil) end |