Class: Olyx::Guardrails::PolicyRule
- Inherits:
-
Object
- Object
- Olyx::Guardrails::PolicyRule
- Defined in:
- lib/olyx/guardrails/policy_rule.rb
Overview
Defines one immutable, named restricted-content rule.
Rules may contain escaped terms, regular expressions, or both. Matching records safe fingerprints and offsets; it does not expose the matched restricted text in public findings.
Instance Method Summary collapse
-
#block? ⇒ Boolean
Returns whether a match blocks a decision.
-
#description ⇒ Object
Returns the optional description, or
nil. -
#initialize(name:, patterns: [], terms: [], match: :substring, block: true, description: nil, replacement: nil) ⇒ PolicyRule
constructor
:call-seq: PolicyRule.new(name:, patterns: [], terms: [], match: :substring, block: true, description: nil, replacement: nil).
-
#match ⇒ Object
Returns
:substring,:whole_word, or:regexp. -
#name ⇒ Object
Returns the normalized String rule identifier.
-
#patterns ⇒ Object
Returns the frozen compiled Regexp collection.
-
#replacement ⇒ Object
Returns the safe replacement used by redaction.
Constructor Details
#initialize(name:, patterns: [], terms: [], match: :substring, block: true, description: nil, replacement: nil) ⇒ PolicyRule
:call-seq:
PolicyRule.new(name:, patterns: [], terms: [], match: :substring,
block: true, description: nil, replacement: nil)
Builds and freezes a rule.
name is the stable rule identifier. terms contains non-empty
Strings. patterns contains Regexp objects or regular-expression source
Strings. match controls how terms compile and accepts :substring,
:whole_word, or :regexp.
block controls the decision but not redaction. description is
optional safe metadata. replacement is the text used during
redaction; when omitted it is derived from name.
Invalid values and expressions that match empty text raise ArgumentError.
30 31 32 33 34 35 |
# File 'lib/olyx/guardrails/policy_rule.rb', line 30 def initialize(name:, patterns: [], terms: [], match: :substring, block: true, description: nil, replacement: nil) @identity = PolicyRuleComponents::IdentityConfiguration.new(name, description) @matching = PolicyRuleComponents::MatchConfiguration.new(patterns, terms, match) @enforcement = PolicyRuleComponents::EnforcementConfiguration.new(block, replacement || default_replacement) freeze end |
Instance Method Details
#block? ⇒ Boolean
Returns whether a match blocks a decision.
53 |
# File 'lib/olyx/guardrails/policy_rule.rb', line 53 def block? = @enforcement.block? |
#description ⇒ Object
Returns the optional description, or nil.
41 |
# File 'lib/olyx/guardrails/policy_rule.rb', line 41 def description = @identity.description |
#match ⇒ Object
Returns :substring, :whole_word, or :regexp.
44 |
# File 'lib/olyx/guardrails/policy_rule.rb', line 44 def match = @matching.mode |
#name ⇒ Object
Returns the normalized String rule identifier.
38 |
# File 'lib/olyx/guardrails/policy_rule.rb', line 38 def name = @identity.name |
#patterns ⇒ Object
Returns the frozen compiled Regexp collection.
47 |
# File 'lib/olyx/guardrails/policy_rule.rb', line 47 def patterns = @matching.patterns |
#replacement ⇒ Object
Returns the safe replacement used by redaction.
50 |
# File 'lib/olyx/guardrails/policy_rule.rb', line 50 def replacement = @enforcement.replacement |