Class: Undestroy::Binding::ActiveRecord
- Inherits:
-
Object
- Object
- Undestroy::Binding::ActiveRecord
- Defined in:
- lib/undestroy/binding/active_record.rb
Defined Under Namespace
Modules: Restorable Classes: MigrationStatement
Instance Attribute Summary collapse
-
#active ⇒ Object
(also: #active?)
Returns the value of attribute active.
-
#config ⇒ Object
Returns the value of attribute config.
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
- #before_destroy(instance) ⇒ Object
- #deactivated ⇒ Object
-
#initialize(model, options = {}) {|self.config| ... } ⇒ ActiveRecord
constructor
A new instance of ActiveRecord.
- #prefix_table_name(name) ⇒ Object
Constructor Details
#initialize(model, options = {}) {|self.config| ... } ⇒ ActiveRecord
Returns a new instance of ActiveRecord.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/undestroy/binding/active_record.rb', line 8 def initialize(model, ={}) ensure_is_ar! model self.model = model self.config = Undestroy::Config.config.merge() yield self.config if block_given? self.active = true set_defaults end |
Instance Attribute Details
#active ⇒ Object 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 |
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/undestroy/binding/active_record.rb', line 5 def config @config end |
#model ⇒ Object
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 |
#deactivated ⇒ Object
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 |