class Cfan122::Reloader
Public Class Methods
new(top)
click to toggle source
# File lib/cfan122.rb, line 40 def initialize(top) @top = top end
Public Instance Methods
reload()
click to toggle source
# File lib/cfan122.rb, line 44 def reload cleanup load_all end
Private Instance Methods
all_project_objects(current = @top)
click to toggle source
@return [Array<Module>] Recursively find all modules and classes under the MyGemName namespace. This code makes assumption number #2 above.
# File lib/cfan122.rb, line 61 def all_project_objects(current = @top) return [] unless current.is_a?(Module) and current.to_s.split('::').first == @top.to_s [current] + current.constants.flat_map{|x| all_project_objects(current.const_get(x))} end
all_project_objects_lookup()
click to toggle source
@return [Hash] of the format {Module => true} containing all modules
and classes under the MyGemName namespace
# File lib/cfan122.rb, line 68 def all_project_objects_lookup @_all_project_objects_lookup ||= Hash[all_project_objects.map{|x| [x, true]}] end
cleanup(parent = Object, current = @top)
click to toggle source
Recursively removes all constant entries of modules and classes under the MyGemName namespace
# File lib/cfan122.rb, line 74 def cleanup(parent = Object, current = @top) return unless all_project_objects_lookup[current] current.constants.each {|const| cleanup current, current.const_get(const)} parent.send(:remove_const, current.to_s.split('::').last.to_sym) end
load_all()
click to toggle source
Re-load all files that were previously reloaded
# File lib/cfan122.rb, line 81 def load_all loaded_files.each{|x| load x} true end
loaded_files()
click to toggle source
@return [Array<String>] array of all files that were loaded to memory under the lib/my_gem_name folder. This code makes assumption #1 above.
# File lib/cfan122.rb, line 54 def loaded_files $LOADED_FEATURES.select{|x| x.starts_with?(__FILE__.chomp('.rb'))} end