Class: Corona::DB

Inherits:
Object
  • Object
show all
Defined in:
lib/corona/db/db.rb,
lib/corona/db/model.rb

Defined Under Namespace

Classes: Device

Instance Method Summary collapse

Constructor Details

#initializeDB

Returns a new instance of DB.



5
6
7
8
9
# File 'lib/corona/db/db.rb', line 5

def initialize
  Sequel::Model.plugin :schema
  @db = Sequel.sqlite(CFG.db, :max_connections => 1, :pool_timeout => 60)
  require_relative 'model'
end

Instance Method Details

#add(record) ⇒ Object



11
12
13
14
15
16
# File 'lib/corona/db/db.rb', line 11

def add record
  record[:first_seen] = record[:last_seen] = Time.now.utc
  record[:active] = true
  Log.debug "adding: #{record}"
  Device.new(record).save
end

#old(ip, oid_sysName) ⇒ Object



25
26
27
28
29
# File 'lib/corona/db/db.rb', line 25

def old ip, oid_sysName
  ip       = Device[:ip => ip]
  sysName  = Device[:oid_sysName => oid_sysName]
  [ip, sysName]
end

#update(record, where) ⇒ Object



18
19
20
21
22
23
# File 'lib/corona/db/db.rb', line 18

def update record, where
  record[:last_seen] = Time.now.utc
  record[:active] = true
  Log.debug "updating (where: #{where}): #{record}"
  Device[where.first.to_sym => where.last].update record
end