GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Kernel#dependency requires gems/files in a before_app_loads block.
benburkert (author)
Mon Mar 03 12:48:51 -0800 2008
commit  0ebd60030f2d8d5e4f50c0bf534172aaacc5c937
tree    9cb7ca47af9329db802db498a54c17713ba9e3a7
parent  ace2bd2aa023b16abc70a83333ffff5e46c65908
...
114
115
116
117
118
119
120
 
 
 
121
122
123
...
182
183
184
 
 
185
186
187
...
114
115
116
 
 
 
 
117
118
119
120
121
122
...
181
182
183
184
185
186
187
188
0
@@ -114,10 +114,9 @@ module Merb
0
     # ==== Returns
0
     # String:: The directory that contains the log file.
0
     def log_path
0
- if Merb::Config[:log_file]
0
- File.dirname(Merb::Config[:log_file])
0
- else
0
- Merb.root_path("log")
0
+ case Merb::Config[:log_file]
0
+ when String then File.dirname(Merb::Config[:log_file])
0
+ else Merb.root_path("log")
0
       end
0
     end
0
 
0
@@ -182,6 +181,8 @@ module Merb
0
       Merb::BootLoader::Logger.run
0
       Merb.logger.auto_flush = true
0
       Merb::BootLoader::Dependencies.run
0
+ Merb::BootLoader::BuildFramework.run
0
+ Merb::BootLoader::BeforeAppRuns.run
0
     end
0
     
0
     # Reload the framework.
...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
...
14
15
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
0
@@ -14,25 +14,27 @@ module Kernel
0
   # off to the system gems (so if you have a lower version of a gem in
0
   # ROOT/gems, it'll still get loaded).
0
   def dependency(name, *ver)
0
- try_framework = Merb.frozen?
0
- begin
0
- # If this is a piece of merb, and we're frozen, try to require
0
- # first, so we can pick it up from framework/,
0
- # otherwise try activating the gem
0
- if name =~ /^merb/ && try_framework
0
- require name
0
- else
0
- Gem.activate(name, true, *ver)
0
- Merb.logger.info("loading gem '#{name}' from #{__app_file_trace__.first} ...")
0
- end
0
- rescue LoadError
0
- if try_framework
0
- try_framework = false
0
- retry
0
- else
0
- Merb.logger.info("loading gem '#{name}' from #{__app_file_trace__.first} ...")
0
- # Failed requiring as a gem, let's try loading with a normal require.
0
- require name
0
+ Merb::BootLoader.before_app_loads do
0
+ try_framework = Merb.frozen?
0
+ begin
0
+ # If this is a piece of merb, and we're frozen, try to require
0
+ # first, so we can pick it up from framework/,
0
+ # otherwise try activating the gem
0
+ if name =~ /^merb/ && try_framework
0
+ require name
0
+ else
0
+ Gem.activate(name, true, *ver)
0
+ Merb.logger.info("loading gem '#{name}' from #{__app_file_trace__.first} ...")
0
+ end
0
+ rescue LoadError
0
+ if try_framework
0
+ try_framework = false
0
+ retry
0
+ else
0
+ Merb.logger.info("loading gem '#{name}' from #{__app_file_trace__.first} ...")
0
+ # Failed requiring as a gem, let's try loading with a normal require.
0
+ require name
0
+ end
0
       end
0
     end
0
   end
...
7
8
9
 
10
11
12
13
14
15
 
16
17
18
19
20
21
 
 
22
23
24
...
31
32
33
 
34
35
36
...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
35
36
37
38
39
40
41
0
@@ -7,18 +7,22 @@ describe "Kernel#dependency" do
0
     Gem.stub!(:use_paths)
0
     Gem.stub!(:clear_paths)
0
     Merb.logger = Merb::Logger.new(File.open("/dev/null", "w"))
0
+ Merb::BootLoader.before_load_callbacks = []
0
   end
0
   
0
   ["dependency", "dependencies"].each do |meth|
0
     it "loads in files from the local gem-cache first (with #{meth})" do
0
       Gem.should_receive(:activate).with("json_pure", true).and_return(true)
0
       Kernel.send meth, "json_pure"
0
+ Merb::BootLoader::BeforeAppRuns.run
0
     end
0
   
0
     it "does a require if it can't find it in either gem cache (with #{meth})" do
0
       Gem.stub!(:activate).twice.with("RedCloth", true).and_raise(LoadError)
0
       Kernel.should_receive(:require).with("RedCloth")
0
       Kernel.send meth, "RedCloth"
0
+
0
+ Merb::BootLoader::BeforeAppRuns.run
0
     end
0
   end
0
 
0
@@ -31,6 +35,7 @@ describe "Kernel#dependency" do
0
     Kernel.should_receive(:dependency).once.with("GreenCloth", ">1").and_return(true)
0
     Kernel.should_receive(:dependency).once.with("RedCloth", ">0.5").and_return(true)
0
     Kernel.dependencies "RedCloth" => ">0.5", "GreenCloth" => ">1"
0
+
0
   end
0
 end
0
 

Comments

    No one has commented yet.