Class: SwarmSDK::LogCollector::Subscription
- Inherits:
-
Object
- Object
- SwarmSDK::LogCollector::Subscription
- Defined in:
- lib/swarm_sdk/log_collector.rb
Overview
Subscription object with filtering capabilities
Encapsulates a callback with optional filters. Filters can match against agent name, event type, swarm_id, or any event field.
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(filter: {}, &callback) ⇒ Subscription
constructor
Initialize a subscription.
-
#matches?(event) ⇒ Boolean
Check if event matches filter criteria.
Constructor Details
#initialize(filter: {}, &callback) ⇒ Subscription
Initialize a subscription
69 70 71 72 73 |
# File 'lib/swarm_sdk/log_collector.rb', line 69 def initialize(filter: {}, &callback) @id = SecureRandom.uuid @filter = normalize_filter(filter) @callback = callback end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
63 64 65 |
# File 'lib/swarm_sdk/log_collector.rb', line 63 def callback @callback end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
63 64 65 |
# File 'lib/swarm_sdk/log_collector.rb', line 63 def filter @filter end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
63 64 65 |
# File 'lib/swarm_sdk/log_collector.rb', line 63 def id @id end |
Instance Method Details
#matches?(event) ⇒ Boolean
Check if event matches filter criteria
Empty filter matches all events. Multiple filter keys are AND'd together.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/swarm_sdk/log_collector.rb', line 81 def matches?(event) return true if @filter.empty? @filter.all? do |key, matcher| value = event[key] case matcher when Array # Match if value is in array (handles symbols/strings) matcher.include?(value) || matcher.map(&:to_s).include?(value.to_s) when Regexp # Regex matching value.to_s.match?(matcher) when Proc # Custom matcher matcher.call(value) else # Exact match (handles symbols/strings) matcher == value || matcher.to_s == value.to_s end end end |