Module: Kakurenbo::Core
- Defined in:
- lib/kakurenbo/core.rb
Defined Under Namespace
Modules: Aliases, Callbacks, ClassMethods, Scopes
Class Method Summary collapse
-
.included(base_class) ⇒ Object
Extend ClassMethods after include.
Instance Method Summary collapse
-
#delete(options = {:hard => false}) ⇒ Object
delete record.
-
#destroy(options = {:hard => false}) ⇒ Boolean, self
destroy record and run callbacks.
-
#destroy!(options = {:hard => false}) ⇒ self
destroy record and run callbacks.
- #destroy_row ⇒ Object
- #destroyed? ⇒ Boolean
- #kakurenbo_column ⇒ Object
- #persisted? ⇒ Boolean
-
#restore(options = {:recursive => true}) ⇒ Boolean, self
restore record.
-
#restore!(options = {:recursive => true}) ⇒ self
restore record.
Class Method Details
.included(base_class) ⇒ Object
Extend ClassMethods after include.
4 5 6 7 8 9 |
# File 'lib/kakurenbo/core.rb', line 4 def self.included(base_class) base_class.extend ClassMethods base_class.extend Callbacks base_class.extend Scopes base_class.extend Aliases end |
Instance Method Details
#delete(options = {:hard => false}) ⇒ Object
delete record.
57 58 59 60 61 62 63 64 |
# File 'lib/kakurenbo/core.rb', line 57 def delete( = {:hard => false}) if [:hard] self.class.delete(self.id, ) else return if new_record? or destroyed? update_column kakurenbo_column, current_time_from_proper_timezone end end |
#destroy(options = {:hard => false}) ⇒ Boolean, self
destroy record and run callbacks.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/kakurenbo/core.rb', line 72 def destroy( = {:hard => false}) if [:hard] with_transaction_returning_status do hard_destroy_associated_records self.reload.hard_destroy end else return true if destroyed? with_transaction_returning_status do destroy_at = current_time_from_proper_timezone run_callbacks(:destroy){ update_column kakurenbo_column, destroy_at; self } end end end |
#destroy!(options = {:hard => false}) ⇒ self
destroy record and run callbacks.
93 94 95 |
# File 'lib/kakurenbo/core.rb', line 93 def destroy!( = {:hard => false}) destroy() || raise(ActiveRecord::RecordNotDestroyed) end |
#destroy_row ⇒ Object
97 98 99 |
# File 'lib/kakurenbo/core.rb', line 97 def destroy_row relation_for_destroy.delete_all(nil, :hard => true) end |
#destroyed? ⇒ Boolean
101 102 103 |
# File 'lib/kakurenbo/core.rb', line 101 def destroyed? !send(kakurenbo_column).nil? end |
#kakurenbo_column ⇒ Object
105 106 107 |
# File 'lib/kakurenbo/core.rb', line 105 def kakurenbo_column self.class.kakurenbo_column end |
#persisted? ⇒ Boolean
109 110 111 |
# File 'lib/kakurenbo/core.rb', line 109 def persisted? !new_record? end |
#restore(options = {:recursive => true}) ⇒ Boolean, self
restore record.
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/kakurenbo/core.rb', line 119 def restore( = {:recursive => true}) return false unless destroyed? with_transaction_returning_status do run_callbacks(:restore) do parent_deleted_at = send(kakurenbo_column) restore_associated_records(parent_deleted_at) if [:recursive] update_column kakurenbo_column, nil self end end end |
#restore!(options = {:recursive => true}) ⇒ self
restore record.
138 139 140 |
# File 'lib/kakurenbo/core.rb', line 138 def restore!( = {:recursive => true}) restore() || raise(ActiveRecord::RecordNotRestored) end |