Class: Apolo::Notifiers::Sqlite

Inherits:
Object
  • Object
show all
Defined in:
lib/apolo/notifiers/sqlite.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Sqlite

Returns a new instance of Sqlite.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/apolo/notifiers/sqlite.rb', line 8

def initialize(options = {})
  @db_name = options[:db_name]
  @db_table = options[:db_table]

  unless @db_name && @db_table
    raise ArgumentError, 'You need to set :db_name and :db_table to use sqlite notify.'
  end

  @db = Sequel.sqlite database: @db_name

  @db.create_table?(@db_table.to_sym) do
    primary_key :id
    DateTime :created_at
    String :monitor
    String :message
    Float :value
  end
end

Instance Method Details

#notify(monitor, message, value) ⇒ Object



27
28
29
30
# File 'lib/apolo/notifiers/sqlite.rb', line 27

def notify(monitor, message, value)
  @db[@db_table.to_sym].insert(created_at: DateTime.now, monitor: monitor,\
                        message: message, value: value)
end