Module: Padrino::Reloader::Storage
Instance Method Summary collapse
- #clear! ⇒ Object
- #commit(name) ⇒ Object
- #prepare(name) ⇒ Object
- #remove(name) ⇒ Object
- #rollback(name) ⇒ Object
Instance Method Details
#clear! ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/padrino-core/reloader/storage.rb', line 6 def clear! files.each_key do |file| remove(file) Reloader.remove_feature(file) end @files = {} end |
#commit(name) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/padrino-core/reloader/storage.rb', line 33 def commit(name) entry = { :constants => new_classes(@old_entries[name][:constants]), :features => Set.new($LOADED_FEATURES) - @old_entries[name][:features] - [name] } files[name] = entry @old_entries.delete(name) end |
#prepare(name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/padrino-core/reloader/storage.rb', line 21 def prepare(name) file = remove(name) @old_entries ||= {} @old_entries[name] = { :constants => object_classes, :features => old_features = Set.new($LOADED_FEATURES.dup) } features = file && file[:features] || [] features.each{ |feature| Reloader.safe_load(feature, :force => true) } Reloader.remove_feature(name) if old_features.include?(name) end |
#remove(name) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/padrino-core/reloader/storage.rb', line 14 def remove(name) file = files[name] || return file[:constants].each{ |constant| Reloader.remove_constant(constant) } file[:features].each{ |feature| Reloader.remove_feature(feature) } files.delete(name) end |
#rollback(name) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/padrino-core/reloader/storage.rb', line 42 def rollback(name) new_classes(@old_entries[name][:constants]).each do |klass| loaded_in_name = files.each do |file, data| next if file == name break if data[:constants].include?(klass) end Reloader.remove_constant(klass) if loaded_in_name end @old_entries.delete(name) end |