Class: Tracebook::Config
- Inherits:
-
Object
- Object
- Tracebook::Config
- Defined in:
- lib/tracebook/config.rb
Instance Attribute Summary collapse
-
#actor_display ⇒ Proc?
Lambda to format actor display name.
-
#chat_class ⇒ String
Class name of the host app's Chat model (default: "Chat").
-
#custom_redactors ⇒ Array<Proc>
readonly
Custom redaction callables.
-
#default_currency ⇒ String
Currency code for cost calculations (default: "USD").
-
#message_class ⇒ String
Class name of the host app's Message model (default: "Message").
-
#per_page ⇒ Integer
Items per page in dashboard (default: 25).
Instance Method Summary collapse
- #build_redaction_pipeline ⇒ Object private
-
#chat_model ⇒ Class
The resolved chat model class.
- #finalize! ⇒ Object
- #finalized? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#message_model ⇒ Class
The resolved message model class.
-
#redact(*names) ⇒ Object
Enable named redaction patterns.
-
#redact_group(group_name) ⇒ Object
Enable a named group of patterns.
-
#redact_pattern(regex, replacement, name: nil) ⇒ Object
Add a custom regex pattern for redaction.
-
#redaction_pipeline ⇒ Redaction::Pipeline
Build the redaction pipeline from configured patterns and custom redactors.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
23 24 25 26 27 28 29 30 31 |
# File 'lib/tracebook/config.rb', line 23 def initialize @chat_class = "Chat" @message_class = "Message" @default_currency = "USD" @per_page = 25 @actor_display = nil @redaction_patterns = [] @custom_redactors = [] end |
Instance Attribute Details
#actor_display ⇒ Proc?
Returns lambda to format actor display name.
18 19 20 |
# File 'lib/tracebook/config.rb', line 18 def actor_display @actor_display end |
#chat_class ⇒ String
Returns class name of the host app's Chat model (default: "Chat").
6 7 8 |
# File 'lib/tracebook/config.rb', line 6 def chat_class @chat_class end |
#custom_redactors ⇒ Array<Proc> (readonly)
Returns custom redaction callables.
21 22 23 |
# File 'lib/tracebook/config.rb', line 21 def custom_redactors @custom_redactors end |
#default_currency ⇒ String
Returns currency code for cost calculations (default: "USD").
12 13 14 |
# File 'lib/tracebook/config.rb', line 12 def default_currency @default_currency end |
#message_class ⇒ String
Returns class name of the host app's Message model (default: "Message").
9 10 11 |
# File 'lib/tracebook/config.rb', line 9 def @message_class end |
#per_page ⇒ Integer
Returns items per page in dashboard (default: 25).
15 16 17 |
# File 'lib/tracebook/config.rb', line 15 def per_page @per_page end |
Instance Method Details
#build_redaction_pipeline ⇒ Object (private)
107 108 109 110 111 112 |
# File 'lib/tracebook/config.rb', line 107 def build_redaction_pipeline patterns = @redaction_patterns.map do |p| p.is_a?(Symbol) ? Redaction::PATTERNS.fetch(p) : p end Redaction::Pipeline.new(patterns: patterns, custom_redactors: @custom_redactors) end |
#chat_model ⇒ Class
Returns the resolved chat model class.
96 97 98 |
# File 'lib/tracebook/config.rb', line 96 def chat_model @chat_class.constantize end |
#finalize! ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/tracebook/config.rb', line 85 def finalize! return if finalized? @redaction_patterns.freeze @custom_redactors.freeze @redaction_pipeline = redaction_pipeline @finalized = true freeze end |
#finalized? ⇒ Boolean
81 82 83 |
# File 'lib/tracebook/config.rb', line 81 def finalized? @finalized == true end |
#message_model ⇒ Class
Returns the resolved message model class.
101 102 103 |
# File 'lib/tracebook/config.rb', line 101 def @message_class.constantize end |
#redact(*names) ⇒ Object
Enable named redaction patterns.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tracebook/config.rb', line 37 def redact(*names) names.each do |name| if Redaction::GROUPS.key?(name) redact_group(name) elsif Redaction::PATTERNS.key?(name) @redaction_patterns << name unless @redaction_patterns.include?(name) else raise ArgumentError, "Unknown redaction pattern: #{name}. Available: #{(Redaction::PATTERNS.keys + Redaction::GROUPS.keys).join(", ")}" end end end |
#redact_group(group_name) ⇒ Object
Enable a named group of patterns.
53 54 55 56 57 58 |
# File 'lib/tracebook/config.rb', line 53 def redact_group(group_name) patterns = Redaction::GROUPS.fetch(group_name) do raise ArgumentError, "Unknown redaction group: #{group_name}. Available: #{Redaction::GROUPS.keys.join(", ")}" end patterns.each { |name| redact(name) } end |
#redact_pattern(regex, replacement, name: nil) ⇒ Object
Add a custom regex pattern for redaction.
64 65 66 67 68 69 70 71 |
# File 'lib/tracebook/config.rb', line 64 def redact_pattern(regex, replacement, name: nil) pattern = Redaction::Pattern.new( name: name || "custom_#{@redaction_patterns.size}", regex: regex, replacement: replacement ) @redaction_patterns << pattern end |
#redaction_pipeline ⇒ Redaction::Pipeline
Build the redaction pipeline from configured patterns and custom redactors. Memoized after first call (safe because config is frozen after finalize!).
77 78 79 |
# File 'lib/tracebook/config.rb', line 77 def redaction_pipeline @redaction_pipeline || build_redaction_pipeline end |