Module: DailyRep::Dbops

Included in:
Entities::Doujob, IBrowser
Defined in:
lib/dailyrep/Dbops.rb

Instance Method Summary collapse

Instance Method Details

#check_history_notif(entity, parameter, timescope = (Time.now - 6.hour)) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/dailyrep/Dbops.rb', line 3

def check_history_notif entity, parameter, timescope=(Time.now - 6.hour)
  sql = History.select("val").where(entity: entity, parameter: parameter, notified: 'Y').where('created_at > ?', timescope).order('id desc').first
  if !sql.nil? then
    sql.val
  else
    nil
  end
end

#check_row_exists(entity, parameter, val, timescope = (Time.now - 99.years)) ⇒ Object



12
13
14
15
# File 'lib/dailyrep/Dbops.rb', line 12

def check_row_exists entity, parameter, val, timescope=(Time.now - 99.years)
  count = History.where(entity: entity, parameter: parameter, val: val).where('created_at > ?', timescope).count
  if count == 0 then false else true end
end

#write_hist(entity, parameter, val, notified = 0) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/dailyrep/Dbops.rb', line 17

def write_hist entity, parameter, val, notified=0
  case notified
  when 1 then
    notified = 'Y'
  else
    notified = 'N'
  end
  History.create(entity: entity, parameter: parameter, val: val, notified: notified)
end