Class: Ahoy::Stores::NatsStore
Instance Method Summary
collapse
Methods inherited from LogStore
#track_event, #track_visit
Methods inherited from BaseStore
#authenticate, #exclude?, #generate_id, #initialize, #report_exception, #track_event, #track_visit, #user, #visit
Instance Method Details
#client ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/ahoy/stores/nats_store.rb', line 16
def client
@client ||= begin
require "nats/io/client"
client = NATS::IO::Client.new
client.connect(servers: (ENV["NATS_URL"] || "nats://127.0.0.1:4222").split(","))
client
end
end
|
#events_subject ⇒ Object
29
30
31
|
# File 'lib/ahoy/stores/nats_store.rb', line 29
def events_subject
"ahoy_events"
end
|
#log_event(data) ⇒ Object
8
9
10
|
# File 'lib/ahoy/stores/nats_store.rb', line 8
def log_event(data)
publish(events_subject, data)
end
|
#log_visit(data) ⇒ Object
4
5
6
|
# File 'lib/ahoy/stores/nats_store.rb', line 4
def log_visit(data)
publish(visits_subject, data)
end
|
#publish(subject, data) ⇒ Object
12
13
14
|
# File 'lib/ahoy/stores/nats_store.rb', line 12
def publish(subject, data)
client.publish(subject, data.to_json)
end
|
#visits_subject ⇒ Object
25
26
27
|
# File 'lib/ahoy/stores/nats_store.rb', line 25
def visits_subject
"ahoy_visits"
end
|