Sha256: b1f74bd9b15cea32e6d1bc238366f6edb40685f8a668bd1a93b657c435ca1e64
Contents?: true
Size: 1.16 KB
Versions: 86
Compression:
Stored size: 1.16 KB
Contents
module Knj::Opts CONFIG = { "table" => "options" } def self.init(arr_opts) arr_opts.each do |pair| if pair[0] == "knjdb" or pair[0] == "table" Knj::Opts::CONFIG[pair[0]] = pair[1] end end end def self.get(title) db = Knj::Opts::CONFIG["knjdb"] value = db.select(Knj::Opts::CONFIG["table"], {"title" => title}, {"limit" => 1}).fetch if !value return "" else return value["value"] if value.key?("value") return value[:value] if value.key?(:value) raise "Could not figure out of value." end end def self.set(title, value) db = Knj::Opts::CONFIG["knjdb"] result = db.select(Knj::Opts::CONFIG["table"], {"title" => title}, {"limit" => 1}).fetch if !result db.insert(Knj::Opts::CONFIG["table"], { "title" => title, "value" => value }) else id = nil id = result["id"] if result.key?("id") id = result[:id] if result.key?(:id) raise "Could not figure out of ID." if !id db.update(Knj::Opts::CONFIG["table"], {"value" => value}, {"id" => id}) end end end
Version data entries
86 entries across 86 versions & 1 rubygems