Module: Bugsage::AiContext
- Defined in:
- lib/bugsage/ai_context.rb
Class Method Summary collapse
- .available? ⇒ Boolean
- .clear! ⇒ Object
- .current ⇒ Object
- .load_from_event(event) ⇒ Object
- .safe_constantize(name) ⇒ Object
- .set(exception:, suggestion:, context:) ⇒ Object
- .suggestion_from_event(event) ⇒ Object
Class Method Details
.available? ⇒ Boolean
34 35 36 |
# File 'lib/bugsage/ai_context.rb', line 34 def available? !@exception.nil? && !@suggestion.nil? end |
.clear! ⇒ Object
28 29 30 31 32 |
# File 'lib/bugsage/ai_context.rb', line 28 def clear! @exception = nil @suggestion = nil @context = {} end |
.current ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/bugsage/ai_context.rb', line 38 def current return nil unless available? { exception: @exception, suggestion: @suggestion, context: @context } end |
.load_from_event(event) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bugsage/ai_context.rb', line 13 def load_from_event(event) return false unless event klass = safe_constantize(event[:exception_class]) = event[:exception_message].to_s = event[:root_cause].to_s if .empty? set( exception: klass.new(), suggestion: suggestion_from_event(event), context: event[:context] || {} ) true end |
.safe_constantize(name) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/bugsage/ai_context.rb', line 61 def safe_constantize(name) return StandardError if name.to_s.strip.empty? Object.const_get(name) rescue NameError StandardError end |
.set(exception:, suggestion:, context:) ⇒ Object
7 8 9 10 11 |
# File 'lib/bugsage/ai_context.rb', line 7 def set(exception:, suggestion:, context:) @exception = exception @suggestion = suggestion @context = context || {} end |
.suggestion_from_event(event) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bugsage/ai_context.rb', line 48 def suggestion_from_event(event) Suggestion.new( issue: event[:issue], location: event[:location], root_cause: event[:root_cause], fixes: event[:fixes] || [], confidence: event[:confidence], source: event[:source] || :rules, ai_notes: event[:ai_notes], code_patch: event[:code_patch] ) end |