class Rowdb
Synchronous file system.
Public Class Methods
new(file_path, adapter = :sync, js_var = "db")
click to toggle source
# File lib/rowdb.rb, line 12 def initialize(file_path, adapter = :sync, js_var = "db") # Initialize the chosen adapter. @adapter = self.send(adapter, file_path, js_var) @chain = R_.chain(@adapter.read()) @get_path = nil end
Public Instance Methods
defaults(data)
click to toggle source
Set default data.
# File lib/rowdb.rb, line 23 def defaults(data) if @chain.value().nil? @chain = R_.chain(data.transform_keys(&:to_sym)) end self end
get(path)
click to toggle source
# File lib/rowdb.rb, line 30 def get(path) @get_path = path @chain.get(path) self end
push(value)
click to toggle source
# File lib/rowdb.rb, line 45 def push(value) if @get_path.nil? raise StandardError.new "You must get() before push()." end # Add value to end of array. adder = -> (items) { [*items, value] } R_.update(@chain.value(), @get_path, adder) self end
set(path, value)
click to toggle source
# File lib/rowdb.rb, line 36 def set(path, value) @chain.set(path, value) self end
value()
click to toggle source
# File lib/rowdb.rb, line 41 def value() @chain.value() end
write()
click to toggle source
# File lib/rowdb.rb, line 59 def write() @adapter.write(@chain.value()) self end
Private Instance Methods
sync(file_path, js_var)
click to toggle source
Adapters.
The chosen adapter is initialized by the constructor.
# File lib/rowdb.rb, line 72 def sync(file_path, js_var) Sync.new(file_path, js_var) end