Module: Rollbacker::Base::ClassMethods

Defined in:
lib/rollbacker/base.rb

Instance Method Summary collapse

Instance Method Details

#rollbacker(*args, &blk) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rollbacker/base.rb', line 14

def rollbacker(*args, &blk)
  unless self.included_modules.include?(ActiveRecord::Transactions::ClassMethods)
    include ActiveRecord::Transactions::ClassMethods
  end
  unless self.included_modules.include?(Rollbacker::Base::InstanceMethods)
    include InstanceMethods
    include Rollbacker::Status  unless self.included_modules.include?(Rollbacker::Status)
    has_many :rollbacker_changes, :as => :rollbackable
  end

  config = Rollbacker::Config.new(*args)
  config.actions.each do |action|
    send "before_#{action}", Rollbacker::DatabaseRollback.new(config.options)
    # send :after_rollback, Rollbacker::Recorder.new(action, config.options, &blk), :on => action
  end
  send :after_rollback, Rollbacker::Recorder.new(config.options, &blk)
end

#rollbacker!(*args, &blk) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/rollbacker/base.rb', line 32

def rollbacker!(*args, &blk)
  if args.last.kind_of?(Hash)
    args.last[:fail_on_error] = true
  else
    args << { :fail_on_error => true }
  end

  rollbacker(*args, &blk)
end