Module: Dcmgr::Models::ArchiveChangedColumn

Defined in:
lib/dcmgr/models/base_new.rb

Overview

This plugin is to archive the changes on each column of the model to a history table.

plugin ArchiveChangedColumn, :your_history_table

or

plugin ArchiveChangedColumn history_dataset = DB

The history table should have the schema below: schema do

Fixnum :id, :null=>false, :primary_key=>true
String :uuid, :size=>50, :null=>false
String :attr, :null=>false
String :vchar_value, :null=>true
String :blob_value, :null=>true, :text=>true
Time  :created_at, :null=>false
index [:uuid, :created_at]
index [:uuid, :attr]

end

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.configure(model, history_table = nil) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/dcmgr/models/base_new.rb', line 315

def self.configure(model, history_table=nil)
  model.history_dataset = case history_table
                          when NilClass
                            nil
                          when String,Symbol
                            model.db.from(history_table)
                          when Class
                            raise "Unknown type" unless history_table < Sequel::Model
                            history_table.dataset
                          when Sequel::Dataset
                            history_table
                          else
                            raise "Unknown type"
                          end
end