Module: Immortal::InstanceMethods
- Defined in:
- lib/immortal.rb
Class Method Summary collapse
Instance Method Summary collapse
- #destroy! ⇒ Object
- #destroy_without_callbacks ⇒ Object
- #immortal_destroy ⇒ Object
- #recover! ⇒ Object
Class Method Details
.included(base) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/immortal.rb', line 88 def self.included(base) unless base.table_exists? && base.columns_hash[COLUMN_NAME] && !base.columns_hash[COLUMN_NAME].null Kernel.warn( "[Immortal] The '#{COLUMN_NAME}' column in #{base} is nullable, " \ 'change the column to not accept NULL values' ) end base.class_eval do scope(:mortal, -> { where(COLUMN_NAME => false) }) scope(:immortal, -> { where(COLUMN_NAME => true) }) default_scope { -> { mortal } } if arel_table[COLUMN_NAME] alias_method :mortal_destroy, :destroy alias_method :destroy, :immortal_destroy end end |
Instance Method Details
#destroy! ⇒ Object
115 116 117 |
# File 'lib/immortal.rb', line 115 def destroy! mortal_destroy end |
#destroy_without_callbacks ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/immortal.rb', line 119 def destroy_without_callbacks scoped_record.update_all( COLUMN_NAME => true, updated_at: current_time_from_proper_timezone ) @destroyed = true reload freeze end |
#immortal_destroy ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/immortal.rb', line 107 def immortal_destroy with_transaction_returning_status do run_callbacks :destroy do destroy_without_callbacks end end end |
#recover! ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/immortal.rb', line 130 def recover! scoped_record.update_all( COLUMN_NAME => false, updated_at: current_time_from_proper_timezone ) @destroyed = false reload end |