Class: OmahPluginSqlite

Inherits:
Object
  • Object
show all
Includes:
RXFHelperModule
Defined in:
lib/omah-plugin-sqlite.rb

Instance Method Summary collapse

Constructor Details

#initialize(settings: {}, variables: {}, debug: false) ⇒ OmahPluginSqlite

Returns a new instance of OmahPluginSqlite.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/omah-plugin-sqlite.rb', line 13

def initialize(settings: {}, variables: {}, debug: false)
  
  dbfile = settings[:dbfile]
  
  sqlite = dbfile =~ /^sqlite:\/\// ? DRbSQLite : SQLite3::Database
  
  if FileX.exists? dbfile then
    
    @db = sqlite.new dbfile      
    
  else
    
    @db = sqlite.new dbfile
      
    # Create a database
    rows = @db.execute <<-SQL
create table headers (
  id integer primary key autoincrement,
  from_x varchar(50),
  to_x varchar(50),
  subject varchar(140),
  date timestamp,
  filepath varchar(70)

);
SQL
  
  end


end

Instance Method Details

#on_newmessage(h) ⇒ Object



45
46
47
48
49
50
# File 'lib/omah-plugin-sqlite.rb', line 45

def on_newmessage(h)

  @db.execute("INSERT INTO headers (from_x, to_x, subject, date, filepath) 
             VALUES (?, ?, ?, ?, ?)", %i(from to subject date html_filepath)\
             .map{|x| h[x]} )
end