Class: GuardrailsRuby::Violation
- Inherits:
-
Object
- Object
- GuardrailsRuby::Violation
- Defined in:
- lib/guardrails_ruby/violation.rb
Constant Summary collapse
- ACTIONS =
i[block warn redact log].freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#sanitized ⇒ Object
readonly
Returns the value of attribute sanitized.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type:, detail:, action: :block, severity: nil, matches: nil, sanitized: nil) ⇒ Violation
constructor
A new instance of Violation.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type:, detail:, action: :block, severity: nil, matches: nil, sanitized: nil) ⇒ Violation
Returns a new instance of Violation.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/guardrails_ruby/violation.rb', line 9 def initialize(type:, detail:, action: :block, severity: nil, matches: nil, sanitized: nil) unless ACTIONS.include?(action) raise ArgumentError, "Invalid action #{action.inspect}. Must be one of: #{ACTIONS.join(', ')}" end @type = type @detail = detail @action = action @severity = severity || default_severity(action) @matches = matches @sanitized = sanitized end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
7 8 9 |
# File 'lib/guardrails_ruby/violation.rb', line 7 def action @action end |
#detail ⇒ Object (readonly)
Returns the value of attribute detail.
7 8 9 |
# File 'lib/guardrails_ruby/violation.rb', line 7 def detail @detail end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
7 8 9 |
# File 'lib/guardrails_ruby/violation.rb', line 7 def matches @matches end |
#sanitized ⇒ Object (readonly)
Returns the value of attribute sanitized.
7 8 9 |
# File 'lib/guardrails_ruby/violation.rb', line 7 def sanitized @sanitized end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
7 8 9 |
# File 'lib/guardrails_ruby/violation.rb', line 7 def severity @severity end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/guardrails_ruby/violation.rb', line 7 def type @type end |
Instance Method Details
#inspect ⇒ Object
26 27 28 |
# File 'lib/guardrails_ruby/violation.rb', line 26 def inspect "#<#{self.class} type=#{type.inspect}, detail=#{detail.inspect}, action=#{action.inspect}>" end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/guardrails_ruby/violation.rb', line 22 def to_s "#{type}: #{detail} (action=#{action})" end |