class Orientea::ChangingCommand

Public Class Methods

build(record) click to toggle source
# File lib/orientea/changing_command.rb, line 5
def self.build(record)
  command = self.new
  command.data = Hash.new
  command.data['cls_str'] = record.class.to_s
  command.data['cls_id'] = record.id
  command.data['changes'] = record.changes.to_json
  # command.save!
  command
end

Public Instance Methods

get_record(old = false) click to toggle source
# File lib/orientea/changing_command.rb, line 19
def get_record(old = false)
  cls = self.data['cls_str'].constantize
  id = self.data['cls_id']
  object = cls.find(id)
  JSON.load(self.data['changes']).each do |key, value|
    object.send("#{key}=", (old ? value.first : value.last))
  end
  object
end
record_changes() click to toggle source
# File lib/orientea/changing_command.rb, line 15
def record_changes
  data['changes']
end