Class: Ahoy::Stores::NatsStore

Inherits:
LogStore show all
Defined in:
lib/ahoy/stores/nats_store.rb

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

Constructor Details

This class inherits a constructor from Ahoy::Stores::BaseStore

Instance Method Details

#clientObject



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_subjectObject



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_subjectObject



25
26
27
# File 'lib/ahoy/stores/nats_store.rb', line 25

def visits_subject
  "ahoy_visits"
end