Module: Coolhand
- Defined in:
- lib/coolhand.rb,
lib/coolhand/version.rb,
lib/coolhand/collector.rb,
lib/coolhand/api_service.rb,
lib/coolhand/configuration.rb,
lib/coolhand/logger_service.rb,
lib/coolhand/base_interceptor.rb,
lib/coolhand/feedback_service.rb,
lib/coolhand/webhook_interceptor.rb,
lib/coolhand/net_http_interceptor.rb,
lib/coolhand/open_ai/webhook_validator.rb,
lib/coolhand/vertex/batch_result_processor.rb,
lib/coolhand/open_ai/batch_result_processor.rb
Overview
The main module for the Coolhand gem. It provides the configuration interface and initializes the patching.
Defined Under Namespace
Modules: BaseInterceptor, Collector, NetHttpInterceptor, OpenAi, Vertex, WebhookInterceptor Classes: ApiService, Configuration, Error, FeedbackService, LoggerService
Constant Summary collapse
- VERSION =
"0.3.0"
Class Attribute Summary collapse
-
.configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Class Method Summary collapse
- .capture ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
Provides a block to configure the gem.
-
.feedback_service ⇒ Object
Creates a new FeedbackService instance.
-
.log(message) ⇒ Object
A simple logger that respects the ‘silent’ configuration option.
-
.logger_service ⇒ Object
Creates a new LoggerService instance.
- .required_field?(value) ⇒ Boolean
-
.reset_configuration! ⇒ Object
Reset configuration to defaults (mainly for testing).
- .with_capture ⇒ Object
- .without_capture ⇒ Object
Class Attribute Details
.configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
28 29 30 |
# File 'lib/coolhand.rb', line 28 def configuration @configuration end |
Class Method Details
.capture ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/coolhand.rb', line 55 def capture unless block_given? log "❌ Coolhand Error: Method .capture requires block." return end patched = NetHttpInterceptor.patched? NetHttpInterceptor.patch! yield ensure NetHttpInterceptor.unpatch! unless patched end |
.configure {|configuration| ... } ⇒ Object
Provides a block to configure the gem.
Example:
Coolhand.configure do |config|
config.environment = 'development'
config.silent = false
config.api_key = "xxx-yyy-zzz"
config.intercept_addresses = ["openai.com", "api.anthropic.com"]
end
45 46 47 48 49 50 51 52 53 |
# File 'lib/coolhand.rb', line 45 def configure yield(configuration) configuration.validate! NetHttpInterceptor.patch! log "✅ Coolhand ready - will log inference calls on monitored URIs" end |
.feedback_service ⇒ Object
Creates a new FeedbackService instance
94 95 96 |
# File 'lib/coolhand.rb', line 94 def feedback_service FeedbackService.new end |
.log(message) ⇒ Object
A simple logger that respects the ‘silent’ configuration option.
87 88 89 90 91 |
# File 'lib/coolhand.rb', line 87 def log() return if configuration.silent puts "COOLHAND: #{}" end |
.logger_service ⇒ Object
Creates a new LoggerService instance
99 100 101 |
# File 'lib/coolhand.rb', line 99 def logger_service LoggerService.new end |
.required_field?(value) ⇒ Boolean
103 104 105 106 107 108 109 |
# File 'lib/coolhand.rb', line 103 def required_field?(value) return false if value.nil? return false if value.respond_to?(:empty?) && value.empty? return false if value.to_s.strip.empty? true end |
.reset_configuration! ⇒ Object
Reset configuration to defaults (mainly for testing)
31 32 33 34 |
# File 'lib/coolhand.rb', line 31 def reset_configuration! @configuration = Configuration.new Thread.current[:coolhand_capture_override] = nil end |
.with_capture ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/coolhand.rb', line 78 def with_capture previous = Thread.current[:coolhand_capture_override] Thread.current[:coolhand_capture_override] = true yield ensure Thread.current[:coolhand_capture_override] = previous end |
.without_capture ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/coolhand.rb', line 70 def without_capture previous = Thread.current[:coolhand_capture_override] Thread.current[:coolhand_capture_override] = false yield ensure Thread.current[:coolhand_capture_override] = previous end |