Module: Massimo::Reloader
Instance Method Summary collapse
- #cache ⇒ Object
- #load(name = :default) ⇒ Object
- #reload(name = :default, &block) ⇒ Object
- #unload(name = :default) ⇒ Object
Instance Method Details
#cache ⇒ Object
33 34 35 |
# File 'lib/massimo/reloader.rb', line 33 def cache @cache ||= {} end |
#load(name = :default) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/massimo/reloader.rb', line 5 def load(name = :default) cache[name] ||= {} previous_constants = Object.constants previous_features = $LOADED_FEATURES.dup yield if block_given? cache[name][:constants] = (Object.constants - previous_constants).uniq cache[name][:features] = ($LOADED_FEATURES - previous_features).uniq cache[name] end |
#reload(name = :default, &block) ⇒ Object
28 29 30 31 |
# File 'lib/massimo/reloader.rb', line 28 def reload(name = :default, &block) unload(name) load(name, &block) end |
#unload(name = :default) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/massimo/reloader.rb', line 17 def unload(name = :default) return unless cache.key?(name) cache[name][:constants].reject! do |const| Object.send(:remove_const, const) if Object.const_defined?(const) end if cache[name].key?(:constants) cache[name][:features].reject! do |feature| $LOADED_FEATURES.delete(feature) end if cache[name].key?(:features) cache[name] end |