diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2010-04-09 17:52:34 +1000 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-04-09 04:49:56 -0700 |
commit | da69c5d8bf5ac4a81de3870eb51a7833bbe79ef5 (patch) | |
tree | 429f144f0bb31f659a0bc07fd412824776367c1e /railties/guides | |
parent | 69d525948058b3a0cc6c3401caa8e05532638c5a (diff) | |
download | rails-da69c5d8bf5ac4a81de3870eb51a7833bbe79ef5.tar.gz rails-da69c5d8bf5ac4a81de3870eb51a7833bbe79ef5.tar.bz2 rails-da69c5d8bf5ac4a81de3870eb51a7833bbe79ef5.zip |
Expansion on require method from runtime.rb
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/initialization.textile | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 7013c3c324..d8d119f608 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) </ruby> -Is defined on _bundler/runtime.rb_ +Is defined on _bundler/runtime.rb_: +<ruby> + 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 +</ruby> + +This method does TODO: Describe what magic this undertakes. +The first method to be called here is +autorequires_for_groups+: + +<ruby> + 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 +</ruby> h3. Firing it up! |