class MeowDBHash

Public Class Methods

new(hash, id, file) click to toggle source
Calls superclass method
# File src/meowdb/hash.rb, line 25
def initialize(hash, id, file)
  super()
  @__id = id if (id != "/")
  @file = file
  hash.each do |k, v|
    self[k] = v
  end
end

Public Instance Methods

__id() click to toggle source
# File src/meowdb/hash.rb, line 34
def __id
  return @__id
end
save() click to toggle source
# File src/meowdb/hash.rb, line 38
def save()
  all_data = JSON.parse(File.read(@file))
  info = ""
  if __id
    __id.split(".").each do |property|
      info += "[\"#{property}\"]"
    end
  end
  self.each do |k, v|
    unless (k.start_with?("__"))
      return MeowDBError.new("The value must be a string, number, hash, boolean, array or a nil") if !valid_value?(v)
      eval("all_data#{info}[\"#{k}\"] = #{stringify_data(v)}")
    end
  end    
  File.write(@file, JSON.generate(all_data))
  return eval("all_data#{info}")
end