wycats-merb-core 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. data/CHANGELOG +992 -0
  2. data/CONTRIBUTORS +94 -0
  3. data/LICENSE +20 -0
  4. data/PUBLIC_CHANGELOG +142 -0
  5. data/README +21 -0
  6. data/Rakefile +458 -0
  7. data/TODO +0 -0
  8. data/bin/merb +11 -0
  9. data/bin/merb-specs +5 -0
  10. data/lib/merb-core.rb +598 -0
  11. data/lib/merb-core/autoload.rb +31 -0
  12. data/lib/merb-core/bootloader.rb +717 -0
  13. data/lib/merb-core/config.rb +305 -0
  14. data/lib/merb-core/constants.rb +45 -0
  15. data/lib/merb-core/controller/abstract_controller.rb +568 -0
  16. data/lib/merb-core/controller/exceptions.rb +315 -0
  17. data/lib/merb-core/controller/merb_controller.rb +256 -0
  18. data/lib/merb-core/controller/mime.rb +107 -0
  19. data/lib/merb-core/controller/mixins/authentication.rb +123 -0
  20. data/lib/merb-core/controller/mixins/conditional_get.rb +83 -0
  21. data/lib/merb-core/controller/mixins/controller.rb +319 -0
  22. data/lib/merb-core/controller/mixins/render.rb +513 -0
  23. data/lib/merb-core/controller/mixins/responder.rb +469 -0
  24. data/lib/merb-core/controller/template.rb +254 -0
  25. data/lib/merb-core/core_ext.rb +9 -0
  26. data/lib/merb-core/core_ext/hash.rb +7 -0
  27. data/lib/merb-core/core_ext/kernel.rb +340 -0
  28. data/lib/merb-core/dispatch/cookies.rb +130 -0
  29. data/lib/merb-core/dispatch/default_exception/default_exception.rb +93 -0
  30. data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +198 -0
  31. data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +73 -0
  32. data/lib/merb-core/dispatch/default_exception/views/index.html.erb +94 -0
  33. data/lib/merb-core/dispatch/dispatcher.rb +176 -0
  34. data/lib/merb-core/dispatch/request.rb +729 -0
  35. data/lib/merb-core/dispatch/router.rb +151 -0
  36. data/lib/merb-core/dispatch/router/behavior.rb +566 -0
  37. data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
  38. data/lib/merb-core/dispatch/router/resources.rb +191 -0
  39. data/lib/merb-core/dispatch/router/route.rb +511 -0
  40. data/lib/merb-core/dispatch/session.rb +222 -0
  41. data/lib/merb-core/dispatch/session/container.rb +74 -0
  42. data/lib/merb-core/dispatch/session/cookie.rb +173 -0
  43. data/lib/merb-core/dispatch/session/memcached.rb +68 -0
  44. data/lib/merb-core/dispatch/session/memory.rb +99 -0
  45. data/lib/merb-core/dispatch/session/store_container.rb +150 -0
  46. data/lib/merb-core/dispatch/worker.rb +28 -0
  47. data/lib/merb-core/gem_ext/erubis.rb +77 -0
  48. data/lib/merb-core/logger.rb +203 -0
  49. data/lib/merb-core/plugins.rb +67 -0
  50. data/lib/merb-core/rack.rb +25 -0
  51. data/lib/merb-core/rack/adapter.rb +44 -0
  52. data/lib/merb-core/rack/adapter/ebb.rb +25 -0
  53. data/lib/merb-core/rack/adapter/evented_mongrel.rb +26 -0
  54. data/lib/merb-core/rack/adapter/fcgi.rb +17 -0
  55. data/lib/merb-core/rack/adapter/irb.rb +118 -0
  56. data/lib/merb-core/rack/adapter/mongrel.rb +26 -0
  57. data/lib/merb-core/rack/adapter/runner.rb +28 -0
  58. data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
  59. data/lib/merb-core/rack/adapter/thin.rb +39 -0
  60. data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
  61. data/lib/merb-core/rack/adapter/webrick.rb +36 -0
  62. data/lib/merb-core/rack/application.rb +32 -0
  63. data/lib/merb-core/rack/handler/mongrel.rb +97 -0
  64. data/lib/merb-core/rack/middleware.rb +20 -0
  65. data/lib/merb-core/rack/middleware/conditional_get.rb +29 -0
  66. data/lib/merb-core/rack/middleware/content_length.rb +18 -0
  67. data/lib/merb-core/rack/middleware/csrf.rb +73 -0
  68. data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
  69. data/lib/merb-core/rack/middleware/profiler.rb +19 -0
  70. data/lib/merb-core/rack/middleware/static.rb +45 -0
  71. data/lib/merb-core/rack/middleware/tracer.rb +20 -0
  72. data/lib/merb-core/server.rb +284 -0
  73. data/lib/merb-core/tasks/audit.rake +68 -0
  74. data/lib/merb-core/tasks/gem_management.rb +229 -0
  75. data/lib/merb-core/tasks/merb.rb +1 -0
  76. data/lib/merb-core/tasks/merb_rake_helper.rb +80 -0
  77. data/lib/merb-core/tasks/stats.rake +71 -0
  78. data/lib/merb-core/test.rb +11 -0
  79. data/lib/merb-core/test/helpers.rb +9 -0
  80. data/lib/merb-core/test/helpers/controller_helper.rb +8 -0
  81. data/lib/merb-core/test/helpers/multipart_request_helper.rb +175 -0
  82. data/lib/merb-core/test/helpers/request_helper.rb +393 -0
  83. data/lib/merb-core/test/helpers/route_helper.rb +39 -0
  84. data/lib/merb-core/test/helpers/view_helper.rb +121 -0
  85. data/lib/merb-core/test/matchers.rb +9 -0
  86. data/lib/merb-core/test/matchers/controller_matchers.rb +351 -0
  87. data/lib/merb-core/test/matchers/route_matchers.rb +137 -0
  88. data/lib/merb-core/test/matchers/view_matchers.rb +375 -0
  89. data/lib/merb-core/test/run_specs.rb +49 -0
  90. data/lib/merb-core/test/tasks/spectasks.rb +68 -0
  91. data/lib/merb-core/test/test_ext/hpricot.rb +32 -0
  92. data/lib/merb-core/test/test_ext/object.rb +14 -0
  93. data/lib/merb-core/test/test_ext/string.rb +14 -0
  94. data/lib/merb-core/vendor/facets.rb +2 -0
  95. data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
  96. data/lib/merb-core/vendor/facets/inflect.rb +342 -0
  97. data/lib/merb-core/version.rb +3 -0
  98. metadata +253 -0
data/TODO ADDED
File without changes
data/bin/merb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'merb-core'
5
+
6
+ ARGV.push '-H' if ARGV[0] && ARGV[0] =~ /^[^-]/
7
+ unless %w[-a --adapter -i --irb-console -r --script-runner].any? { |o| ARGV.index(o) }
8
+ ARGV.push *%w[-a mongrel]
9
+ end
10
+
11
+ Merb.start
data/bin/merb-specs ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__),"..","lib","merb-core","test","run_specs")
4
+
5
+ run_specs ARGV
data/lib/merb-core.rb ADDED
@@ -0,0 +1,598 @@
1
+ #---
2
+ # require 'merb' must happen after Merb::Config is instantiated
3
+ require 'rubygems'
4
+
5
+ # Add the local gems dir if found within the app root; any dependencies loaded
6
+ # hereafter will try to load from the local gems before loading system gems.
7
+ root_key = %w[-m --merb-root].detect { |o| ARGV.index(o) }
8
+ root = ARGV[ARGV.index(root_key) + 1] if root_key
9
+ root = root.to_a.empty? ? Dir.getwd : root
10
+ if File.directory?(gems_dir = File.join(root, 'gems')) && !$BUNDLE
11
+ $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(gems_dir)
12
+ # Warn if local merb-core is available but not loaded.
13
+ if File.expand_path($0).index(root) != 0 &&
14
+ (local_mc = Dir[File.join(gems_dir, 'specifications', 'merb-core-*.gemspec')].last)
15
+ puts "Warning: please use bin/#{File.basename($0)} to load #{File.basename(local_mc, '.gemspec')} from ./gems"
16
+ end
17
+ end
18
+
19
+ require 'thread'
20
+ require 'set'
21
+ require 'fileutils'
22
+ require 'socket'
23
+ require 'pathname'
24
+ require "extlib"
25
+
26
+ __DIR__ = File.dirname(__FILE__)
27
+
28
+ $LOAD_PATH.unshift __DIR__ unless
29
+ $LOAD_PATH.include?(__DIR__) ||
30
+ $LOAD_PATH.include?(File.expand_path(__DIR__))
31
+
32
+ require 'merb-core' / 'vendor' / 'facets'
33
+
34
+ module Merb
35
+ # Create stub module for global controller helpers.
36
+ module GlobalHelpers; end
37
+
38
+ class << self
39
+
40
+ # Merge environment settings
41
+ # Can allow you to have a "localdev" that runs like your "development"
42
+ # OR
43
+ # A "staging" environment that runs like your "production"
44
+ #
45
+ # ==== Examples
46
+ # From any environment config file (ie, development.rb, custom.rb, localdev.rb, etc)
47
+ # staging.rb:
48
+ # Merb.merge_env "production" #We want to use all the settings production uses
49
+ # Merb::Config.use { |c|
50
+ # c[:log_level] = "debug" #except we want debug log level
51
+ # c[:exception_details] = true #and we want to see exception details
52
+ # }
53
+ #
54
+ # ==== Parameters
55
+ # env<~String>:: Environment to run like
56
+ # use_db<~Boolean>:: Should Merb use the merged environments DB connection
57
+ # Defaults to +false+
58
+ def merge_env(env,use_db=false)
59
+ if Merb.environment_info.nil?
60
+ Merb.environment_info = {
61
+ :real_env => Merb.environment,
62
+ :merged_envs => [],
63
+ :db_env => Merb.environment
64
+ }
65
+ end
66
+
67
+ #Only load if it hasn't been loaded
68
+ unless Merb.environment_info[:merged_envs].member? env
69
+ Merb.environment_info[:merged_envs] << env
70
+
71
+ env_file = Merb.dir_for(:config) / "environments" / ("#{env}.rb")
72
+ if File.exists?(env_file)
73
+ load(env_file)
74
+ else
75
+ Merb.logger.warn! "Environment file does not exist! #{env_file}"
76
+ end
77
+
78
+ end
79
+
80
+ # Mark specific environment to load when ORM loads,
81
+ # if multiple environments are loaded, the last one
82
+ # with use_db as TRUE will be loaded
83
+ if use_db
84
+ Merb.environment_info[:db_env] = env
85
+ end
86
+ end
87
+
88
+
89
+ # Startup Merb by setting up the Config and starting the server.
90
+ # This is where Merb application environment and root path are set.
91
+ #
92
+ # ==== Parameters
93
+ # argv<String, Hash>::
94
+ # The config arguments to start Merb with. Defaults to +ARGV+.
95
+ def start(argv=ARGV)
96
+ if Hash === argv
97
+ Merb::Config.setup(argv)
98
+ else
99
+ Merb::Config.parse_args(argv)
100
+ end
101
+ Merb.environment = Merb::Config[:environment]
102
+ Merb.root = Merb::Config[:merb_root]
103
+ case Merb::Config[:action]
104
+ when :kill
105
+ Merb::Server.kill(Merb::Config[:port], 1)
106
+ when :kill_9
107
+ Merb::Server.kill(Merb::Config[:port], 9)
108
+ else
109
+ Merb::Server.start(Merb::Config[:port], Merb::Config[:cluster])
110
+ end
111
+ end
112
+
113
+ # Start the Merb environment, but only if it hasn't been loaded yet.
114
+ #
115
+ # ==== Parameters
116
+ # argv<String, Hash>::
117
+ # The config arguments to start Merb with. Defaults to +ARGV+.
118
+ def start_environment(argv=ARGV)
119
+ unless (@started ||= false)
120
+ start(argv)
121
+ @started = true
122
+ end
123
+ end
124
+
125
+ # Restart the Merb environment explicitly.
126
+ #
127
+ # ==== Parameters
128
+ # argv<String, Hash>::
129
+ # The config arguments to restart Merb with. Defaults to +Merb::Config+.
130
+ def restart_environment(argv={})
131
+ @started = false
132
+ start_environment(Merb::Config.to_hash.merge(argv))
133
+ end
134
+
135
+ attr_accessor :environment, :load_paths, :adapter, :environment_info, :started
136
+
137
+ alias :env :environment
138
+ alias :started? :started
139
+
140
+ Merb.load_paths = Dictionary.new { [Merb.root] } unless Merb.load_paths.is_a?(Dictionary)
141
+
142
+ # This is the core mechanism for setting up your application layout.
143
+ # There are three application layouts in Merb:
144
+ #
145
+ # Regular app/:type layout of Ruby on Rails fame:
146
+ #
147
+ # app/models for models
148
+ # app/mailers for mailers (special type of controllers)
149
+ # app/parts for parts, Merb components
150
+ # app/views for templates
151
+ # app/controllers for controller
152
+ # lib for libraries
153
+ #
154
+ # Flat application layout:
155
+ #
156
+ # application.rb for models, controllers, mailers, etc
157
+ # config/init.rb for initialization and router configuration
158
+ # config/framework.rb for framework and dependencies configuration
159
+ # views for views
160
+ #
161
+ # and Camping-style "very flat" application layout, where the whole Merb
162
+ # application and configs fit into a single file.
163
+ #
164
+ # ==== Notes
165
+ # Autoloading for lib uses empty glob by default. If you
166
+ # want to have your libraries under lib use autoload, add
167
+ # the following to Merb init file:
168
+ #
169
+ # Merb.push_path(:lib, Merb.root / "lib", "**/*.rb") # glob set explicity.
170
+ #
171
+ # Then lib/magicwand/lib/magicwand.rb with MagicWand module will
172
+ # be autoloaded when you first access that constant.
173
+ #
174
+ # ==== Examples
175
+ # This method gives you a way to build up your own application
176
+ # structure, for instance, to reflect the structure Rails
177
+ # uses to simplify transition of legacy application, you can
178
+ # set it up like this:
179
+ #
180
+ # Merb.push_path(:model, Merb.root / "app" / "models", "**/*.rb")
181
+ # Merb.push_path(:mailer, Merb.root / "app" / "models", "**/*.rb")
182
+ # Merb.push_path(:controller, Merb.root / "app" / "controllers", "**/*.rb")
183
+ # Merb.push_path(:view, Merb.root / "app" / "views", "**/*.rb")
184
+ #
185
+ # ==== Parameters
186
+ # type<Symbol>:: The type of path being registered (i.e. :view)
187
+ # path<String>:: The full path
188
+ # file_glob<String>::
189
+ # A glob that will be used to autoload files under the path. Defaults to
190
+ # "**/*.rb".
191
+ def push_path(type, path, file_glob = "**/*.rb")
192
+ enforce!(type => Symbol)
193
+ load_paths[type] = [path, file_glob]
194
+ end
195
+
196
+ # Removes given types of application components
197
+ # from load path Merb uses for autoloading.
198
+ #
199
+ # ==== Parameters
200
+ # *args<Array(Symbol)>::
201
+ # components names, for instance, :views, :models
202
+ #
203
+ # ==== Examples
204
+ # Using this combined with Merb::GlobalHelpers.push_path
205
+ # you can make your Merb application use legacy Rails
206
+ # application components.
207
+ #
208
+ # Merb.root = "path/to/legacy/app/root"
209
+ # Merb.remove_paths(:mailer)
210
+ # Merb.push_path(:mailer, Merb.root / "app" / "models", "**/*.rb")
211
+ #
212
+ # Will make Merb use app/models for mailers just like Ruby on Rails does.
213
+ def remove_paths(*args)
214
+ args.each {|arg| load_paths.delete(arg)}
215
+ end
216
+
217
+ # ==== Parameters
218
+ # type<Symbol>:: The type of path to retrieve directory for, e.g. :view.
219
+ #
220
+ # ==== Returns
221
+ # String:: The directory for the requested type.
222
+ def dir_for(type)
223
+ Merb.load_paths[type].first
224
+ end
225
+
226
+ # ==== Parameters
227
+ # type<Symbol>:: The type of path to retrieve glob for, e.g. :view.
228
+ #
229
+ # ===== Returns
230
+ # String:: The pattern with which to match files within the type directory.
231
+ def glob_for(type)
232
+ Merb.load_paths[type][1]
233
+ end
234
+
235
+ # ==== Returns
236
+ # String:: The Merb root path.
237
+ def root
238
+ @root || Merb::Config[:merb_root] || File.expand_path(Dir.pwd)
239
+ end
240
+
241
+ # ==== Parameters
242
+ # value<String>:: Path to the root directory.
243
+ def root=(value)
244
+ @root = value
245
+ end
246
+
247
+ # ==== Parameters
248
+ # *path::
249
+ # The relative path (or list of path components) to a directory under the
250
+ # root of the application.
251
+ #
252
+ # ==== Returns
253
+ # String:: The full path including the root.
254
+ #
255
+ # ==== Examples
256
+ # Merb.root = "/home/merb/app"
257
+ # Merb.path("images") # => "/home/merb/app/images"
258
+ # Merb.path("views", "admin") # => "/home/merb/app/views/admin"
259
+ #---
260
+ # @public
261
+ def root_path(*path)
262
+ File.join(root, *path)
263
+ end
264
+
265
+ # Logger settings
266
+ attr_accessor :logger
267
+
268
+ # ==== Returns
269
+ # String::
270
+ # The path to the log file. If this Merb instance is running as a daemon
271
+ # this will return +STDOUT+.
272
+ def log_file
273
+ if Merb::Config[:log_file]
274
+ Merb::Config[:log_file]
275
+ elsif Merb.testing?
276
+ log_path / "merb_test.log"
277
+ elsif !(Merb::Config[:daemonize] || Merb::Config[:cluster])
278
+ STDOUT
279
+ else
280
+ log_path / "merb.#{Merb::Config[:port]}.log"
281
+ end
282
+ end
283
+
284
+ # ==== Returns
285
+ # String:: Path to directory that contains the log file.
286
+ def log_path
287
+ case Merb::Config[:log_file]
288
+ when String then File.dirname(Merb::Config[:log_file])
289
+ else Merb.root_path("log")
290
+ end
291
+ end
292
+
293
+ # ==== Returns
294
+ # String:: The path of root directory of the Merb framework.
295
+ def framework_root
296
+ @framework_root ||= File.dirname(__FILE__)
297
+ end
298
+
299
+ # ==== Returns
300
+ # RegExp::
301
+ # Regular expression against which deferred actions
302
+ # are matched by Rack application handler.
303
+ #
304
+ # ==== Notes
305
+ # Concatenates :deferred_actions configuration option
306
+ # values.
307
+ def deferred_actions
308
+ @deferred ||= begin
309
+ if Merb::Config[:deferred_actions].empty?
310
+ /^\0$/
311
+ else
312
+ /#{Merb::Config[:deferred_actions].join("|")}/
313
+ end
314
+ end
315
+ end
316
+
317
+ # Allows flat apps by setting no default framework directories and yielding
318
+ # a Merb::Router instance. This is optional since the router will
319
+ # automatically configure the app with default routes.
320
+ #
321
+ # ==== Block parameters
322
+ # r<Merb::Router::Behavior>::
323
+ # The root behavior upon which new routes can be added.
324
+ def flat!(framework = {})
325
+ default = {
326
+ :framework => { :public => [Merb.root / "public", nil] },
327
+ :session_store => 'none',
328
+ :exception_details => true
329
+ }
330
+
331
+ Merb::Config[:framework] = default.merge(framework)
332
+
333
+ Merb::Router.prepare do |r|
334
+ yield(r) if block_given?
335
+ r.default_routes
336
+ end
337
+ end
338
+
339
+ # Set up default variables under Merb
340
+ attr_accessor :klass_hashes, :orm, :test_framework, :template_engine
341
+
342
+ # Returns the default ORM for this application. For instance, :datamapper.
343
+ #
344
+ # ==== Returns
345
+ # <Symbol>:: default ORM.
346
+ def orm
347
+ @orm ||= :none
348
+ end
349
+
350
+ # @deprecated
351
+ def orm_generator_scope
352
+ Merb.logger.warn!("WARNING: Merb.orm_generator_scope is deprecated")
353
+ return :merb_default if Merb.orm == :none
354
+ Merb.orm
355
+ end
356
+
357
+ # Returns the default test framework for this application. For instance :rspec.
358
+ #
359
+ # ==== Returns
360
+ # <Symbol>:: default test framework.
361
+ def test_framework
362
+ @test_framework ||= :rspec
363
+ end
364
+
365
+ # @deprecated
366
+ def test_framework_generator_scope
367
+ Merb.logger.warn!("WARNING: Merb.test_framework_generator_scope is deprecated")
368
+ Merb.test_framework
369
+ end
370
+
371
+ # Returns the default template engine for this application. For instance :haml.
372
+ #
373
+ # ==== Returns
374
+ # <Symbol>:: default template engine.
375
+ def template_engine
376
+ @template_engine ||= :erb
377
+ end
378
+
379
+ Merb.klass_hashes = []
380
+
381
+ # ==== Returns
382
+ # Boolean:: True if Merb is running as an application with bundled gems.
383
+ #
384
+ # ==== Notes
385
+ # Bundling required gems makes your application independent from the
386
+ # environment it runs in. This is a good practice to freeze application
387
+ # framework and gems it uses and very useful when application is run in
388
+ # some sort of sandbox, for instance, shared hosting with preconfigured gems.
389
+ def bundled?
390
+ $BUNDLE || ENV.key?("BUNDLE")
391
+ end
392
+
393
+ # Load configuration and assign logger.
394
+ #
395
+ # ==== Parameters
396
+ # options<Hash>:: Options to pass on to the Merb config.
397
+ #
398
+ # ==== Options
399
+ # :host<String>:: host to bind to,
400
+ # default is 0.0.0.0.
401
+ #
402
+ # :port<Fixnum>:: port to run Merb application on,
403
+ # default is 4000.
404
+ #
405
+ # :adapter<String>:: name of Rack adapter to use,
406
+ # default is "runner"
407
+ #
408
+ # :rackup<String>:: name of Rack init file to use,
409
+ # default is "rack.rb"
410
+ #
411
+ # :reload_classes<Boolean>:: whether Merb should reload
412
+ # classes on each request,
413
+ # default is true
414
+ #
415
+ # :environment<String>:: name of environment to use,
416
+ # default is development
417
+ #
418
+ # :merb_root<String>:: Merb application root,
419
+ # default is Dir.pwd
420
+ #
421
+ # :use_mutex<Boolean>:: turns action dispatch synchronization
422
+ # on or off, default is on (true)
423
+ #
424
+ # :log_delimiter<String>:: what Merb logger uses as delimiter
425
+ # between message sections, default is " ~ "
426
+ #
427
+ # :log_auto_flush<Boolean>:: whether the log should automatically
428
+ # flush after new messages are
429
+ # added, defaults to true.
430
+ #
431
+ # :log_file<IO>:: IO for logger. Default is STDOUT.
432
+ #
433
+ # :log_level<Symbol>:: logger level, default is :warn
434
+ #
435
+ # :disabled_components<Array[Symbol]>::
436
+ # array of disabled component names,
437
+ # for instance, to disable json gem,
438
+ # specify :json. Default is empty array.
439
+ #
440
+ # :deferred_actions<Array(Symbol, String)]>::
441
+ # names of actions that should be deferred
442
+ # no matter what controller they belong to.
443
+ # Default is empty array.
444
+ #
445
+ # Some of these options come from command line on Merb
446
+ # application start, some of them are set in Merb init file
447
+ # or environment-specific.
448
+ def load_config(options = {})
449
+ Merb::Config.setup({ :log_file => STDOUT, :log_level => :warn, :log_auto_flush => true }.merge(options))
450
+ Merb::BootLoader::Logger.run
451
+ end
452
+
453
+ # Load all basic dependencies (selected BootLoaders only).
454
+ # This sets up Merb framework component paths
455
+ # (directories for models, controllers, etc) using
456
+ # framework.rb or default layout, loads init file
457
+ # and dependencies specified in it and runs before_app_loads hooks.
458
+ #
459
+ # ==== Parameters
460
+ # options<Hash>:: Options to pass on to the Merb config.
461
+ def load_dependencies(options = {})
462
+ load_config(options)
463
+ Merb::BootLoader::BuildFramework.run
464
+ Merb::BootLoader::Dependencies.run
465
+ Merb::BootLoader::BeforeAppLoads.run
466
+ end
467
+
468
+ # Reload application and framework classes.
469
+ # See Merb::BootLoader::ReloadClasses for details.
470
+ def reload
471
+ Merb::BootLoader::ReloadClasses.reload
472
+ end
473
+
474
+ # ==== Returns
475
+ # Boolean:: True if Merb environment is testing for instance,
476
+ # Merb is running with RSpec, Test::Unit of other testing facility.
477
+ def testing?
478
+ $TESTING || Merb::Config[:testing]
479
+ end
480
+
481
+ # Ask the question about which environment you're in.
482
+ # ==== Parameters
483
+ # env<Symbol, String>:: Name of the environment to query
484
+ #
485
+ # ==== Examples
486
+ # Merb.env #=> production
487
+ # Merb.env?(:production) #=> true
488
+ # Merb.env?(:development) #=> false
489
+ def env?(env)
490
+ Merb.env == env.to_s
491
+ end
492
+
493
+ # If block was given configures using the block.
494
+ #
495
+ # ==== Parameters
496
+ # &block:: Configuration parameter block, see example below.
497
+ #
498
+ # ==== Returns
499
+ # Hash:: The current configuration.
500
+ #
501
+ # ==== Notes
502
+ # See Merb::GlobalHelpers.load_config for configuration
503
+ # options list.
504
+ #
505
+ # ==== Examples
506
+ # Merb.config do
507
+ # beer "good"
508
+ # hashish :foo => "bar"
509
+ # environment "development"
510
+ # log_level "debug"
511
+ # use_mutex false
512
+ # exception_details true
513
+ # reload_classes true
514
+ # reload_time 0.5
515
+ # end
516
+ def config(&block)
517
+ Merb::Config.configure(&block) if block_given?
518
+ Config
519
+ end
520
+
521
+ # Disables the given core components, like a Gem for example.
522
+ #
523
+ # ==== Parameters
524
+ # *args:: One or more symbols of Merb internal components.
525
+ def disable(*components)
526
+ disabled_components.push(*components)
527
+ end
528
+
529
+ # ==== Parameters
530
+ # Array:: All components that should be disabled.
531
+ def disabled_components=(components)
532
+ disabled_components.replace components
533
+ end
534
+
535
+ # ==== Returns
536
+ # Array:: All components that have been disabled.
537
+ def disabled_components
538
+ Merb::Config[:disabled_components] ||= []
539
+ end
540
+
541
+ # ==== Returns
542
+ # Boolean:: True if all components (or just one) are disabled.
543
+ def disabled?(*components)
544
+ components.all? { |c| disabled_components.include?(c) }
545
+ end
546
+
547
+ # ==== Returns
548
+ # Array(String):: Paths Rakefiles are loaded from.
549
+ #
550
+ # ==== Notes
551
+ # Recommended way to find out what paths Rakefiles
552
+ # are loaded from.
553
+ def rakefiles
554
+ @rakefiles ||= ['merb-core/test/tasks/spectasks']
555
+ end
556
+
557
+ # === Returns
558
+ # Array(String):: Paths generators are loaded from
559
+ #
560
+ # === Notes
561
+ # Recommended way to find out what paths generators
562
+ # are loaded from.
563
+ def generators
564
+ @generators ||= []
565
+ end
566
+
567
+ # ==== Parameters
568
+ # *rakefiles:: Rakefile pathss to add to the list of Rakefiles.
569
+ #
570
+ # ==== Notes
571
+ # Recommended way to add Rakefiles load path for plugins authors.
572
+ def add_rakefiles(*rakefiles)
573
+ @rakefiles ||= ['merb-core/test/tasks/spectasks']
574
+ @rakefiles += rakefiles
575
+ end
576
+
577
+ # ==== Parameters
578
+ # *generators:: Generator paths to add to the list of generators.
579
+ #
580
+ # ==== Notes
581
+ # Recommended way to add Generator load paths for plugin authors.
582
+ def add_generators(*generators)
583
+ @generators ||= []
584
+ @generators += generators
585
+ end
586
+
587
+ end
588
+ end
589
+
590
+ require 'merb-core/autoload'
591
+ require 'merb-core/server'
592
+ require 'merb-core/gem_ext/erubis'
593
+ require 'merb-core/logger'
594
+ require 'merb-core/version'
595
+ require 'merb-core/controller/mime'
596
+
597
+ # Set the environment if it hasn't already been set.
598
+ Merb.environment ||= ENV['MERB_ENV'] || Merb::Config[:environment] || (Merb.testing? ? 'test' : 'development')