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.
113 114 115 116 117 |
# File 'lib/rails_development_boost/dependencies_patch.rb', line 113 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
136 137 138 |
# File 'lib/rails_development_boost/dependencies_patch.rb', line 136 def <<(mod) (Class === mod ? @classes : @modules) << mod end |
#each_dependent_on(mod, &block) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/rails_development_boost/dependencies_patch.rb', line 119 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
128 129 130 131 132 133 134 |
# File 'lib/rails_development_boost/dependencies_patch.rb', line 128 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 |