From 11f838dc2e6a32a9e55e77f2c1114dbbfa6af6b2 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Fri, 9 Apr 2010 17:52:34 +1000 Subject: [PATCH] Expansion on require method from runtime.rb --- railties/guides/source/initialization.textile | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 7013c3c3244ac..d8d119f6087e2 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -2229,9 +2229,44 @@ The second +require+ method here: load(gemfile).require(*groups) -Is defined on _bundler/runtime.rb_ +Is defined on _bundler/runtime.rb_: + + def require(*groups) + groups.map! { |g| g.to_sym } + groups = [:default] if groups.empty? + autorequires = autorequires_for_groups(*groups) + + groups.each do |group| + (autorequires[group] || [[]]).each do |path, explicit| + if explicit + Kernel.require(path) + else + begin + Kernel.require(path) + rescue LoadError + end + end + end + end + end + + +This method does TODO: Describe what magic this undertakes. +The first method to be called here is +autorequires_for_groups+: + + + def autorequires_for_groups(*groups) + groups.map! { |g| g.to_sym } + autorequires = Hash.new { |h,k| h[k] = [] } + + ordered_deps = [] + specs_for(*groups).each do |g| + dep = @definition.dependencies.find{|d| d.name == g.name } + ordered_deps << dep if dep && !ordered_deps.include?(dep) + end + h3. Firing it up!