Module: BrainzLab::Development
- Defined in:
- lib/brainzlab/development.rb,
lib/brainzlab/development/store.rb,
lib/brainzlab/development/logger.rb
Overview
Development mode support for offline SDK usage Logs all events to stdout and stores them locally in SQLite
Defined Under Namespace
Class Method Summary collapse
-
.clear! ⇒ Object
Clear all stored events.
-
.enabled? ⇒ Boolean
Check if development mode is enabled.
-
.events(service: nil, event_type: nil, since: nil, limit: 100) ⇒ Array<Hash>
Query stored events.
-
.logger ⇒ Object
Get the development logger.
-
.record(service:, event_type:, payload:) ⇒ Object
Record an event from any service.
-
.reset! ⇒ Object
Reset the development module (for testing).
-
.stats ⇒ Object
Get event counts by service.
-
.store ⇒ Object
Get the store instance.
Class Method Details
.clear! ⇒ Object
Clear all stored events
53 54 55 |
# File 'lib/brainzlab/development.rb', line 53 def clear! store.clear! if enabled? end |
.enabled? ⇒ Boolean
Check if development mode is enabled
12 13 14 |
# File 'lib/brainzlab/development.rb', line 12 def enabled? BrainzLab.configuration.mode == :development end |
.events(service: nil, event_type: nil, since: nil, limit: 100) ⇒ Array<Hash>
Query stored events
46 47 48 49 50 |
# File 'lib/brainzlab/development.rb', line 46 def events(service: nil, event_type: nil, since: nil, limit: 100) return [] unless enabled? store.query(service: service, event_type: event_type, since: since, limit: limit) end |
.logger ⇒ Object
Get the development logger
22 23 24 |
# File 'lib/brainzlab/development.rb', line 22 def logger @logger ||= Logger.new(output: BrainzLab.configuration.development_log_output || $stdout) end |
.record(service:, event_type:, payload:) ⇒ Object
Record an event from any service
30 31 32 33 34 35 36 37 38 |
# File 'lib/brainzlab/development.rb', line 30 def record(service:, event_type:, payload:) return unless enabled? # Log to stdout logger.log(service: service, event_type: event_type, payload: payload) # Store in SQLite store.insert(service: service, event_type: event_type, payload: payload) end |
.reset! ⇒ Object
Reset the development module (for testing)
58 59 60 61 62 |
# File 'lib/brainzlab/development.rb', line 58 def reset! @store&.close @store = nil @logger = nil end |
.stats ⇒ Object
Get event counts by service
65 66 67 68 69 |
# File 'lib/brainzlab/development.rb', line 65 def stats return {} unless enabled? store.stats end |
.store ⇒ Object
Get the store instance
17 18 19 |
# File 'lib/brainzlab/development.rb', line 17 def store @store ||= Store.new(BrainzLab.configuration) end |