Class: GuardrailsRuby::Check
- Inherits:
-
Object
- Object
- GuardrailsRuby::Check
- Defined in:
- lib/guardrails_ruby/check.rb
Direct Known Subclasses
GuardrailsRuby::Checks::CodeExecution, GuardrailsRuby::Checks::CompetitorMention, GuardrailsRuby::Checks::Disclaimer, GuardrailsRuby::Checks::Encoding, GuardrailsRuby::Checks::Format, GuardrailsRuby::Checks::HallucinatedEmails, GuardrailsRuby::Checks::HallucinatedURLs, GuardrailsRuby::Checks::KeywordFilter, GuardrailsRuby::Checks::MaxLength, GuardrailsRuby::Checks::PII, GuardrailsRuby::Checks::PromptInjection, GuardrailsRuby::Checks::Relevance, GuardrailsRuby::Checks::ScriptDetection, GuardrailsRuby::Checks::Topic, GuardrailsRuby::Checks::ToxicLanguage
Class Attribute Summary collapse
-
.registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.check_name(name = nil) ⇒ Object
DSL: set or get the check name.
-
.direction(dir = nil) ⇒ Object
DSL: set or get the direction.
-
.lookup(name) ⇒ Object
Look up a check class by its registered name.
Instance Method Summary collapse
-
#call(text, context: {}) ⇒ Object
Override in subclasses.
-
#initialize(**options) ⇒ Check
constructor
A new instance of Check.
Constructor Details
#initialize(**options) ⇒ Check
Returns a new instance of Check.
35 36 37 |
# File 'lib/guardrails_ruby/check.rb', line 35 def initialize(**) @options = end |
Class Attribute Details
.registry ⇒ Object (readonly)
Returns the value of attribute registry.
8 9 10 |
# File 'lib/guardrails_ruby/check.rb', line 8 def registry @registry end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
33 34 35 |
# File 'lib/guardrails_ruby/check.rb', line 33 def @options end |
Class Method Details
.check_name(name = nil) ⇒ Object
DSL: set or get the check name
11 12 13 14 15 16 17 |
# File 'lib/guardrails_ruby/check.rb', line 11 def check_name(name = nil) if name @check_name = name.to_sym Check.registry[name.to_sym] = self end @check_name end |
.direction(dir = nil) ⇒ Object
DSL: set or get the direction
20 21 22 23 24 25 |
# File 'lib/guardrails_ruby/check.rb', line 20 def direction(dir = nil) if dir @direction = dir.to_sym end @direction || :both end |
.lookup(name) ⇒ Object
Look up a check class by its registered name
28 29 30 |
# File 'lib/guardrails_ruby/check.rb', line 28 def lookup(name) registry[name.to_sym] end |
Instance Method Details
#call(text, context: {}) ⇒ Object
Override in subclasses
40 41 42 |
# File 'lib/guardrails_ruby/check.rb', line 40 def call(text, context: {}) raise NotImplementedError, "#{self.class}#call must be implemented" end |