Take the 2008 Git User's Survey and help out! [ hide ]

public
Fork of wycats/merb-core
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/auser/merb-core.git
Search Repo:
Important changes to the BootLoader process

Merb::Config is now correctly taken into account in Rake (and 
spec_helper.rb).
Before, Merb::BootLoader::Dependencies would require config/init.rb and
config/environments/*.rb, but due to the nature of Kernel#require, this 
would happen
just once at runtime.

Now Kernel#load will (re)load the init files whenever the 
Merb::BootLoader::Dependencies
step is run. For Rake this happens twice: the first time to load 
dependencies to gather
additional Rake tasks, the second time if a task depends on the :merb_env 
task. Without
the fixes, the :merb_env just loaded with the default config.

In spec_helper.rb (of a generated Merb app) the Merb BootLoader would run 
twice during
'rake specs' (once for controller specs, again for model specs) causing 
everyting to
reload. The Merb::BootLoader::LoadClasses step proved to be problematic 
for some class
definitions. The method Merb.start_environment has been added, to prevent 
the procedure
from running through the BootLoader again if it has been encountered a 
second time.

To enable greater control of certain core components being loaded, you can 
now work
with Merb.disable(:comp, ...) which internally stores an array of symbols 
in
Merb::Config[:disabled_components]. Sofar this has only been applied to 
the JSON
Gems (Merb.disable :json) but it has been implemented to be a 
generalization of it.

A pesky bug concerning Merb::BootLoader.subclasses being emptied has been 
fixed too.
fabien (author)
Mon Mar 10 12:09:56 -0700 2008
commit  2f1555c55cd6957a1fc245a1daf079de7cb7c1dc
tree    0e516fec559c95eda1e18685537ed387a5b1fe2b
parent  e6303b6c9a656156acdb516ebb08614af102a25f
...
13
14
15
 
 
16
17
18
...
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
...
102
103
104
105
 
106
107
108
...
170
171
172
 
 
173
174
175
176
177
178
 
 
 
179
180
181
182
183
...
214
215
216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
218
219
...
238
239
240
241
242
 
243
...
13
14
15
16
17
18
19
20
...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
126
127
128
 
129
130
131
132
...
194
195
196
197
198
199
 
 
 
 
 
200
201
202
203
 
204
205
206
...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
...
287
288
289
 
290
291
292
0
@@ -13,6 +13,8 @@ module Merb
0
   module GlobalHelpers; end
0
   class << self
0
 
0
+ # Startup Merb by setting up the Config and starting the server.
0
+ #
0
     # ==== Parameters
0
     # argv<String, Hash>::
0
     # The config arguments to start Merb with. Defaults to +ARGV+.
0
@@ -26,6 +28,28 @@ module Merb
0
       Merb.root = Merb::Config[:merb_root]
0
       Merb::Server.start(Merb::Config[:port], Merb::Config[:cluster])
0
     end
0
+
0
+ # Start the Merb environment, but only if it hasn't been loaded yet.
0
+ #
0
+ # ==== Parameters
0
+ # argv<String, Hash>::
0
+ # The config arguments to start Merb with. Defaults to +ARGV+.
0
+ def start_environment(argv=ARGV)
0
+ unless (@started ||= false)
0
+ start(argv)
0
+ @started = true
0
+ end
0
+ end
0
+
0
+ # Restart the Merb environment explicitly.
0
+ #
0
+ # ==== Parameters
0
+ # argv<String, Hash>::
0
+ # The config arguments to restart Merb with. Defaults to +Merb::Config+.
0
+ def restart_environment(argv={})
0
+ @started = false
0
+ start_environment(Merb::Config.to_hash.merge(argv))
0
+ end
0
 
0
     attr_accessor :environment, :load_paths, :adapter
0
     
0
@@ -102,7 +126,7 @@ module Merb
0
         Merb::Config[:log_file]
0
       elsif $TESTING
0
         log_path / "merb_test.log"
0
- elsif !(Merb::Config[:daemonize] || Merb::Config[:cluster] )
0
+ elsif !(Merb::Config[:daemonize] || Merb::Config[:cluster])
0
         STDOUT
0
       else
0
         log_path / "merb.#{Merb::Config[:port]}.log"
0
@@ -170,14 +194,13 @@ module Merb
0
       @frozen = true
0
     end
0
 
0
+ # Load all basic dependencies (selected BootLoaders only).
0
+ #
0
     # ==== Parameters
0
- # init_file<String>:: The file to load first.
0
- # options<Hash>:: Other options to pass on to the Merb config.
0
- def load_dependencies(init_file, options = {})
0
- Merb::Config.setup({:log_file => $stdout, :log_level => :warn,
0
- :init_file => init_file}.merge(options))
0
+ # options<Hash>:: Options to pass on to the Merb config.
0
+ def load_dependencies(options = {})
0
+ Merb::Config.setup({ :log_file => $stdout, :log_level => :warn, :log_auto_flush => true }.merge(options))
0
       Merb::BootLoader::Logger.run
0
- Merb.logger.auto_flush = true
0
       Merb::BootLoader::BuildFramework.run
0
       Merb::BootLoader::Dependencies.run
0
       Merb::BootLoader::BeforeAppRuns.run
0
@@ -214,6 +237,32 @@ module Merb
0
       Config
0
     end
0
     
0
+ # Disables the given core components, like a Gem for example.
0
+ #
0
+ # ==== Parameters
0
+ # *args:: One or more symbols of Merb internal components.
0
+ def disable(*components)
0
+ disabled_components.push *components
0
+ end
0
+
0
+ # ==== Parameters
0
+ # Array:: All components that should be disabled.
0
+ def disabled_components=(components)
0
+ disabled_components.replace components
0
+ end
0
+
0
+ # ==== Returns
0
+ # Array:: All components that have been disabled.
0
+ def disabled_components
0
+ Merb::Config[:disabled_components] ||= []
0
+ end
0
+
0
+ # ==== Returns
0
+ # Boolean:: True if all components (or just one) are disabled.
0
+ def disabled?(*components)
0
+ components.all? { |c| disabled_components.include?(c) }
0
+ end
0
+
0
     # ==== Returns
0
     # Array:: All Rakefiles for plugins.
0
     def rakefiles
0
@@ -238,4 +287,4 @@ require 'merb-core/controller/mime'
0
 require 'merb-core/vendor/facets'
0
 
0
 # Set the environment if it hasn't already been set.
0
-Merb.environment ||= Merb::Config[:environment] || ($TESTING ? 'test' : 'development')
0
\ No newline at end of file
0
+Merb.environment ||= ENV['MERB_ENV'] || Merb::Config[:environment] || ($TESTING ? 'test' : 'development')
0
\ No newline at end of file
...
66
67
68
69
 
70
71
72
...
127
128
129
130
 
131
132
133
...
209
210
211
 
212
213
214
...
216
217
218
219
 
220
221
 
222
223
 
224
225
226
 
 
227
228
229
 
230
231
232
...
66
67
68
 
69
70
71
72
...
127
128
129
 
130
131
132
133
...
209
210
211
212
213
214
215
...
217
218
219
 
220
221
 
222
223
 
224
225
 
 
226
227
228
229
 
230
231
232
233
0
@@ -66,7 +66,7 @@ module Merb
0
           Merb.logger.debug!("Loading: #{bootloader}") if ENV['DEBUG']
0
           Object.full_const_get(bootloader).run
0
         end
0
- subclasses = subklasses
0
+ self.subclasses = subklasses
0
       end
0
 
0
       # Set up the default framework
0
@@ -127,7 +127,7 @@ class Merb::BootLoader::Logger < Merb::BootLoader
0
 
0
   # Sets Merb.logger to a new logger created based on the config settings.
0
   def self.run
0
- Merb.logger = Merb::Logger.new(Merb.log_file, Merb::Config[:log_level])
0
+ Merb.logger = Merb::Logger.new(Merb.log_file, Merb::Config[:log_level], Merb::Config[:log_delimiter], Merb::Config[:log_auto_flush])
0
   end
0
 end
0
 
0
@@ -209,6 +209,7 @@ class Merb::BootLoader::Dependencies < Merb::BootLoader
0
   # init.rb file from the Merb configuration directory, and any environment
0
   # files, which register the list of necessary dependencies and any
0
   # after_app_loads hooks.
0
+ #
0
   # Dependencies can hook into the bootloader process itself by using
0
   # before or after insertion methods. Since these are loaded from this
0
   # bootloader (Dependencies), they can only adapt the bootloaders that
0
@@ -216,17 +217,17 @@ class Merb::BootLoader::Dependencies < Merb::BootLoader
0
   
0
   def self.run
0
     if Merb::Config[:init_file]
0
- initfile = Merb::Config[:init_file].chomp(".rb")
0
+ initfile = Merb::Config[:init_file].chomp(".rb") + ".rb"
0
     else
0
- initfile = Merb.dir_for(:config) / "init"
0
+ initfile = Merb.dir_for(:config) / "init.rb"
0
     end
0
- require initfile if File.exists?(initfile + ".rb")
0
+ load initfile if File.exists?(initfile)
0
 
0
- if Merb.environment && File.exist?(Merb.dir_for(:config) / "environments" / (Merb.environment + ".rb"))
0
- require Merb.dir_for(:config) / "environments" / Merb.environment
0
+ if Merb.environment && File.exist?(env_config = (Merb.dir_for(:config) / "environments" / (Merb.environment + ".rb")))
0
+ load env_config
0
     end
0
     
0
- enable_json_gem unless Merb::Config[:disable_json_gem]
0
+ enable_json_gem unless Merb::disabled?(:json)
0
     load_dependencies
0
   end
0
   
...
18
19
20
21
 
 
 
 
22
23
24
...
18
19
20
 
21
22
23
24
25
26
27
0
@@ -18,7 +18,10 @@ module Merb
0
           :environment => "development",
0
           :merb_root => Dir.pwd,
0
           :use_mutex => true,
0
- :session_id_key => "_session_id"
0
+ :session_id_key => "_session_id",
0
+ :log_delimiter => " ~ ",
0
+ :log_auto_flush => false,
0
+ :disabled_components => []
0
         }
0
       end
0
 
...
1
2
 
3
4
5
...
49
50
51
52
 
53
54
55
...
139
140
141
142
 
 
 
143
 
144
145
146
...
1
 
2
3
4
5
...
49
50
51
 
52
53
54
55
...
139
140
141
 
142
143
144
145
146
147
148
149
0
@@ -1,5 +1,5 @@
0
 module Kernel
0
- # Declares the given string as a gem in a queue. Execution is deferred to
0
+ # Loads the given string as a gem. Execution is deferred to
0
   # the Merb::BootLoader::Dependencies.run during bootup.
0
   #
0
   # ==== Parameters
0
@@ -49,7 +49,7 @@ module Kernel
0
     end
0
   end
0
 
0
- # Queues both gem and library dependencies that are passed in as arguments.
0
+ # Loads both gem and library dependencies that are passed in as arguments.
0
   # Execution is deferred to the Merb::BootLoader::Dependencies.run during bootup.
0
   #
0
   # ==== Parameters
0
@@ -139,8 +139,11 @@ module Kernel
0
   # # This will use the DataMapper generator for your ORM
0
   # $ ruby script/generate model MyModel
0
   def use_orm(orm)
0
- raise "Don't call use_orm more than once" unless Merb.generator_scope.delete(:merb_default)
0
+ if !Merb.generator_scope.include?(:merb_default) && !Merb.generator_scope.include?(orm.to_sym)
0
+ raise "Don't call use_orm more than once"
0
+ end
0
     begin
0
+ Merb.generator_scope.delete(:merb_default)
0
       orm_plugin = orm.to_s.match(/^merb_/) ? orm.to_s : "merb_#{orm}"
0
       Merb.generator_scope.unshift(orm.to_sym) unless Merb.generator_scope.include?(orm.to_sym)
0
       Kernel.dependency(orm_plugin)
...
115
116
117
 
 
 
 
 
 
 
 
 
 
118
119
...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
0
@@ -115,4 +115,14 @@ describe Merb::Config do
0
     Merb::Config[:use_mutex].should == true
0
   end
0
   
0
+ it "should take Merb.disable into account" do
0
+ Merb::Config[:disabled_components].should == []
0
+ Merb::Config[:disabled_components] << :foo
0
+ Merb.disable(:bar)
0
+ Merb.disable(:buz, :fux)
0
+ Merb::Config[:disabled_components].should == [:foo, :bar, :buz, :fux]
0
+ Merb.disabled?(:foo).should == true
0
+ Merb.disabled?(:foo, :buz).should == true
0
+ end
0
+
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.