3 Adds a minimal dependency injection framework so that owners of polymorphic relationships reload after their children, reinjecting the child helper methods.
5 Overrides Dependencies#<tt>new_constants_in</tt>.
10 mattr_accessor :injection_graph
11 self.injection_graph = Hash.new([])
13 # Add a dependency for this target.
14 def inject_dependency(target, *requirements)
15 target, requirements = target.to_s, requirements.map(&:to_s)
16 injection_graph[target] = ((injection_graph[target] + requirements).uniq - [target])
17 requirements.each {|requirement| mark_for_unload requirement }
18 _logger_debug "injection graph: #{injection_graph.inspect}" if Dependencies.log_activity
21 # Make sure any dependent constants of the constants added by <tt>yield</tt> are reloaded.
22 def new_constants_in_with_injection(*descs, &block) # chain
24 if Dependencies.log_activity
25 _logger_debug "autoloaded constants: #{autoloaded_constants.inspect}"
26 _logger_debug "explicitly unloadable constants: #{explicitly_unloadable_constants.inspect}"
29 returning(new_constants_in_without_injection(*descs, &block)) do |found|
30 _logger_debug "new constants: #{found.inspect}" if Dependencies.log_activity and found.any?
31 found.each do |constant|
32 injection_graph[constant].each do |requirement|
33 requirement.constantize
34 _logger_debug "constantized #{requirement}" if Dependencies.log_activity
39 alias_method_chain :new_constants_in, :injection