Module: Kakurenbo::MixinARBase::ClassMethods
- Defined in:
- lib/kakurenbo/mixin_ar_base.rb
Instance Method Summary collapse
-
#inherited(child_class) ⇒ Object
Initialize Kakurenbo in child class.
-
#paranoid? ⇒ Boolean
Will be override this method, if class is soft_delete.
-
#remodel_as_original ⇒ Object
Remodel Model as normal.
-
#remodel_as_soft_delete(options = {}) ⇒ Object
(also: #acts_as_paranoid)
Remodel Model as soft-delete.
Instance Method Details
#inherited(child_class) ⇒ Object
Initialize Kakurenbo in child class.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kakurenbo/mixin_ar_base.rb', line 12 def inherited(child_class) super child_class.define_singleton_method :table_name= do |value| super(value) if has_kakurenbo_column? remodel_as_soft_delete else remodel_as_original end end child_class.instance_eval do remodel_as_soft_delete if has_kakurenbo_column? end end |
#paranoid? ⇒ Boolean
Will be override this method, if class is soft_delete.
70 71 72 |
# File 'lib/kakurenbo/mixin_ar_base.rb', line 70 def paranoid? false end |
#remodel_as_original ⇒ Object
Note:
Restore to original model.
Remodel Model as normal.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kakurenbo/mixin_ar_base.rb', line 31 def remodel_as_original if paranoid? alias_method :delete, :hard_delete alias_method :destroy, :hard_destroy alias_method :destroy!, :hard_destroy! singleton_class.send(:alias_method, :delete, :hard_delete) singleton_class.send(:alias_method, :delete_all, :hard_delete_all) define_singleton_method(:paranoid?) { false } end end |
#remodel_as_soft_delete(options = {}) ⇒ Object Also known as: acts_as_paranoid
Remodel Model as soft-delete.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/kakurenbo/mixin_ar_base.rb', line 48 def remodel_as_soft_delete( = {}) .reverse_merge!( :column => :deleted_at ) unless paranoid? alias_method :hard_delete, :delete alias_method :hard_destroy, :destroy alias_method :hard_destroy!, :destroy! singleton_class.send(:alias_method, :hard_delete, :delete) singleton_class.send(:alias_method, :hard_delete_all, :delete_all) class_attribute :kakurenbo_column include Kakurenbo::Core end self.kakurenbo_column = [:column] end |