Sha256: 82448e07ca716c281eda32ed20f1bde5687dcd841d73027234e07788d582ef48

Contents?: true

Size: 583 Bytes

Versions: 9

Compression:

Stored size: 583 Bytes

Contents

require 'oj'
require 'multi_json'
require 'fileutils'

module Hookit
  class DB
    
    DEFAULT_PATH = '/var/db/hookit/db.json'

    def initialize(path=nil)
      @path = path || DEFAULT_PATH
    end

    def fetch(key)
      data[key]
    end

    def put(key, value)
      data[key] = value
      save
    end

    def load
      ::MultiJson.load(::File.read(@path), symbolize_keys: true) rescue {}
    end

    def save
      ::FileUtils.mkdir_p(File.dirname(@path))
      ::File.write(@path, ::MultiJson.dump(data))
    end

    def data
      @data ||= load
    end

  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
micro-hookit-0.12.13 lib/hookit/db.rb
hookit-1.0.0 lib/hookit/db.rb
micro-hookit-0.12.12 lib/hookit/db.rb
micro-hookit-0.12.11 lib/hookit/db.rb
hookit-0.12.3 lib/hookit/db.rb
hookit-0.12.2 lib/hookit/db.rb
hookit-0.12.1 lib/hookit/db.rb
hookit-0.12.0 lib/hookit/db.rb
hookit-0.11.2 lib/hookit/db.rb