Class: Undestroy::Binding::ActiveRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/undestroy/binding/active_record.rb

Defined Under Namespace

Modules: Restorable Classes: MigrationStatement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options = {}) {|self.config| ... } ⇒ ActiveRecord

Returns a new instance of ActiveRecord.

Yields:



8
9
10
11
12
13
14
15
16
17
# File 'lib/undestroy/binding/active_record.rb', line 8

def initialize(model, options={})
  ensure_is_ar! model

  self.model = model
  self.config = Undestroy::Config.config.merge(options)
  yield self.config if block_given?
  self.active = true

  set_defaults
end

Instance Attribute Details

#activeObject Also known as: active?

Returns the value of attribute active.



5
6
7
# File 'lib/undestroy/binding/active_record.rb', line 5

def active
  @active
end

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/undestroy/binding/active_record.rb', line 5

def config
  @config
end

#modelObject

Returns the value of attribute model.



5
6
7
# File 'lib/undestroy/binding/active_record.rb', line 5

def model
  @model
end

Instance Method Details

#before_destroy(instance) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/undestroy/binding/active_record.rb', line 19

def before_destroy(instance)
  config.internals[:archive].new(
    :config => config,
    :transfer_options => { :target => target(instance) },
    :source => instance
  ).run if active?
end

#deactivatedObject



31
32
33
34
35
36
37
# File 'lib/undestroy/binding/active_record.rb', line 31

def deactivated
  previously = self.active
  self.active = false
  yield
ensure
  self.active = previously
end

#prefix_table_name(name) ⇒ Object



27
28
29
# File 'lib/undestroy/binding/active_record.rb', line 27

def prefix_table_name(name)
  self.config.prefix.to_s + name.to_s
end