Class: OmahPluginSqlite
- Inherits:
-
Object
- Object
- OmahPluginSqlite
- Defined in:
- lib/omah-plugin-sqlite.rb
Instance Method Summary collapse
-
#initialize(settings: {}, variables: {}) ⇒ OmahPluginSqlite
constructor
A new instance of OmahPluginSqlite.
- #on_newmessage(h) ⇒ Object
Constructor Details
#initialize(settings: {}, variables: {}) ⇒ OmahPluginSqlite
Returns a new instance of OmahPluginSqlite.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/omah-plugin-sqlite.rb', line 9 def initialize(settings: {}, variables: {}) dbfile = settings[:dbfile] unless File.exists? dbfile then @db = SQLite3::Database.new dbfile # Create a database rows = @db.execute <<-SQL create table headers ( uid integer primary key, from_x varchar(50), to_x varchar(50), subject varchar(140), date timestamp ); SQL end end |
Instance Method Details
#on_newmessage(h) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/omah-plugin-sqlite.rb', line 33 def (h) @db.execute("INSERT INTO headers (uid, from_x, to_x, subject, date) VALUES (?, ?, ?, ?, ?)", [(Time.now.strftime("%y%m%d") + \ h[:uid]).to_i] + %i(from to subject date).map{|x| h[x]} ) end |