Class: Sqreen::Rules::ExecJSCB
- Inherits:
-
RuleCB
- Object
- CB
- FrameworkCB
- RuleCB
- Sqreen::Rules::ExecJSCB
- Defined in:
- lib/sqreen/rules/execjs_cb.rb
Overview
Exec js callbacks
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
Class Method Summary collapse
Instance Method Summary collapse
- #failing(rv, inst, args, budget = nil, &_block) ⇒ Object
- #failing? ⇒ Boolean
-
#initialize(klass, method, rule_hash) ⇒ ExecJSCB
constructor
A new instance of ExecJSCB.
- #post(rv, inst, args, budget = nil, &_block) ⇒ Object
- #post? ⇒ Boolean
- #pre(inst, args, budget = nil, &_block) ⇒ Object
- #pre? ⇒ Boolean
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) ⇒ ExecJSCB
Returns a new instance of ExecJSCB.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sqreen/rules/execjs_cb.rb', line 25 def initialize(klass, method, rule_hash) super(klass, method, rule_hash) callbacks = @rule[Attrs::CALLBACKS] @conditions = @rule.fetch(Attrs::CONDITIONS, {}) build_runnable(callbacks) unless pre? || post? || failing? raise Sqreen::Exception, 'no JS CB provided' end @executable = ExecJSCB.js_service.prepare(rule_name, @source) @argument_filter = ArgumentFilter.new(rule_hash) end |
Class Method Details
.build_accessors(reqs) ⇒ Object
131 132 133 134 135 |
# File 'lib/sqreen/rules/execjs_cb.rb', line 131 def build_accessors(reqs) reqs.map do |req| BindingAccessor.new(req, true) end end |
.js_service ⇒ Sqreen::Js::JsService
20 21 22 |
# File 'lib/sqreen/rules/execjs_cb.rb', line 20 def js_service Sqreen::Js::JsService.instance end |
Instance Method Details
#failing(rv, inst, args, budget = nil, &_block) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/sqreen/rules/execjs_cb.rb', line 66 def failing(rv, inst, args, budget = nil, &_block) Sqreen.log.debug { "#{self.class} failing args: #{args.inspect}" } return unless failing? call_callback('failing', budget, inst, @cb_bas['failing'], args, rv) end |
#failing? ⇒ Boolean
48 49 50 |
# File 'lib/sqreen/rules/execjs_cb.rb', line 48 def failing? @js_failing end |
#post(rv, inst, args, budget = nil, &_block) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/sqreen/rules/execjs_cb.rb', line 59 def post(rv, inst, args, budget = nil, &_block) Sqreen.log.debug { "#{self.class} post args: #{args.inspect}" } return unless post? call_callback('post', budget, inst, @cb_bas['post'], args, rv) end |
#post? ⇒ Boolean
44 45 46 |
# File 'lib/sqreen/rules/execjs_cb.rb', line 44 def post? @js_post end |
#pre(inst, args, budget = nil, &_block) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/sqreen/rules/execjs_cb.rb', line 52 def pre(inst, args, budget = nil, &_block) Sqreen.log.debug { "#{self.class} pre args: #{args.inspect}" } return unless pre? call_callback('pre', budget, inst, @cb_bas['pre'], args) end |
#pre? ⇒ Boolean
40 41 42 |
# File 'lib/sqreen/rules/execjs_cb.rb', line 40 def pre? @js_pre end |