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

Version Path
knjrbfw-0.0.116 lib/knj/opts.rb
knjrbfw-0.0.115 lib/knj/opts.rb
knjrbfw-0.0.114 lib/knj/opts.rb
knjrbfw-0.0.113 lib/knj/opts.rb
knjrbfw-0.0.111 lib/knj/opts.rb
knjrbfw-0.0.110 lib/knj/opts.rb
knjrbfw-0.0.109 lib/knj/opts.rb
knjrbfw-0.0.108 lib/knj/opts.rb
knjrbfw-0.0.107 lib/knj/opts.rb
knjrbfw-0.0.105 lib/knj/opts.rb
knjrbfw-0.0.104 lib/knj/opts.rb
knjrbfw-0.0.103 lib/knj/opts.rb
knjrbfw-0.0.102 lib/knj/opts.rb
knjrbfw-0.0.101 lib/knj/opts.rb
knjrbfw-0.0.100 lib/knj/opts.rb
knjrbfw-0.0.99 lib/knj/opts.rb
knjrbfw-0.0.98 lib/knj/opts.rb
knjrbfw-0.0.97 lib/knj/opts.rb
knjrbfw-0.0.96 lib/knj/opts.rb
knjrbfw-0.0.95 lib/knj/opts.rb