Class: RailsDevelopmentBoost::DependenciesPatch::ModuleCache
- Inherits:
-
Object
- Object
- RailsDevelopmentBoost::DependenciesPatch::ModuleCache
- Defined in:
- lib/rails_development_boost/dependencies_patch.rb
Instance Method Summary collapse
- #<<(mod) ⇒ Object
- #each_dependent_on(mod, &block) ⇒ Object
-
#initialize ⇒ ModuleCache
constructor
A new instance of ModuleCache.
- #remove_const(const_name, object) ⇒ Object
Constructor Details
#initialize ⇒ ModuleCache
Returns a new instance of ModuleCache.
97 98 99 100 101 |
# File 'lib/rails_development_boost/dependencies_patch.rb', line 97 def initialize @classes, @modules = [], [] ObjectSpace.each_object(Module) {|mod| self << mod if relevant?(mod)} @singleton_ancestors = Hash.new {|h, klass| h[klass] = klass.singleton_class.ancestors} end |
Instance Method Details
#<<(mod) ⇒ Object
120 121 122 |
# File 'lib/rails_development_boost/dependencies_patch.rb', line 120 def <<(mod) (Class === mod ? @classes : @modules) << mod end |
#each_dependent_on(mod, &block) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/rails_development_boost/dependencies_patch.rb', line 103 def each_dependent_on(mod, &block) arr = [] each_inheriting_from(mod) do |other| mod_name = other._mod_name arr << other if qualified_const_defined?(mod_name) && mod_name.constantize == other end arr.each(&block) end |
#remove_const(const_name, object) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/rails_development_boost/dependencies_patch.rb', line 112 def remove_const(const_name, object) if object && Class === object remove_const_from_colletion(@classes, const_name, object) else [@classes, @modules].each {|collection| remove_const_from_colletion(collection, const_name, object)} end end |