system_data.rb
381 Bytes
class SystemData
attr_reader :id
def initialize(args = {})
@backend = args[:backend]
@id = args[:id]
end
def save
kind = self.class.to_s.to_sym
if @id
@backend.update(kind, to_h)
else
@backend.insert(kind, to_h)
end
end
def to_h
Hash[instance_variables.map do |var|
[var[1...var.size].to_sym, eval(var)] if var != '@backend'
end]
end
end