Module: DatabaseResetHelpers
- Included in:
- StoryTeller::Persistence
- Defined in:
- lib/story_teller/persistence.rb
Overview
module DatabaseResetHelpers
Instance Method Summary collapse
- #concrete_world_model?(db, model) ⇒ Boolean
- #reset! ⇒ Object
- #without_committing!(&block) ⇒ Object
- #world_object_ids ⇒ Object
- #world_tables(db) ⇒ Object
- #world_tree? ⇒ Boolean
Instance Method Details
#concrete_world_model?(db, model) ⇒ Boolean
139 140 141 142 143 144 |
# File 'lib/story_teller/persistence.rb', line 139 def concrete_world_model?(db, model) table_name = model.table_name table_name && db.table_exists?(table_name) rescue Sequel::Error false end |
#reset! ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/story_teller/persistence.rb', line 116 def reset! db = Sequel::Model.db tables = world_tables(db) return if tables.empty? db.from(*tables).truncate(cascade: true, restart: true) end |
#without_committing!(&block) ⇒ Object
146 147 148 |
# File 'lib/story_teller/persistence.rb', line 146 def without_committing!(&block) Sequel::Model.db.transaction(rollback: :always, auto_savepoint: true, &block) end |
#world_object_ids ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/story_teller/persistence.rb', line 150 def world_object_ids return Set.new unless Sequel::Model.db.table_exists?(:object) Inform::Object.select_map(:id).to_set rescue Sequel::Error Set.new end |