Class: RaceGuard::Rule
- Inherits:
-
Object
- Object
- RaceGuard::Rule
- Defined in:
- lib/race_guard/rule.rb
Overview
Immutable rule definition built by define_rule.
Defined Under Namespace
Classes: Builder
Constant Summary collapse
- KNOWN_EVENTS =
%i[protect_enter protect_exit].freeze
- EMPTY_HOOKS =
[].freeze
Instance Attribute Summary collapse
-
#detect_proc ⇒ Object
readonly
Returns the value of attribute detect_proc.
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#message_proc ⇒ Object
readonly
Returns the value of attribute message_proc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#run_on ⇒ Object
readonly
Returns the value of attribute run_on.
-
#severity_override ⇒ Object
readonly
Returns the value of attribute severity_override.
Instance Method Summary collapse
-
#hooks_for(event) ⇒ Object
rubocop:enable Metrics/ParameterLists.
-
#initialize(name:, detect_proc:, message_proc:, hooks:, run_on:, severity_override:) ⇒ Rule
constructor
rubocop:disable Metrics/ParameterLists – explicit fields keep Rule immutable and clear.
- #run_on?(event) ⇒ Boolean
Constructor Details
#initialize(name:, detect_proc:, message_proc:, hooks:, run_on:, severity_override:) ⇒ Rule
rubocop:disable Metrics/ParameterLists – explicit fields keep Rule immutable and clear
14 15 16 17 18 19 20 21 22 |
# File 'lib/race_guard/rule.rb', line 14 def initialize(name:, detect_proc:, message_proc:, hooks:, run_on:, severity_override:) @name = name.to_sym @detect_proc = detect_proc @message_proc = @hooks = hooks.freeze @run_on = run_on.freeze @severity_override = severity_override freeze end |
Instance Attribute Details
#detect_proc ⇒ Object (readonly)
Returns the value of attribute detect_proc.
11 12 13 |
# File 'lib/race_guard/rule.rb', line 11 def detect_proc @detect_proc end |
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
11 12 13 |
# File 'lib/race_guard/rule.rb', line 11 def hooks @hooks end |
#message_proc ⇒ Object (readonly)
Returns the value of attribute message_proc.
11 12 13 |
# File 'lib/race_guard/rule.rb', line 11 def @message_proc end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/race_guard/rule.rb', line 11 def name @name end |
#run_on ⇒ Object (readonly)
Returns the value of attribute run_on.
11 12 13 |
# File 'lib/race_guard/rule.rb', line 11 def run_on @run_on end |
#severity_override ⇒ Object (readonly)
Returns the value of attribute severity_override.
11 12 13 |
# File 'lib/race_guard/rule.rb', line 11 def severity_override @severity_override end |
Instance Method Details
#hooks_for(event) ⇒ Object
rubocop:enable Metrics/ParameterLists
25 26 27 |
# File 'lib/race_guard/rule.rb', line 25 def hooks_for(event) hooks[event.to_sym] || EMPTY_HOOKS end |
#run_on?(event) ⇒ Boolean
29 30 31 |
# File 'lib/race_guard/rule.rb', line 29 def run_on?(event) run_on.include?(event.to_sym) end |