class Hookit::DB
Constants
- DEFAULT_PATH
Public Class Methods
new(path=nil)
click to toggle source
# File lib/hookit/db.rb, line 10 def initialize(path=nil) @path = path || DEFAULT_PATH end
Public Instance Methods
data()
click to toggle source
# File lib/hookit/db.rb, line 32 def data @data ||= load end
fetch(key)
click to toggle source
# File lib/hookit/db.rb, line 14 def fetch(key) data[key] end
load()
click to toggle source
# File lib/hookit/db.rb, line 23 def load ::MultiJson.load(::File.read(@path), symbolize_keys: true) rescue {} end
put(key, value)
click to toggle source
# File lib/hookit/db.rb, line 18 def put(key, value) data[key] = value save end
save()
click to toggle source
# File lib/hookit/db.rb, line 27 def save ::FileUtils.mkdir_p(File.dirname(@path)) ::File.write(@path, ::MultiJson.dump(data)) end