merb-core 0.9.13 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/Rakefile +5 -3
  2. data/lib/merb-core.rb +84 -41
  3. data/lib/merb-core/bootloader.rb +71 -60
  4. data/lib/merb-core/config.rb +31 -17
  5. data/lib/merb-core/controller/abstract_controller.rb +35 -35
  6. data/lib/merb-core/controller/exceptions.rb +14 -9
  7. data/lib/merb-core/controller/merb_controller.rb +22 -20
  8. data/lib/merb-core/controller/mime.rb +5 -5
  9. data/lib/merb-core/controller/mixins/authentication.rb +11 -8
  10. data/lib/merb-core/controller/mixins/conditional_get.rb +7 -7
  11. data/lib/merb-core/controller/mixins/controller.rb +15 -15
  12. data/lib/merb-core/controller/mixins/render.rb +16 -16
  13. data/lib/merb-core/controller/mixins/responder.rb +23 -23
  14. data/lib/merb-core/controller/template.rb +17 -17
  15. data/lib/merb-core/core_ext/hash.rb +2 -2
  16. data/lib/merb-core/core_ext/kernel.rb +19 -18
  17. data/lib/merb-core/dispatch/cookies.rb +13 -0
  18. data/lib/merb-core/dispatch/default_exception/default_exception.rb +12 -1
  19. data/lib/merb-core/dispatch/dispatcher.rb +6 -5
  20. data/lib/merb-core/dispatch/request.rb +56 -52
  21. data/lib/merb-core/dispatch/request_parsers.rb +7 -7
  22. data/lib/merb-core/dispatch/router.rb +14 -14
  23. data/lib/merb-core/dispatch/router/behavior.rb +31 -31
  24. data/lib/merb-core/dispatch/router/cached_proc.rb +13 -1
  25. data/lib/merb-core/dispatch/router/resources.rb +9 -9
  26. data/lib/merb-core/dispatch/router/route.rb +60 -7
  27. data/lib/merb-core/dispatch/session.rb +21 -15
  28. data/lib/merb-core/dispatch/session/container.rb +10 -8
  29. data/lib/merb-core/dispatch/session/cookie.rb +12 -11
  30. data/lib/merb-core/dispatch/session/memcached.rb +4 -2
  31. data/lib/merb-core/dispatch/session/memory.rb +8 -6
  32. data/lib/merb-core/dispatch/session/store_container.rb +6 -5
  33. data/lib/merb-core/dispatch/worker.rb +28 -10
  34. data/lib/merb-core/gem_ext/erubis.rb +4 -2
  35. data/lib/merb-core/logger.rb +3 -22
  36. data/lib/merb-core/plugins.rb +5 -5
  37. data/lib/merb-core/rack.rb +1 -1
  38. data/lib/merb-core/rack/adapter.rb +5 -1
  39. data/lib/merb-core/rack/adapter/abstract.rb +15 -10
  40. data/lib/merb-core/rack/adapter/ebb.rb +4 -2
  41. data/lib/merb-core/rack/adapter/evented_mongrel.rb +2 -1
  42. data/lib/merb-core/rack/adapter/fcgi.rb +3 -1
  43. data/lib/merb-core/rack/adapter/irb.rb +10 -1
  44. data/lib/merb-core/rack/adapter/mongrel.rb +5 -2
  45. data/lib/merb-core/rack/adapter/runner.rb +3 -1
  46. data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +2 -1
  47. data/lib/merb-core/rack/adapter/thin.rb +4 -1
  48. data/lib/merb-core/rack/adapter/thin_turbo.rb +1 -0
  49. data/lib/merb-core/rack/adapter/webrick.rb +8 -34
  50. data/lib/merb-core/rack/application.rb +2 -2
  51. data/lib/merb-core/rack/handler/mongrel.rb +7 -0
  52. data/lib/merb-core/rack/helpers.rb +1 -1
  53. data/lib/merb-core/rack/middleware.rb +7 -1
  54. data/lib/merb-core/rack/middleware/conditional_get.rb +3 -0
  55. data/lib/merb-core/rack/middleware/content_length.rb +2 -0
  56. data/lib/merb-core/rack/middleware/path_prefix.rb +4 -0
  57. data/lib/merb-core/rack/middleware/profiler.rb +3 -1
  58. data/lib/merb-core/rack/middleware/static.rb +7 -1
  59. data/lib/merb-core/rack/middleware/tracer.rb +1 -0
  60. data/lib/merb-core/rack/stream_wrapper.rb +35 -30
  61. data/lib/merb-core/server.rb +17 -16
  62. data/lib/merb-core/tasks/gem_management.rb +1 -1
  63. data/lib/merb-core/tasks/merb.rb +3 -1
  64. data/lib/merb-core/tasks/merb_rake_helper.rb +1 -1
  65. data/lib/merb-core/test.rb +8 -8
  66. data/lib/merb-core/test/helpers.rb +1 -1
  67. data/lib/merb-core/test/helpers/cookie_jar.rb +16 -2
  68. data/lib/merb-core/test/helpers/mock_request_helper.rb +13 -13
  69. data/lib/merb-core/test/helpers/request_helper.rb +1 -1
  70. data/lib/merb-core/test/helpers/route_helper.rb +2 -2
  71. data/lib/merb-core/test/matchers.rb +3 -3
  72. data/lib/merb-core/test/matchers/request_matchers.rb +1 -1
  73. data/lib/merb-core/test/run_spec.rb +1 -1
  74. data/lib/merb-core/test/tasks/spectasks.rb +1 -1
  75. data/lib/merb-core/test/test_ext/hpricot.rb +1 -1
  76. data/lib/merb-core/test/test_ext/rspec.rb +2 -2
  77. data/lib/merb-core/test/test_ext/string.rb +1 -1
  78. data/lib/merb-core/version.rb +1 -1
  79. metadata +8 -22
  80. data/lib/merb-core/test/matchers/view_matchers.rb +0 -231
  81. data/lib/merb-core/test/webrat.rb +0 -37
  82. data/lib/merb-core/vendor/nokogiri/css.rb +0 -6
  83. data/lib/merb-core/vendor/nokogiri/css/generated_parser.rb +0 -653
  84. data/lib/merb-core/vendor/nokogiri/css/generated_tokenizer.rb +0 -159
  85. data/lib/merb-core/vendor/nokogiri/css/node.rb +0 -95
  86. data/lib/merb-core/vendor/nokogiri/css/parser.rb +0 -24
  87. data/lib/merb-core/vendor/nokogiri/css/parser.y +0 -198
  88. data/lib/merb-core/vendor/nokogiri/css/tokenizer.rb +0 -9
  89. data/lib/merb-core/vendor/nokogiri/css/tokenizer.rex +0 -63
  90. data/lib/merb-core/vendor/nokogiri/css/xpath_visitor.rb +0 -159
@@ -10,7 +10,7 @@ module Merb
10
10
  # The configuration loaded from Merb.root / "config/plugins.yml" or, if
11
11
  # the load fails, an empty hash whose default value is another Hash.
12
12
  #
13
- # @api plugin
13
+ # :api: plugin
14
14
  def self.config
15
15
  @config ||= begin
16
16
  # this is so you can do Merb.plugins.config[:helpers][:awesome] = "bar"
@@ -31,7 +31,7 @@ module Merb
31
31
  # ==== Returns
32
32
  # Array(String):: All Rakefile load paths Merb uses for plugins.
33
33
  #
34
- # @api plugin
34
+ # :api: plugin
35
35
  def self.rakefiles
36
36
  Merb.rakefiles
37
37
  end
@@ -39,7 +39,7 @@ module Merb
39
39
  # ==== Returns
40
40
  # Array(String):: All Generator load paths Merb uses for plugins.
41
41
  #
42
- # @api plugin
42
+ # :api: plugin
43
43
  def self.generators
44
44
  Merb.generators
45
45
  end
@@ -59,7 +59,7 @@ module Merb
59
59
  # Merb::Plugins.add_rakefiles "merb_sequel" / "merbtasks"
60
60
  # end
61
61
  #
62
- # @api plugin
62
+ # :api: plugin
63
63
  def self.add_rakefiles(*rakefiles)
64
64
  Merb.add_rakefiles(*rakefiles)
65
65
  end
@@ -72,7 +72,7 @@ module Merb
72
72
  # This is the recommended way to register your plugin's generators
73
73
  # in Merb.
74
74
  #
75
- # @api plugin
75
+ # :api: plugin
76
76
  def self.add_generators(*generators)
77
77
  Merb.add_generators(*generators)
78
78
  end
@@ -24,4 +24,4 @@ module Merb
24
24
  autoload :StreamWrapper, 'merb-core/rack/stream_wrapper'
25
25
  autoload :Helpers, 'merb-core/rack/helpers'
26
26
  end # Rack
27
- end # Merb
27
+ end # Merb
@@ -11,6 +11,8 @@ module Merb
11
11
  #
12
12
  # ==== Returns.
13
13
  # Class:: The adapter class.
14
+ #
15
+ # :api: private
14
16
  def get(id)
15
17
  if @adapters[id.to_s]
16
18
  Object.full_const_get(@adapters[id.to_s])
@@ -24,6 +26,8 @@ module Merb
24
26
  # ==== Parameters
25
27
  # ids<Array>:: Identifiers by which this adapter is recognized by.
26
28
  # adapter_class<Class>:: The Rack adapter class.
29
+ #
30
+ # :api: plugin
27
31
  def register(ids, adapter_class)
28
32
  @adapters ||= Hash.new
29
33
  ids.each { |id| @adapters[id] = "Merb::Rack::#{adapter_class}" }
@@ -45,4 +49,4 @@ module Merb
45
49
  Adapter.register %w{webrick}, :WEBrick
46
50
 
47
51
  end # Rack
48
- end # Merb
52
+ end # Merb
@@ -6,7 +6,7 @@ module Merb
6
6
  # will be called to start a server created with the new_server method.
7
7
  # This is called from the AbstractAdapter start method.
8
8
  #
9
- # @api plugin
9
+ # :api: plugin
10
10
  # @overridable
11
11
  def self.start_server
12
12
  raise NotImplemented
@@ -20,12 +20,12 @@ module Merb
20
20
  # ==== Parameters
21
21
  # port<Integer>:: The port the server should listen on
22
22
  #
23
- # @api plugin
23
+ # :api: plugin
24
24
  # @overridable
25
25
  def self.new_server(port)
26
26
  raise NotImplemented
27
27
  end
28
-
28
+
29
29
  # This method is designed to be overridden in a rack adapter. It will
30
30
  # be called to stop the adapter server.
31
31
  #
@@ -35,7 +35,7 @@ module Merb
35
35
  # ==== Returns
36
36
  # Boolean:: True if the server was properly stopped.
37
37
  #
38
- # @api plugin
38
+ # :api: plugin
39
39
  # @overridable
40
40
  def self.stop(status)
41
41
  raise NotImplemented
@@ -46,7 +46,7 @@ module Merb
46
46
  # ==== Parameters
47
47
  # port<Integer>:: The port to start the worker process on.
48
48
  #
49
- # @api private
49
+ # :api: private
50
50
  def self.spawn_worker(port)
51
51
  worker_pid = Kernel.fork
52
52
  start_at_port(port, @opts) unless worker_pid
@@ -69,7 +69,7 @@ module Merb
69
69
  # port: the port to bind to
70
70
  # cluster: the number
71
71
  #
72
- # @api private
72
+ # :api: private
73
73
  def self.start(opts={})
74
74
  @opts = opts
75
75
  $WORKERS ||= []
@@ -148,7 +148,7 @@ module Merb
148
148
  # opts<Hash>:: The hash of options, defaults to the @opts
149
149
  # instance variable.
150
150
  #
151
- # @api private
151
+ # :api: private
152
152
  def self.start_at_port(port, opts = @opts)
153
153
  at_exit do
154
154
  Merb::Server.remove_pid(port)
@@ -161,6 +161,7 @@ module Merb
161
161
  # of workers.
162
162
  if Merb::Config[:daemonize]
163
163
  Merb.trap('INT') do
164
+ Merb.exiting = true
164
165
  stop
165
166
  Merb.logger.warn! "Exiting port #{port}\n"
166
167
  exit_process
@@ -209,7 +210,11 @@ module Merb
209
210
  # Call the adapter's new_server method, which should attempt
210
211
  # to bind to a port.
211
212
  new_server(port)
212
- rescue Errno::EADDRINUSE
213
+ rescue Errno::EADDRINUSE => e
214
+ if Merb::Config[:bind_fail_fatal]
215
+ Merb.fatal! "Could not bind to #{port}. It was already in use", e
216
+ end
217
+
213
218
  unless printed_warning
214
219
  Merb.logger.warn! "Port #{port} is in use, " \
215
220
  "Waiting for it to become available."
@@ -235,7 +240,7 @@ module Merb
235
240
  # ==== Parameters
236
241
  # status<Integer>:: The exit code of the process.
237
242
  #
238
- # @api private
243
+ # :api: private
239
244
  def self.exit_process(status = 0)
240
245
  exit(status)
241
246
  end
@@ -247,7 +252,7 @@ module Merb
247
252
  # processes.
248
253
  # port<Integer>:: The base port that the app is running on.
249
254
  #
250
- # @api private
255
+ # :api: private
251
256
  def self.process_title(whoami, port)
252
257
  name = Merb::Config[:name]
253
258
  app = "merb#{" : #{name}" if (name && name != "merb")}"
@@ -5,20 +5,22 @@ module Merb
5
5
 
6
6
  class Ebb < Merb::Rack::AbstractAdapter
7
7
  # start an Ebb server on given host and port.
8
-
8
+ # :api: plugin
9
9
  def self.new_server(port)
10
10
  Merb::Dispatcher.use_mutex = false
11
11
  opts = @opts.merge(:port => port)
12
12
  @th = Thread.new { Thread.current[:server] = ::Ebb.start_server(opts[:app], opts) }
13
13
  end
14
14
 
15
+ # :api: plugin
15
16
  def self.start_server
16
17
  @th.join
17
18
  end
18
19
 
20
+ # :api: plugin
19
21
  def self.stop(status = 0)
20
22
  ::Ebb.stop_server
21
23
  end
22
24
  end
23
25
  end
24
- end
26
+ end
@@ -4,10 +4,11 @@ module Merb
4
4
  module Rack
5
5
 
6
6
  class EventedMongrel < Mongrel
7
+ # :api: plugin
7
8
  def self.new_server(port)
8
9
  Merb::Dispatcher.use_mutex = false
9
10
  super
10
11
  end
11
12
  end
12
13
  end
13
- end
14
+ end
@@ -7,6 +7,8 @@ module Merb
7
7
  #
8
8
  # ==== Options (opts)
9
9
  # :app<String>>:: The application name.
10
+ #
11
+ # :api: plugin
10
12
  def self.start(opts={})
11
13
  Merb.logger.warn!("Using FastCGI adapter")
12
14
  Merb::Server.change_privilege
@@ -14,4 +16,4 @@ module Merb
14
16
  end
15
17
  end
16
18
  end
17
- end
19
+ end
@@ -54,18 +54,20 @@ module Merb
54
54
  #
55
55
  # url(:articles, 2008, 10, "test_article")
56
56
  #
57
- # @api public
57
+ # :api: public
58
58
  def url(name, *args)
59
59
  args << {}
60
60
  Merb::Router.url(name, *args)
61
61
  end
62
62
 
63
63
  # Reloads classes using Merb::BootLoader::ReloadClasses.
64
+ # :api: public
64
65
  def reload!
65
66
  Merb::BootLoader::ReloadClasses.reload
66
67
  end
67
68
 
68
69
  # Prints all routes for the application.
70
+ # :api: public
69
71
  def show_routes
70
72
  seen = []
71
73
  unless Merb::Router.named_routes.empty?
@@ -96,6 +98,7 @@ module Merb
96
98
  #
97
99
  # An ORM should implement Merb::Orms::MyOrm#open_sandbox! to support this.
98
100
  # Usually this involves starting a transaction.
101
+ # :api: public
99
102
  def open_sandbox!
100
103
  puts "Loading #{Merb.environment} environment in sandbox (Merb #{Merb::VERSION})"
101
104
  puts "Any modifications you make will be rolled back on exit"
@@ -106,12 +109,14 @@ module Merb
106
109
  #
107
110
  # An ORM should implement Merb::Orms::MyOrm#close_sandbox! to support this.
108
111
  # Usually this involves rolling back a transaction.
112
+ # :api: public
109
113
  def close_sandbox!
110
114
  orm_modules.each { |orm| orm.close_sandbox! if orm.respond_to?(:close_sandbox!) }
111
115
  puts "Modifications have been rolled back"
112
116
  end
113
117
 
114
118
  # Explictly show logger output during IRB session
119
+ # :api: public
115
120
  def trace_log!
116
121
  Merb.logger.auto_flush = true
117
122
  end
@@ -120,6 +125,7 @@ module Merb
120
125
 
121
126
  # ==== Returns
122
127
  # Array:: All Merb::Orms::* modules.
128
+ # :api: private
123
129
  def orm_modules
124
130
  if Merb.const_defined?('Orms')
125
131
  Merb::Orms.constants.map { |c| Merb::Orms::const_get(c) }
@@ -138,6 +144,8 @@ module Merb
138
144
  # ==== Notes
139
145
  # If the +.irbrc+ file exists, it will be loaded into the IRBRC
140
146
  # environment variable.
147
+ #
148
+ # :api: plugin
141
149
  def self.start(opts={})
142
150
  m = Merb::Rack::Console.new
143
151
  m.extend Merb::Test::RequestHelper
@@ -156,6 +164,7 @@ module Merb
156
164
 
157
165
  private
158
166
 
167
+ # :api: private
159
168
  def self.sandboxed?
160
169
  Merb::Config[:sandbox]
161
170
  end
@@ -14,6 +14,7 @@ module Merb
14
14
 
15
15
  class Mongrel < Merb::Rack::AbstractAdapter
16
16
 
17
+ # :api: plugin
17
18
  def self.stop(status = 0)
18
19
  if @server
19
20
  begin
@@ -25,11 +26,13 @@ module Merb
25
26
  true
26
27
  end
27
28
  end
28
-
29
+
30
+ # :api: plugin
29
31
  def self.new_server(port)
30
32
  @server = ::Mongrel::HttpServer.new(@opts[:host], port)
31
33
  end
32
34
 
35
+ # :api: plugin
33
36
  def self.start_server
34
37
  @server.register('/', ::Merb::Rack::Handler::Mongrel.new(@opts[:app]))
35
38
  @server.run.join
@@ -38,4 +41,4 @@ module Merb
38
41
  end
39
42
 
40
43
  end
41
- end
44
+ end
@@ -12,6 +12,8 @@ module Merb
12
12
  # ==== Notes
13
13
  # If opts[:runner_code] matches a filename, that file will be read and
14
14
  # the contents executed. Otherwise the code will be executed directly.
15
+ #
16
+ # :api: plugin
15
17
  def self.start(opts={})
16
18
  Merb::Server.change_privilege
17
19
  if opts[:runner_code]
@@ -25,4 +27,4 @@ module Merb
25
27
  end
26
28
  end
27
29
  end
28
- end
30
+ end
@@ -4,6 +4,7 @@ module Merb
4
4
  module Rack
5
5
 
6
6
  class SwiftipliedMongrel < Mongrel
7
+ # :api: plugin
7
8
  def self.new_server(port)
8
9
  Merb::Dispatcher.use_mutex = false
9
10
  super
@@ -11,4 +12,4 @@ module Merb
11
12
  end
12
13
 
13
14
  end
14
- end
15
+ end
@@ -7,6 +7,7 @@ module Merb
7
7
  class Thin < Merb::Rack::AbstractAdapter
8
8
  # start a Thin server on given host and port.
9
9
 
10
+ # :api: plugin
10
11
  def self.new_server(port)
11
12
  Merb::Dispatcher.use_mutex = false
12
13
 
@@ -22,11 +23,13 @@ module Merb
22
23
  end
23
24
  end
24
25
 
26
+ # :api: plugin
25
27
  def self.start_server
26
28
  ::Thin::Logging.silent = true
27
29
  @server.start
28
30
  end
29
31
 
32
+ # :api: plugin
30
33
  def self.stop(status = 0)
31
34
  if @server
32
35
  @server.stop
@@ -35,4 +38,4 @@ module Merb
35
38
  end
36
39
  end
37
40
  end
38
- end
41
+ end
@@ -7,6 +7,7 @@ module Merb
7
7
  class ThinTurbo < Thin
8
8
  # start a Thin Turbo server on given host and port.
9
9
 
10
+ # :api: plugin
10
11
  def self.new_server(port)
11
12
  @opts.merge!(:backend => ::Thin::Backends::Turbo)
12
13
  super
@@ -7,9 +7,11 @@ module Merb
7
7
  class WEBrick < Merb::Rack::AbstractAdapter
8
8
 
9
9
  class << self
10
+ # :api: private
10
11
  attr_accessor :server
11
12
  end
12
-
13
+
14
+ # :api: plugin
13
15
  def self.new_server(port)
14
16
  options = {
15
17
  :Port => port,
@@ -25,48 +27,20 @@ module Merb
25
27
  @server = ::WEBrick::HTTPServer.new(options.merge(:DoNotListen => true))
26
28
  @server.listeners.replace sockets
27
29
  end
28
-
30
+
31
+ # :api: plugin
29
32
  def self.start_server
30
33
  @server.mount("/", ::Rack::Handler::WEBrick, @opts[:app])
31
34
  @server.start
32
35
  exit(@status)
33
36
  end
34
37
 
38
+ # :api: plugin
35
39
  def self.stop(status = 0)
36
40
  @status = status
37
41
  @server.shutdown
38
42
  end
39
-
40
- def self.exit_process(status = 0)
41
- end
42
-
43
- # start WEBrick server on given host and port.
44
-
45
- # ==== Parameters
46
- # opts<Hash>:: Options for WEBrick (see below).
47
- #
48
- # ==== Options (opts)
49
- # :host<String>:: The hostname that WEBrick should serve.
50
- # :port<Fixnum>:: The port WEBrick should bind to.
51
- # :app<String>>:: The application name.
52
- # def self.start(opts={})
53
- # Merb.logger.warn!("Using Webrick adapter")
54
- #
55
- # options = {
56
- # :Port => opts[:port],
57
- # :BindAddress => opts[:host],
58
- # :Logger => Merb.logger,
59
- # :AccessLog => [
60
- # [Merb.logger, ::WEBrick::AccessLog::COMMON_LOG_FORMAT],
61
- # [Merb.logger, ::WEBrick::AccessLog::REFERER_LOG_FORMAT]
62
- # ]
63
- # }
64
- #
65
- # server = ::WEBrick::HTTPServer.new(options)
66
- # Merb::Server.change_privilege
67
- # server.mount("/", ::Rack::Handler::WEBrick, opts[:app])
68
- # server.start
69
- # end
43
+
70
44
  end
71
45
  end
72
- end
46
+ end