merb-core 0.9.8 → 0.9.9
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.
- data/CONTRIBUTORS +33 -0
- data/README +7 -3
- data/Rakefile +3 -3
- data/lib/merb-core.rb +165 -94
- data/lib/merb-core/bootloader.rb +469 -100
- data/lib/merb-core/config.rb +79 -3
- data/lib/merb-core/constants.rb +24 -2
- data/lib/merb-core/controller/abstract_controller.rb +172 -67
- data/lib/merb-core/controller/exceptions.rb +50 -6
- data/lib/merb-core/controller/merb_controller.rb +215 -108
- data/lib/merb-core/controller/mime.rb +36 -12
- data/lib/merb-core/controller/mixins/authentication.rb +52 -7
- data/lib/merb-core/controller/mixins/conditional_get.rb +14 -0
- data/lib/merb-core/controller/mixins/controller.rb +90 -58
- data/lib/merb-core/controller/mixins/render.rb +34 -10
- data/lib/merb-core/controller/mixins/responder.rb +40 -16
- data/lib/merb-core/controller/template.rb +37 -16
- data/lib/merb-core/core_ext/hash.rb +9 -0
- data/lib/merb-core/core_ext/kernel.rb +92 -41
- data/lib/merb-core/dispatch/dispatcher.rb +29 -45
- data/lib/merb-core/dispatch/request.rb +186 -82
- data/lib/merb-core/dispatch/router.rb +141 -53
- data/lib/merb-core/dispatch/router/behavior.rb +296 -139
- data/lib/merb-core/dispatch/router/resources.rb +51 -19
- data/lib/merb-core/dispatch/router/route.rb +76 -23
- data/lib/merb-core/dispatch/session.rb +80 -36
- data/lib/merb-core/dispatch/session/container.rb +31 -15
- data/lib/merb-core/dispatch/session/cookie.rb +51 -22
- data/lib/merb-core/dispatch/session/memcached.rb +10 -6
- data/lib/merb-core/dispatch/session/memory.rb +17 -5
- data/lib/merb-core/dispatch/session/store_container.rb +21 -9
- data/lib/merb-core/dispatch/worker.rb +16 -2
- data/lib/merb-core/gem_ext/erubis.rb +4 -0
- data/lib/merb-core/plugins.rb +13 -0
- data/lib/merb-core/rack.rb +1 -0
- data/lib/merb-core/rack/adapter.rb +1 -0
- data/lib/merb-core/rack/adapter/abstract.rb +95 -17
- data/lib/merb-core/rack/adapter/irb.rb +50 -5
- data/lib/merb-core/rack/application.rb +27 -5
- data/lib/merb-core/rack/handler/mongrel.rb +6 -6
- data/lib/merb-core/rack/helpers.rb +33 -0
- data/lib/merb-core/rack/middleware/conditional_get.rb +1 -1
- data/lib/merb-core/rack/middleware/path_prefix.rb +3 -3
- data/lib/merb-core/rack/middleware/static.rb +11 -7
- data/lib/merb-core/server.rb +134 -69
- data/lib/merb-core/tasks/gem_management.rb +153 -80
- data/lib/merb-core/tasks/merb_rake_helper.rb +12 -4
- data/lib/merb-core/tasks/stats.rake +1 -1
- data/lib/merb-core/test/helpers/mock_request_helper.rb +29 -22
- data/lib/merb-core/test/helpers/request_helper.rb +1 -1
- data/lib/merb-core/test/helpers/route_helper.rb +50 -4
- data/lib/merb-core/test/matchers/request_matchers.rb +2 -36
- data/lib/merb-core/test/matchers/view_matchers.rb +32 -22
- data/lib/merb-core/test/run_specs.rb +6 -5
- data/lib/merb-core/test/test_ext/rspec.rb +6 -19
- data/lib/merb-core/version.rb +1 -1
- metadata +5 -4
data/CONTRIBUTORS
CHANGED
@@ -4,49 +4,70 @@ Aaron Wheeler
|
|
4
4
|
Abhay Kumar
|
5
5
|
Adam Jacob
|
6
6
|
Andy C
|
7
|
+
Andy Delcambre
|
7
8
|
Antti Tarvainen
|
8
9
|
Ben Burkert
|
9
10
|
Ben Chiu
|
10
11
|
Ben Griffiths
|
11
12
|
Bradly Feeley
|
12
13
|
Brandon Dimcheff
|
14
|
+
Brandon Mitchell
|
13
15
|
Brian Mitchell
|
14
16
|
Bryan Ray
|
15
17
|
Carl Lerche
|
18
|
+
Carlos Villela
|
16
19
|
Charles Jolley
|
20
|
+
Cheah Chu Yeow
|
21
|
+
Chris Van Pelt
|
17
22
|
Coda Hale
|
18
23
|
Cory ODaniel
|
24
|
+
Cristi Balan
|
25
|
+
Damian Terentiev
|
19
26
|
Daniel Neighman
|
20
27
|
Daniel Schierbeck
|
21
28
|
Daniel Siemssen
|
22
29
|
David James
|
30
|
+
Debian User
|
23
31
|
Diego Scataglini
|
24
32
|
Dirkjan Bussink
|
33
|
+
Dr Nic
|
25
34
|
Drew Colthorp
|
35
|
+
Duane Johnson
|
26
36
|
Dudley Flanders
|
37
|
+
Eric D. White
|
27
38
|
Ezra Zygmuntowicz
|
28
39
|
Fabien Franzen
|
29
40
|
Flea
|
30
41
|
Foy Savas
|
31
42
|
Gabe
|
32
43
|
Geoffrey Grosenbach
|
44
|
+
Gert Goet
|
45
|
+
Glenn Rempe
|
33
46
|
Goh Toh Chye
|
34
47
|
Grant Hollingworth
|
35
48
|
Guillaume Maury
|
36
49
|
Hampton Catlin
|
37
50
|
Ho-Sheng Hsiao
|
38
51
|
Jack Dempsey
|
52
|
+
Jakub Šťastný aka Botanicus
|
39
53
|
James Herdman
|
40
54
|
James Whiteman
|
41
55
|
Janne Asmala
|
56
|
+
Jarkko Laine
|
42
57
|
Jaroslaw Zabiello
|
58
|
+
Jed Hurt
|
43
59
|
Jonas Nicklas
|
60
|
+
Jonathan Stott
|
44
61
|
Jonathan Younger
|
45
62
|
Josh Nichols
|
63
|
+
Justin Pease
|
64
|
+
Justin S. Leitgeb
|
46
65
|
Kyle Drake
|
66
|
+
Lachie Cox
|
47
67
|
Lance Carlson
|
48
68
|
Loren Segal
|
49
69
|
Lori Holden
|
70
|
+
Maciej Piechotka
|
50
71
|
Martin Grund
|
51
72
|
Mason Browne
|
52
73
|
Matt Aimonetti
|
@@ -65,16 +86,25 @@ Michael S. Klishin
|
|
65
86
|
Michael Sheakoski
|
66
87
|
Mirko Froehlich
|
67
88
|
Nathan Weizenbaum
|
89
|
+
Nick Dufresne
|
90
|
+
Nicos Gollan
|
91
|
+
Nikos Dimitrakopoulos
|
68
92
|
Oliver Jakubiec
|
69
93
|
Paul Barry
|
70
94
|
Paul Boone
|
71
95
|
Paul Carey
|
72
96
|
Ray Morgan
|
73
97
|
Rich Cavanaugh
|
98
|
+
Richard Grundy
|
99
|
+
Rob Ares
|
100
|
+
Rob Kaufman
|
74
101
|
Ross Lawley
|
102
|
+
Sergey Molodtsoff
|
103
|
+
Seth Thomas Rasmussen
|
75
104
|
Shalon Wood
|
76
105
|
Shay Arnett
|
77
106
|
Simon Jefford
|
107
|
+
Simon Rozet
|
78
108
|
Sindre Aarsaether
|
79
109
|
StarTrader
|
80
110
|
Steve Tooke
|
@@ -90,7 +120,10 @@ William Smith
|
|
90
120
|
Wilson Bilkovich
|
91
121
|
Yehuda Katz
|
92
122
|
Zach Holt
|
123
|
+
atmos
|
124
|
+
booss
|
93
125
|
brainopia
|
126
|
+
gert@pacificstarfish.net
|
94
127
|
jonas
|
95
128
|
jonuts
|
96
129
|
macournoyer
|
data/README
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
merb-core
|
1
|
+
merb-core
|
2
2
|
|
3
|
-
|
3
|
+
A new branch of Merb (sometimes referred to as merb-next) which aims to provide
|
4
|
+
a stable, stripped down API for the Merb 1.0 release.
|
5
|
+
|
6
|
+
This branch was based off the 0.5 release series with *significant* rewrites.
|
4
7
|
|
5
8
|
Goals of this release:
|
6
9
|
|
@@ -13,8 +16,9 @@ Goals of this release:
|
|
13
16
|
* Implement a new render API
|
14
17
|
* Build more extensions to regain selected features when needed
|
15
18
|
|
16
|
-
To familiarize yourself with how a merb-core application might look,
|
19
|
+
To familiarize yourself with how a merb-core application might look,
|
17
20
|
use merb-gen (from merb-more) to generate a few apps:
|
21
|
+
|
18
22
|
$ merb-gen app myapp # a "normal" merb app
|
19
23
|
$ merb-gen app myapp --flat # a flattened app
|
20
24
|
$ merb-gen app myapp --very-flat # a single-file app
|
data/Rakefile
CHANGED
@@ -57,7 +57,7 @@ spec = Gem::Specification.new do |s|
|
|
57
57
|
s.extra_rdoc_files = %w( README LICENSE TODO )
|
58
58
|
|
59
59
|
# Dependencies
|
60
|
-
s.add_dependency "extlib", ">= 0.9.
|
60
|
+
s.add_dependency "extlib", ">= 0.9.8"
|
61
61
|
s.add_dependency "erubis"
|
62
62
|
s.add_dependency "rake"
|
63
63
|
s.add_dependency "json_pure"
|
@@ -65,7 +65,7 @@ spec = Gem::Specification.new do |s|
|
|
65
65
|
s.add_dependency "rack"
|
66
66
|
s.add_dependency "mime-types"
|
67
67
|
s.add_dependency "hpricot"
|
68
|
-
s.add_dependency "thor", ">= 0.9.
|
68
|
+
s.add_dependency "thor", ">= 0.9.7"
|
69
69
|
# this escalates to "regular" dependencies, comment it out
|
70
70
|
# for now. RubyGems need some love.
|
71
71
|
#s.add_development_dependency "libxml-ruby"
|
@@ -336,7 +336,7 @@ def contributors(since_release = nil)
|
|
336
336
|
git_log(since_release).split("\n").uniq.sort
|
337
337
|
end
|
338
338
|
|
339
|
-
PREVIOUS_RELEASE = '0.9.
|
339
|
+
PREVIOUS_RELEASE = '0.9.8'
|
340
340
|
namespace :history do
|
341
341
|
namespace :update do
|
342
342
|
desc "updates contributors list"
|
data/lib/merb-core.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
-
#---
|
2
1
|
# require 'merb' must happen after Merb::Config is instantiated
|
3
|
-
require
|
2
|
+
require "rubygems"
|
4
3
|
|
5
4
|
# Add the local gems dir if found within the app root; any dependencies loaded
|
6
5
|
# hereafter will try to load from the local gems before loading system gems.
|
7
6
|
root_key = %w[-m --merb-root].detect { |o| ARGV.index(o) }
|
8
7
|
root = ARGV[ARGV.index(root_key) + 1] if root_key
|
9
8
|
root = root.to_a.empty? ? Dir.getwd : root
|
10
|
-
if File.directory?(gems_dir = File.join(root,
|
9
|
+
if File.directory?(gems_dir = File.join(root, "gems")) && !$BUNDLE
|
11
10
|
$BUNDLE = true; Gem.clear_paths; Gem.path.unshift(gems_dir)
|
12
11
|
# Warn if local merb-core is available but not loaded.
|
13
12
|
if File.expand_path($0).index(root) != 0 &&
|
14
|
-
(local_mc = Dir[File.join(gems_dir,
|
15
|
-
puts "Warning: please use bin/#{File.basename($0)} to load #{File.basename(local_mc,
|
13
|
+
(local_mc = Dir[File.join(gems_dir, "specifications", "merb-core-*.gemspec")].last)
|
14
|
+
puts "Warning: please use bin/#{File.basename($0)} to load #{File.basename(local_mc, ".gemspec")} from ./gems"
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
18
|
+
require "thread"
|
19
|
+
require "set"
|
20
|
+
require "fileutils"
|
21
|
+
require "socket"
|
22
|
+
require "pathname"
|
24
23
|
require "extlib"
|
25
24
|
require "extlib/dictionary"
|
26
25
|
|
@@ -30,31 +29,47 @@ $LOAD_PATH.unshift __DIR__ unless
|
|
30
29
|
$LOAD_PATH.include?(__DIR__) ||
|
31
30
|
$LOAD_PATH.include?(File.expand_path(__DIR__))
|
32
31
|
|
32
|
+
# Some dependencies tend to require&rescue for optionally required files;
|
33
|
+
# doing so will load the full rubygems, even though it was just optional.
|
34
|
+
$MINIGEMS_SKIPPABLE = ['encoding/character/utf-8']
|
35
|
+
|
33
36
|
module Merb
|
34
37
|
# Create stub module for global controller helpers.
|
35
38
|
module GlobalHelpers; end
|
36
39
|
|
37
40
|
class << self
|
38
|
-
|
41
|
+
attr_reader :exiting
|
42
|
+
|
43
|
+
def exiting=(bool)
|
44
|
+
Extlib.exiting = bool
|
45
|
+
if bool && Extlib.const_defined?("Pooling") && Extlib::Pooling.scavenger
|
46
|
+
Extlib::Pooling.scavenger.wakeup
|
47
|
+
end
|
48
|
+
@exiting = bool
|
49
|
+
end
|
39
50
|
|
40
51
|
# Merge environment settings
|
41
|
-
#
|
52
|
+
#
|
53
|
+
# This can allow you to have a "localdev" environment that runs like your "development".
|
42
54
|
# OR
|
43
|
-
# A "staging" environment that runs
|
55
|
+
# A "staging" environment that runs identical to your "production" environment.
|
44
56
|
#
|
45
57
|
# ==== Examples
|
46
|
-
# From any environment config file (ie, development.rb, custom.rb, localdev.rb, etc)
|
58
|
+
# From any environment config file (ie, development.rb, custom.rb, localdev.rb, etc).
|
47
59
|
# staging.rb:
|
48
|
-
# Merb.merge_env "production" #We want to use all the settings production uses
|
49
|
-
# Merb::Config.use
|
50
|
-
# c[:log_level] = "debug" #except we want debug log level
|
51
|
-
# c[:
|
52
|
-
#
|
60
|
+
# Merb.merge_env "production" # We want to use all the settings production uses
|
61
|
+
# Merb::Config.use do |c|
|
62
|
+
# c[:log_level] = "debug" # except we want debug log level
|
63
|
+
# c[:log_stream] = @some_io # and log to this IO handle
|
64
|
+
# c[:exception_details] = true # and we want to see exception details
|
65
|
+
# end
|
53
66
|
#
|
54
67
|
# ==== Parameters
|
55
68
|
# env<~String>:: Environment to run like
|
56
69
|
# use_db<~Boolean>:: Should Merb use the merged environments DB connection
|
57
70
|
# Defaults to +false+
|
71
|
+
#
|
72
|
+
# @api public
|
58
73
|
def merge_env(env,use_db=false)
|
59
74
|
if Merb.environment_info.nil?
|
60
75
|
Merb.environment_info = {
|
@@ -74,7 +89,6 @@ module Merb
|
|
74
89
|
else
|
75
90
|
Merb.logger.warn! "Environment file does not exist! #{env_file}"
|
76
91
|
end
|
77
|
-
|
78
92
|
end
|
79
93
|
|
80
94
|
# Mark specific environment to load when ORM loads,
|
@@ -85,14 +99,15 @@ module Merb
|
|
85
99
|
end
|
86
100
|
end
|
87
101
|
|
88
|
-
#
|
89
|
-
#
|
102
|
+
# Start Merb by setting up the Config and then starting the server.
|
103
|
+
# Set the Merb application environment and the root path.
|
90
104
|
#
|
91
105
|
# ==== Parameters
|
92
106
|
# argv<String, Hash>::
|
93
107
|
# The config arguments to start Merb with. Defaults to +ARGV+.
|
94
|
-
|
95
|
-
|
108
|
+
#
|
109
|
+
# @api public
|
110
|
+
def start(argv = ARGV)
|
96
111
|
Merb::Config[:log_stream] = STDOUT
|
97
112
|
if Hash === argv
|
98
113
|
Merb::Config.setup(argv)
|
@@ -103,6 +118,7 @@ module Merb
|
|
103
118
|
|
104
119
|
Merb.environment = Merb::Config[:environment]
|
105
120
|
Merb.root = Merb::Config[:merb_root]
|
121
|
+
|
106
122
|
case Merb::Config[:action]
|
107
123
|
when :kill
|
108
124
|
Merb::Server.kill(Merb::Config[:port], 2)
|
@@ -112,6 +128,7 @@ module Merb
|
|
112
128
|
Merb::Server.kill("main", "HUP")
|
113
129
|
else
|
114
130
|
Merb::Server.start(Merb::Config[:port], Merb::Config[:cluster])
|
131
|
+
@started = true
|
115
132
|
end
|
116
133
|
end
|
117
134
|
|
@@ -120,11 +137,10 @@ module Merb
|
|
120
137
|
# ==== Parameters
|
121
138
|
# argv<String, Hash>::
|
122
139
|
# The config arguments to start Merb with. Defaults to +ARGV+.
|
140
|
+
#
|
141
|
+
# @api public
|
123
142
|
def start_environment(argv=ARGV)
|
124
|
-
unless (@started ||= false)
|
125
|
-
start(argv)
|
126
|
-
@started = true
|
127
|
-
end
|
143
|
+
start(argv) unless (@started ||= false)
|
128
144
|
end
|
129
145
|
|
130
146
|
# Restart the Merb environment explicitly.
|
@@ -132,6 +148,8 @@ module Merb
|
|
132
148
|
# ==== Parameters
|
133
149
|
# argv<String, Hash>::
|
134
150
|
# The config arguments to restart Merb with. Defaults to +Merb::Config+.
|
151
|
+
#
|
152
|
+
# @api public
|
135
153
|
def restart_environment(argv={})
|
136
154
|
@started = false
|
137
155
|
start_environment(Merb::Config.to_hash.merge(argv))
|
@@ -144,30 +162,30 @@ module Merb
|
|
144
162
|
|
145
163
|
Merb.load_paths = Dictionary.new { [Merb.root] } unless Merb.load_paths.is_a?(Dictionary)
|
146
164
|
|
147
|
-
# This is the
|
165
|
+
# This is the mechanism for setting up your application layout.
|
148
166
|
# There are three application layouts in Merb:
|
149
167
|
#
|
150
|
-
# Regular app/:type layout of Ruby on Rails fame:
|
168
|
+
# 1. Regular app/:type layout of Ruby on Rails fame:
|
151
169
|
#
|
152
|
-
# app/models
|
153
|
-
# app/mailers
|
154
|
-
# app/parts
|
155
|
-
# app/views
|
156
|
-
# app/controllers
|
157
|
-
# lib
|
170
|
+
# app/models for models
|
171
|
+
# app/mailers for mailers (special type of controllers)
|
172
|
+
# app/parts for parts, Merb components
|
173
|
+
# app/views for templates
|
174
|
+
# app/controllers for controller
|
175
|
+
# lib for libraries
|
158
176
|
#
|
159
|
-
# Flat application layout:
|
177
|
+
# 2. Flat application layout:
|
160
178
|
#
|
161
179
|
# application.rb for models, controllers, mailers, etc
|
162
180
|
# config/init.rb for initialization and router configuration
|
163
181
|
# config/framework.rb for framework and dependencies configuration
|
164
182
|
# views for views
|
165
183
|
#
|
166
|
-
#
|
167
|
-
# application and configs
|
184
|
+
# 3. Camping-style "very flat" application layout, where the whole Merb
|
185
|
+
# application and configs are contained within a single file.
|
168
186
|
#
|
169
187
|
# ==== Notes
|
170
|
-
# Autoloading for lib uses empty glob by default. If you
|
188
|
+
# Autoloading for lib uses an empty glob by default. If you
|
171
189
|
# want to have your libraries under lib use autoload, add
|
172
190
|
# the following to Merb init file:
|
173
191
|
#
|
@@ -193,6 +211,8 @@ module Merb
|
|
193
211
|
# file_glob<String>::
|
194
212
|
# A glob that will be used to autoload files under the path. Defaults to
|
195
213
|
# "**/*.rb".
|
214
|
+
#
|
215
|
+
# @api public
|
196
216
|
def push_path(type, path, file_glob = "**/*.rb")
|
197
217
|
enforce!(type => Symbol)
|
198
218
|
load_paths[type] = [path, file_glob]
|
@@ -203,18 +223,19 @@ module Merb
|
|
203
223
|
#
|
204
224
|
# ==== Parameters
|
205
225
|
# *args<Array(Symbol)>::
|
206
|
-
#
|
226
|
+
# component(s) names, for instance, :views, :models
|
207
227
|
#
|
208
228
|
# ==== Examples
|
209
|
-
# Using this combined with Merb::GlobalHelpers.push_path
|
210
|
-
#
|
211
|
-
# application components.
|
229
|
+
# Using this combined with Merb::GlobalHelpers.push_path you can make
|
230
|
+
# your Merb application use legacy Rails application components.
|
212
231
|
#
|
213
232
|
# Merb.root = "path/to/legacy/app/root"
|
214
233
|
# Merb.remove_paths(:mailer)
|
215
|
-
# Merb.push_path(:mailer,
|
234
|
+
# Merb.push_path(:mailer, Merb.root / "app" / "models", "**/*.rb")
|
216
235
|
#
|
217
236
|
# Will make Merb use app/models for mailers just like Ruby on Rails does.
|
237
|
+
#
|
238
|
+
# @api public
|
218
239
|
def remove_paths(*args)
|
219
240
|
args.each {|arg| load_paths.delete(arg)}
|
220
241
|
end
|
@@ -224,6 +245,8 @@ module Merb
|
|
224
245
|
#
|
225
246
|
# ==== Returns
|
226
247
|
# String:: The directory for the requested type.
|
248
|
+
#
|
249
|
+
# @api public
|
227
250
|
def dir_for(type)
|
228
251
|
Merb.load_paths[type].first
|
229
252
|
end
|
@@ -233,18 +256,24 @@ module Merb
|
|
233
256
|
#
|
234
257
|
# ===== Returns
|
235
258
|
# String:: The pattern with which to match files within the type directory.
|
259
|
+
#
|
260
|
+
# @api public
|
236
261
|
def glob_for(type)
|
237
262
|
Merb.load_paths[type][1]
|
238
263
|
end
|
239
264
|
|
240
265
|
# ==== Returns
|
241
266
|
# String:: The Merb root path.
|
267
|
+
#
|
268
|
+
# @api public
|
242
269
|
def root
|
243
270
|
@root || Merb::Config[:merb_root] || File.expand_path(Dir.pwd)
|
244
271
|
end
|
245
272
|
|
246
273
|
# ==== Parameters
|
247
274
|
# value<String>:: Path to the root directory.
|
275
|
+
#
|
276
|
+
# @api public
|
248
277
|
def root=(value)
|
249
278
|
@root = value
|
250
279
|
end
|
@@ -261,28 +290,41 @@ module Merb
|
|
261
290
|
# Merb.root = "/home/merb/app"
|
262
291
|
# Merb.path("images") # => "/home/merb/app/images"
|
263
292
|
# Merb.path("views", "admin") # => "/home/merb/app/views/admin"
|
264
|
-
|
293
|
+
#
|
265
294
|
# @public
|
266
295
|
def root_path(*path)
|
267
296
|
File.join(root, *path)
|
268
297
|
end
|
269
298
|
|
270
|
-
# Logger
|
299
|
+
# Return the Merb Logger object for the current thread.
|
300
|
+
# Set it up if it does not exist.
|
301
|
+
#
|
302
|
+
# @api public
|
271
303
|
def logger
|
272
304
|
Thread.current[:merb_logger] ||= Merb::Logger.new
|
273
305
|
end
|
274
306
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
307
|
+
# Removes the logger for the current thread (nil).
|
308
|
+
#
|
309
|
+
# @api public
|
310
|
+
def reset_logger!
|
311
|
+
Thread.current[:merb_logger] = nil
|
279
312
|
end
|
280
313
|
|
281
314
|
# ==== Returns
|
282
315
|
# String::
|
283
|
-
# The path to the log file.
|
284
|
-
# this will return +STDOUT+.
|
316
|
+
# The path to the log file.
|
317
|
+
# If this Merb instance is running as a daemon this will return +STDOUT+.
|
318
|
+
#
|
319
|
+
# ==== Notes
|
320
|
+
# When Merb.testing? the port is modified to become :test - this keeps this
|
321
|
+
# special environment situation from ending up in the memoized @streams
|
322
|
+
# just once, thereby never taking changes into account again. Now, it will
|
323
|
+
# be memoized as :test - and just logging to merb_test.log.
|
324
|
+
#
|
325
|
+
# @api public
|
285
326
|
def log_stream(port = "main")
|
327
|
+
port = :test if Merb.testing?
|
286
328
|
@streams ||= {}
|
287
329
|
@streams[port] ||= begin
|
288
330
|
log = if Merb.testing?
|
@@ -309,7 +351,9 @@ module Merb
|
|
309
351
|
end
|
310
352
|
|
311
353
|
# ==== Returns
|
312
|
-
# String:: Path to directory
|
354
|
+
# String:: Path to the log directory which contains the log file.
|
355
|
+
#
|
356
|
+
# @api public
|
313
357
|
def log_path
|
314
358
|
case Merb::Config[:log_file]
|
315
359
|
when String then File.dirname(Merb::Config[:log_file])
|
@@ -319,6 +363,8 @@ module Merb
|
|
319
363
|
|
320
364
|
# ==== Returns
|
321
365
|
# String:: The path of root directory of the Merb framework.
|
366
|
+
#
|
367
|
+
# @api public
|
322
368
|
def framework_root
|
323
369
|
@framework_root ||= File.dirname(__FILE__)
|
324
370
|
end
|
@@ -329,8 +375,9 @@ module Merb
|
|
329
375
|
# are matched by Rack application handler.
|
330
376
|
#
|
331
377
|
# ==== Notes
|
332
|
-
# Concatenates :deferred_actions configuration option
|
333
|
-
#
|
378
|
+
# Concatenates :deferred_actions configuration option values.
|
379
|
+
#
|
380
|
+
# @api public
|
334
381
|
def deferred_actions
|
335
382
|
@deferred ||= begin
|
336
383
|
if Merb::Config[:deferred_actions].empty?
|
@@ -341,28 +388,10 @@ module Merb
|
|
341
388
|
end
|
342
389
|
end
|
343
390
|
|
344
|
-
#
|
345
|
-
# a
|
346
|
-
#
|
347
|
-
#
|
348
|
-
# ==== Block parameters
|
349
|
-
# r<Merb::Router::Behavior>::
|
350
|
-
# The root behavior upon which new routes can be added.
|
351
|
-
def flat!(framework = {})
|
352
|
-
default = {
|
353
|
-
:framework => { :public => [Merb.root / "public", nil] },
|
354
|
-
:session_store => 'none',
|
355
|
-
:exception_details => true
|
356
|
-
}
|
357
|
-
|
358
|
-
Merb::Config[:framework] = default.merge(framework)
|
359
|
-
|
360
|
-
Merb::Router.prepare do |r|
|
361
|
-
yield(r) if block_given?
|
362
|
-
r.default_routes
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
391
|
+
# Perform a hard Exit.
|
392
|
+
# Print a backtrace to the merb logger before exiting if verbose is enabled.
|
393
|
+
#
|
394
|
+
# @api private
|
366
395
|
def fatal!(str, e = nil)
|
367
396
|
Merb.logger.fatal!
|
368
397
|
Merb.logger.fatal!("\e[1;31;47mFATAL: #{str}\e[0m")
|
@@ -372,6 +401,9 @@ module Merb
|
|
372
401
|
exit(1)
|
373
402
|
end
|
374
403
|
|
404
|
+
# Print a colorized backtrace to the merb logger.
|
405
|
+
#
|
406
|
+
# @api private
|
375
407
|
def print_colorized_backtrace(e)
|
376
408
|
e.backtrace.map! do |line|
|
377
409
|
line.gsub!(/^#{Merb.framework_root}/, "\e[34mFRAMEWORK_ROOT\e[31m")
|
@@ -392,13 +424,15 @@ module Merb
|
|
392
424
|
#
|
393
425
|
# ==== Returns
|
394
426
|
# <Symbol>:: default ORM.
|
427
|
+
#
|
428
|
+
# @api public
|
395
429
|
def orm
|
396
430
|
@orm ||= :none
|
397
431
|
end
|
398
432
|
|
399
433
|
# @deprecated
|
400
434
|
def orm_generator_scope
|
401
|
-
Merb.logger.warn!("WARNING: Merb.orm_generator_scope is deprecated")
|
435
|
+
Merb.logger.warn!("WARNING: Merb.orm_generator_scope is deprecated!")
|
402
436
|
return :merb_default if Merb.orm == :none
|
403
437
|
Merb.orm
|
404
438
|
end
|
@@ -407,6 +441,8 @@ module Merb
|
|
407
441
|
#
|
408
442
|
# ==== Returns
|
409
443
|
# <Symbol>:: default test framework.
|
444
|
+
#
|
445
|
+
# @api public
|
410
446
|
def test_framework
|
411
447
|
@test_framework ||= :rspec
|
412
448
|
end
|
@@ -421,6 +457,8 @@ module Merb
|
|
421
457
|
#
|
422
458
|
# ==== Returns
|
423
459
|
# <Symbol>:: default template engine.
|
460
|
+
#
|
461
|
+
# @api public
|
424
462
|
def template_engine
|
425
463
|
@template_engine ||= :erb
|
426
464
|
end
|
@@ -432,14 +470,16 @@ module Merb
|
|
432
470
|
#
|
433
471
|
# ==== Notes
|
434
472
|
# Bundling required gems makes your application independent from the
|
435
|
-
# environment it runs in.
|
436
|
-
# framework and gems
|
473
|
+
# environment it runs in. It is a good practice to freeze application
|
474
|
+
# framework and gems and is very useful when application is run in
|
437
475
|
# some sort of sandbox, for instance, shared hosting with preconfigured gems.
|
476
|
+
#
|
477
|
+
# @api public
|
438
478
|
def bundled?
|
439
479
|
$BUNDLE || ENV.key?("BUNDLE")
|
440
480
|
end
|
441
481
|
|
442
|
-
# Load configuration and assign logger.
|
482
|
+
# Load configuration and assign the logger.
|
443
483
|
#
|
444
484
|
# ==== Parameters
|
445
485
|
# options<Hash>:: Options to pass on to the Merb config.
|
@@ -477,9 +517,11 @@ module Merb
|
|
477
517
|
# flush after new messages are
|
478
518
|
# added, defaults to true.
|
479
519
|
#
|
480
|
-
# :
|
520
|
+
# :log_stream<IO>:: IO handle for logger. Defaults to STDOUT.
|
521
|
+
#
|
522
|
+
# :log_file<String>:: File path for logger. Overrides :log_stream.
|
481
523
|
#
|
482
|
-
# :log_level<Symbol>:: logger level, default is :
|
524
|
+
# :log_level<Symbol>:: logger level, default is :info
|
483
525
|
#
|
484
526
|
# :disabled_components<Array[Symbol]>::
|
485
527
|
# array of disabled component names,
|
@@ -494,8 +536,10 @@ module Merb
|
|
494
536
|
# Some of these options come from command line on Merb
|
495
537
|
# application start, some of them are set in Merb init file
|
496
538
|
# or environment-specific.
|
539
|
+
#
|
540
|
+
# @api public
|
497
541
|
def load_config(options = {})
|
498
|
-
Merb::Config.setup(
|
542
|
+
Merb::Config.setup(Merb::Config.defaults.merge(options))
|
499
543
|
Merb::BootLoader::Logger.run
|
500
544
|
end
|
501
545
|
|
@@ -507,6 +551,8 @@ module Merb
|
|
507
551
|
#
|
508
552
|
# ==== Parameters
|
509
553
|
# options<Hash>:: Options to pass on to the Merb config.
|
554
|
+
#
|
555
|
+
# @api public
|
510
556
|
def load_dependencies(options = {})
|
511
557
|
load_config(options)
|
512
558
|
Merb::BootLoader::BuildFramework.run
|
@@ -516,6 +562,8 @@ module Merb
|
|
516
562
|
|
517
563
|
# Reload application and framework classes.
|
518
564
|
# See Merb::BootLoader::ReloadClasses for details.
|
565
|
+
#
|
566
|
+
# @api public
|
519
567
|
def reload
|
520
568
|
Merb::BootLoader::ReloadClasses.reload
|
521
569
|
end
|
@@ -523,6 +571,8 @@ module Merb
|
|
523
571
|
# ==== Returns
|
524
572
|
# Boolean:: True if Merb environment is testing for instance,
|
525
573
|
# Merb is running with RSpec, Test::Unit of other testing facility.
|
574
|
+
#
|
575
|
+
# @api public
|
526
576
|
def testing?
|
527
577
|
$TESTING ||= env?(:test) || Merb::Config[:testing]
|
528
578
|
end
|
@@ -535,6 +585,8 @@ module Merb
|
|
535
585
|
# Merb.env #=> production
|
536
586
|
# Merb.env?(:production) #=> true
|
537
587
|
# Merb.env?(:development) #=> false
|
588
|
+
#
|
589
|
+
# @api public
|
538
590
|
def env?(env)
|
539
591
|
Merb.env == env.to_s
|
540
592
|
end
|
@@ -562,6 +614,8 @@ module Merb
|
|
562
614
|
# reload_classes true
|
563
615
|
# reload_time 0.5
|
564
616
|
# end
|
617
|
+
#
|
618
|
+
# @api public
|
565
619
|
def config(&block)
|
566
620
|
Merb::Config.configure(&block) if block_given?
|
567
621
|
Config
|
@@ -571,24 +625,32 @@ module Merb
|
|
571
625
|
#
|
572
626
|
# ==== Parameters
|
573
627
|
# *args:: One or more symbols of Merb internal components.
|
628
|
+
#
|
629
|
+
# @api public
|
574
630
|
def disable(*components)
|
575
631
|
disabled_components.push(*components)
|
576
632
|
end
|
577
633
|
|
578
634
|
# ==== Parameters
|
579
635
|
# Array:: All components that should be disabled.
|
636
|
+
#
|
637
|
+
# @api public
|
580
638
|
def disabled_components=(components)
|
581
639
|
disabled_components.replace components
|
582
640
|
end
|
583
641
|
|
584
642
|
# ==== Returns
|
585
643
|
# Array:: All components that have been disabled.
|
644
|
+
#
|
645
|
+
# @api public
|
586
646
|
def disabled_components
|
587
647
|
Merb::Config[:disabled_components] ||= []
|
588
648
|
end
|
589
649
|
|
590
650
|
# ==== Returns
|
591
651
|
# Boolean:: True if all components (or just one) are disabled.
|
652
|
+
#
|
653
|
+
# @api public
|
592
654
|
def disabled?(*components)
|
593
655
|
components.all? { |c| disabled_components.include?(c) }
|
594
656
|
end
|
@@ -599,6 +661,8 @@ module Merb
|
|
599
661
|
# ==== Notes
|
600
662
|
# Recommended way to find out what paths Rakefiles
|
601
663
|
# are loaded from.
|
664
|
+
#
|
665
|
+
# @api public
|
602
666
|
def rakefiles
|
603
667
|
@rakefiles ||= []
|
604
668
|
end
|
@@ -607,8 +671,9 @@ module Merb
|
|
607
671
|
# Array(String):: Paths generators are loaded from
|
608
672
|
#
|
609
673
|
# === Notes
|
610
|
-
# Recommended way to find out what paths generators
|
611
|
-
#
|
674
|
+
# Recommended way to find out what paths generators are loaded from.
|
675
|
+
#
|
676
|
+
# @api public
|
612
677
|
def generators
|
613
678
|
@generators ||= []
|
614
679
|
end
|
@@ -618,6 +683,8 @@ module Merb
|
|
618
683
|
#
|
619
684
|
# ==== Notes
|
620
685
|
# Recommended way to add Rakefiles load path for plugins authors.
|
686
|
+
#
|
687
|
+
# @api public
|
621
688
|
def add_rakefiles(*rakefiles)
|
622
689
|
@rakefiles ||= []
|
623
690
|
@rakefiles += rakefiles
|
@@ -628,6 +695,8 @@ module Merb
|
|
628
695
|
#
|
629
696
|
# ==== Notes
|
630
697
|
# Recommended way to add Generator load paths for plugin authors.
|
698
|
+
#
|
699
|
+
# @api public
|
631
700
|
def add_generators(*generators)
|
632
701
|
@generators ||= []
|
633
702
|
@generators += generators
|
@@ -638,6 +707,8 @@ module Merb
|
|
638
707
|
# ==== Parameters
|
639
708
|
# signal:: The name of the signal to install a handler for.
|
640
709
|
# &block:: The block to be run when the given signal is received.
|
710
|
+
#
|
711
|
+
# @api public
|
641
712
|
def trap(signal, &block)
|
642
713
|
Kernel.trap(signal, &block) unless Merb.disabled?(:signals)
|
643
714
|
end
|
@@ -645,12 +716,12 @@ module Merb
|
|
645
716
|
end
|
646
717
|
end
|
647
718
|
|
648
|
-
require
|
649
|
-
require
|
650
|
-
require
|
651
|
-
require
|
652
|
-
require
|
653
|
-
require
|
719
|
+
require "merb-core/autoload"
|
720
|
+
require "merb-core/server"
|
721
|
+
require "merb-core/gem_ext/erubis"
|
722
|
+
require "merb-core/logger"
|
723
|
+
require "merb-core/version"
|
724
|
+
require "merb-core/controller/mime"
|
654
725
|
|
655
726
|
# Set the environment if it hasn't already been set.
|
656
|
-
Merb.environment ||= ENV[
|
727
|
+
Merb.environment ||= ENV["MERB_ENV"] || Merb::Config[:environment] || (Merb.testing? ? "test" : "development")
|