merb-core 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/LICENSE +1 -1
  2. data/README +3 -3
  3. data/Rakefile +144 -33
  4. data/bin/merb +0 -0
  5. data/bin/merb-specs +0 -0
  6. data/docs/bootloading.dox +1 -0
  7. data/docs/merb-core-call-stack-diagram.mmap +0 -0
  8. data/docs/merb-core-call-stack-diagram.pdf +0 -0
  9. data/docs/merb-core-call-stack-diagram.png +0 -0
  10. data/lib/merb-core.rb +159 -37
  11. data/lib/merb-core/autoload.rb +1 -0
  12. data/lib/merb-core/bootloader.rb +208 -92
  13. data/lib/merb-core/config.rb +20 -6
  14. data/lib/merb-core/controller/abstract_controller.rb +113 -61
  15. data/lib/merb-core/controller/exceptions.rb +28 -13
  16. data/lib/merb-core/controller/merb_controller.rb +73 -44
  17. data/lib/merb-core/controller/mime.rb +25 -7
  18. data/lib/merb-core/controller/mixins/authentication.rb +1 -1
  19. data/lib/merb-core/controller/mixins/controller.rb +44 -8
  20. data/lib/merb-core/controller/mixins/render.rb +191 -128
  21. data/lib/merb-core/controller/mixins/responder.rb +65 -63
  22. data/lib/merb-core/controller/template.rb +103 -54
  23. data/lib/merb-core/core_ext.rb +7 -12
  24. data/lib/merb-core/core_ext/kernel.rb +128 -136
  25. data/lib/merb-core/dispatch/cookies.rb +26 -4
  26. data/lib/merb-core/dispatch/default_exception/default_exception.rb +93 -0
  27. data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +198 -0
  28. data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +73 -0
  29. data/lib/merb-core/dispatch/default_exception/views/index.html.erb +92 -0
  30. data/lib/merb-core/dispatch/dispatcher.rb +156 -224
  31. data/lib/merb-core/dispatch/request.rb +126 -25
  32. data/lib/merb-core/dispatch/router.rb +61 -6
  33. data/lib/merb-core/dispatch/router/behavior.rb +122 -41
  34. data/lib/merb-core/dispatch/router/route.rb +147 -22
  35. data/lib/merb-core/dispatch/session.rb +52 -2
  36. data/lib/merb-core/dispatch/session/cookie.rb +4 -2
  37. data/lib/merb-core/dispatch/session/memcached.rb +38 -27
  38. data/lib/merb-core/dispatch/session/memory.rb +18 -11
  39. data/lib/merb-core/dispatch/worker.rb +28 -0
  40. data/lib/merb-core/gem_ext/erubis.rb +58 -0
  41. data/lib/merb-core/logger.rb +3 -31
  42. data/lib/merb-core/plugins.rb +25 -3
  43. data/lib/merb-core/rack.rb +18 -12
  44. data/lib/merb-core/rack/adapter.rb +10 -8
  45. data/lib/merb-core/rack/adapter/ebb.rb +2 -2
  46. data/lib/merb-core/rack/adapter/irb.rb +31 -21
  47. data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
  48. data/lib/merb-core/rack/adapter/thin.rb +19 -9
  49. data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
  50. data/lib/merb-core/rack/application.rb +9 -84
  51. data/lib/merb-core/rack/middleware.rb +26 -0
  52. data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
  53. data/lib/merb-core/rack/middleware/profiler.rb +19 -0
  54. data/lib/merb-core/rack/middleware/static.rb +45 -0
  55. data/lib/merb-core/server.rb +27 -9
  56. data/lib/merb-core/tasks/audit.rake +68 -0
  57. data/lib/merb-core/tasks/merb.rb +1 -0
  58. data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
  59. data/lib/merb-core/tasks/stats.rake +71 -0
  60. data/lib/merb-core/test.rb +2 -1
  61. data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -3
  62. data/lib/merb-core/test/helpers/request_helper.rb +66 -24
  63. data/lib/merb-core/test/matchers/controller_matchers.rb +36 -4
  64. data/lib/merb-core/test/matchers/route_matchers.rb +12 -3
  65. data/lib/merb-core/test/matchers/view_matchers.rb +3 -3
  66. data/lib/merb-core/test/run_specs.rb +1 -0
  67. data/lib/merb-core/test/tasks/spectasks.rb +13 -5
  68. data/lib/merb-core/test/test_ext/string.rb +14 -0
  69. data/lib/merb-core/vendor/facets/dictionary.rb +3 -3
  70. data/lib/merb-core/vendor/facets/inflect.rb +82 -37
  71. data/lib/merb-core/version.rb +2 -2
  72. data/spec/private/config/config_spec.rb +39 -4
  73. data/spec/private/core_ext/kernel_spec.rb +3 -14
  74. data/spec/private/dispatch/bootloader_spec.rb +1 -1
  75. data/spec/private/dispatch/cookies_spec.rb +181 -69
  76. data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -2
  77. data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -2
  78. data/spec/private/dispatch/fixture/config/rack.rb +10 -0
  79. data/spec/private/dispatch/fixture/log/merb_test.log +7054 -1802
  80. data/spec/private/dispatch/route_params_spec.rb +2 -3
  81. data/spec/private/dispatch/session_mixin_spec.rb +47 -0
  82. data/spec/private/plugins/plugin_spec.rb +73 -59
  83. data/spec/private/router/behavior_spec.rb +60 -0
  84. data/spec/private/router/fixture/log/merb_test.log +1693 -0
  85. data/spec/private/router/route_spec.rb +414 -0
  86. data/spec/private/router/router_spec.rb +175 -0
  87. data/spec/private/vendor/facets/plural_spec.rb +564 -0
  88. data/spec/private/vendor/facets/singular_spec.rb +489 -0
  89. data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
  90. data/spec/public/abstract_controller/controllers/helpers.rb +12 -2
  91. data/spec/public/abstract_controller/controllers/partial.rb +17 -2
  92. data/spec/public/abstract_controller/controllers/render.rb +16 -1
  93. data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
  94. data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
  95. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
  96. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
  97. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
  98. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
  99. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
  100. data/spec/public/abstract_controller/filter_spec.rb +20 -1
  101. data/spec/public/abstract_controller/helper_spec.rb +10 -2
  102. data/spec/public/abstract_controller/partial_spec.rb +8 -0
  103. data/spec/public/abstract_controller/render_spec.rb +8 -0
  104. data/spec/public/abstract_controller/spec_helper.rb +7 -3
  105. data/spec/public/boot_loader/boot_loader_spec.rb +2 -2
  106. data/spec/public/controller/base_spec.rb +10 -2
  107. data/spec/public/controller/config/init.rb +6 -0
  108. data/spec/public/controller/controllers/authentication.rb +9 -11
  109. data/spec/public/controller/controllers/base.rb +2 -8
  110. data/spec/public/controller/controllers/cookies.rb +16 -0
  111. data/spec/public/controller/controllers/dispatcher.rb +35 -0
  112. data/spec/public/controller/controllers/display.rb +62 -14
  113. data/spec/public/controller/controllers/redirect.rb +36 -0
  114. data/spec/public/controller/controllers/responder.rb +37 -11
  115. data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
  116. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
  117. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
  118. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
  119. data/spec/public/controller/cookies_spec.rb +23 -0
  120. data/spec/public/controller/dispatcher_spec.rb +411 -0
  121. data/spec/public/controller/display_spec.rb +43 -10
  122. data/spec/public/controller/redirect_spec.rb +33 -0
  123. data/spec/public/controller/responder_spec.rb +79 -11
  124. data/spec/public/controller/spec_helper.rb +3 -1
  125. data/spec/public/controller/url_spec.rb +10 -0
  126. data/spec/public/core/merb_core_spec.rb +11 -0
  127. data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
  128. data/spec/public/core_ext/kernel_spec.rb +9 -0
  129. data/spec/public/core_ext/spec_helper.rb +1 -0
  130. data/spec/public/directory_structure/directory/log/merb_test.log +3729 -272
  131. data/spec/public/directory_structure/directory_spec.rb +3 -4
  132. data/spec/public/logger/logger_spec.rb +4 -4
  133. data/spec/public/reloading/directory/log/merb_test.log +288066 -15
  134. data/spec/public/reloading/reload_spec.rb +49 -27
  135. data/spec/public/request/multipart_spec.rb +26 -0
  136. data/spec/public/request/request_spec.rb +21 -2
  137. data/spec/public/router/fixation_spec.rb +27 -0
  138. data/spec/public/router/fixture/log/merb_test.log +30050 -0
  139. data/spec/public/router/nested_matches_spec.rb +97 -0
  140. data/spec/public/router/resource_spec.rb +1 -9
  141. data/spec/public/router/resources_spec.rb +0 -20
  142. data/spec/public/router/spec_helper.rb +27 -9
  143. data/spec/public/router/special_spec.rb +21 -8
  144. data/spec/public/template/template_spec.rb +17 -5
  145. data/spec/public/test/controller_matchers_spec.rb +10 -0
  146. data/spec/public/test/request_helper_spec.rb +29 -0
  147. data/spec/public/test/route_helper_spec.rb +18 -1
  148. data/spec/public/test/route_matchers_spec.rb +28 -1
  149. data/spec/public/test/view_matchers_spec.rb +3 -3
  150. data/spec/spec_helper.rb +56 -12
  151. metadata +89 -47
  152. data/lib/merb-core/core_ext/class.rb +0 -299
  153. data/lib/merb-core/core_ext/hash.rb +0 -426
  154. data/lib/merb-core/core_ext/mash.rb +0 -154
  155. data/lib/merb-core/core_ext/object.rb +0 -147
  156. data/lib/merb-core/core_ext/object_space.rb +0 -14
  157. data/lib/merb-core/core_ext/rubygems.rb +0 -28
  158. data/lib/merb-core/core_ext/set.rb +0 -46
  159. data/lib/merb-core/core_ext/string.rb +0 -89
  160. data/lib/merb-core/core_ext/time.rb +0 -13
  161. data/lib/merb-core/dispatch/exceptions.html.erb +0 -297
  162. data/spec/private/core_ext/class_spec.rb +0 -22
  163. data/spec/private/core_ext/hash_spec.rb +0 -522
  164. data/spec/private/core_ext/object_spec.rb +0 -121
  165. data/spec/private/core_ext/set_spec.rb +0 -26
  166. data/spec/private/core_ext/string_spec.rb +0 -167
  167. data/spec/private/core_ext/time_spec.rb +0 -16
  168. data/spec/private/dispatch/dispatch_spec.rb +0 -26
  169. data/spec/private/dispatch/fixture/log/development.log +0 -1
  170. data/spec/private/dispatch/fixture/log/merb.4000.pid +0 -1
  171. data/spec/private/dispatch/fixture/log/production.log +0 -1
  172. data/spec/private/dispatch/fixture/merb.4000.pid +0 -1
  173. data/spec/private/rack/application_spec.rb +0 -43
  174. data/spec/public/controller/log/merb.4000.pid +0 -1
  175. data/spec/public/directory_structure/directory/log/merb.4000.pid +0 -1
  176. data/spec/public/directory_structure/directory/merb.4000.pid +0 -1
  177. data/spec/public/reloading/directory/log/merb.4000.pid +0 -1
  178. data/spec/public/reloading/directory/merb.4000.pid +0 -1
@@ -5,9 +5,14 @@ module Merb
5
5
  # ==== Returns
6
6
  # Hash::
7
7
  # The configuration loaded from Merb.root / "config/plugins.yml" or, if
8
- # the load fails, an empty hash.
8
+ # the load fails, an empty hash whose default value is another Hash.
9
9
  def self.config
10
- @config ||= File.exists?(Merb.root / "config" / "plugins.yml") ? YAML.load(File.read(Merb.root / "config" / "plugins.yml")) || {} : {}
10
+ @config ||= begin
11
+ # this is so you can do Merb.plugins.config[:helpers][:awesome] = "bar"
12
+ config_hash = Hash.new {|h,k| h[k] = {}}
13
+ file = Merb.root / "config" / "plugins.yml"
14
+ config_hash.merge((File.exists?(file) && YAML.load_file(file)) || {})
15
+ end
11
16
  end
12
17
 
13
18
  # ==== Returns
@@ -15,6 +20,12 @@ module Merb
15
20
  def self.rakefiles
16
21
  Merb.rakefiles
17
22
  end
23
+
24
+ # ==== Returns
25
+ # Array(String):: All Generator load paths Merb uses for plugins.
26
+ def self.generators
27
+ Merb.generators
28
+ end
18
29
 
19
30
  # ==== Parameters
20
31
  # *rakefiles:: Rakefiles to add to the list of plugin Rakefiles.
@@ -31,7 +42,18 @@ module Merb
31
42
  # Merb::Plugins.add_rakefiles "merb_sequel" / "merbtasks"
32
43
  # end
33
44
  def self.add_rakefiles(*rakefiles)
34
- Merb.add_rakefiles *rakefiles
45
+ Merb.add_rakefiles(*rakefiles)
46
+ end
47
+
48
+ # ==== Parameters
49
+ # *generators:: Generator paths to add to the list of plugin generators.
50
+ #
51
+ # ==== Notes
52
+ #
53
+ # This is the recommended way to register your plugin's generators
54
+ # in Merb.
55
+ def self.add_generators(*generators)
56
+ Merb.add_generators(*generators)
35
57
  end
36
58
  end
37
59
  end
@@ -1,15 +1,21 @@
1
1
  require 'rack'
2
- module Merb
2
+ module Merb
3
3
  module Rack
4
- autoload :Application, "merb-core/rack/application"
5
- autoload :Adapter, "merb-core/rack/adapter"
6
- autoload :Ebb, "merb-core/rack/adapter/ebb"
7
- autoload :EventedMongrel, "merb-core/rack/adapter/evented_mongrel"
8
- autoload :FastCGI, "merb-core/rack/adapter/fcgi"
9
- autoload :Irb, "merb-core/rack/adapter/irb"
10
- autoload :Mongrel, "merb-core/rack/adapter/mongrel"
11
- autoload :Runner, "merb-core/rack/adapter/runner"
12
- autoload :Thin, "merb-core/rack/adapter/thin"
13
- autoload :WEBrick, "merb-core/rack/adapter/webrick"
4
+ autoload :Application, 'merb-core' / 'rack' / 'application'
5
+ autoload :Adapter, 'merb-core' / 'rack' / 'adapter'
6
+ autoload :Ebb, 'merb-core' / 'rack' / 'adapter' / 'ebb'
7
+ autoload :EventedMongrel, 'merb-core' / 'rack' / 'adapter' / 'evented_mongrel'
8
+ autoload :FastCGI, 'merb-core' / 'rack' / 'adapter' / 'fcgi'
9
+ autoload :Irb, 'merb-core' / 'rack' / 'adapter' / 'irb'
10
+ autoload :Middleware, 'merb-core' / 'rack' / 'middleware'
11
+ autoload :Mongrel, 'merb-core' / 'rack' / 'adapter' / 'mongrel'
12
+ autoload :Runner, 'merb-core' / 'rack' / 'adapter' / 'runner'
13
+ autoload :SwiftipliedMongrel, 'merb-core' / 'rack' / 'adapter' / 'swiftiplied_mongrel'
14
+ autoload :Thin, 'merb-core' / 'rack' / 'adapter' / 'thin'
15
+ autoload :ThinTurbo, 'merb-core' / 'rack' / 'adapter' / 'thin_turbo'
16
+ autoload :WEBrick, 'merb-core' / 'rack' / 'adapter' / 'webrick'
17
+ autoload :PathPrefix, 'merb-core' / 'rack' / 'middleware' / 'path_prefix'
18
+ autoload :Static, 'merb-core' / 'rack' / 'middleware' / 'static'
19
+ autoload :Profiler, 'merb-core' / 'rack' / 'middleware' / 'profiler'
14
20
  end # Rack
15
- end # Merb
21
+ end # Merb
@@ -28,14 +28,16 @@ module Merb
28
28
  end # Adapter
29
29
 
30
30
  # Register some Rack adapters
31
- Adapter.register %w{ebb}, :Ebb
32
- Adapter.register %w{emongrel}, :EventedMongrel
33
- Adapter.register %w{fastcgi fcgi}, :FastCGI
34
- Adapter.register %w{irb}, :Irb
35
- Adapter.register %w{mongrel}, :Mongrel
36
- Adapter.register %w{runner}, :Runner
37
- Adapter.register %w{thin}, :Thin
38
- Adapter.register %w{webrick}, :WEBrick
31
+ Adapter.register %w{ebb}, :Ebb
32
+ Adapter.register %w{emongrel}, :EventedMongrel
33
+ Adapter.register %w{fastcgi fcgi}, :FastCGI
34
+ Adapter.register %w{irb}, :Irb
35
+ Adapter.register %w{mongrel}, :Mongrel
36
+ Adapter.register %w{runner}, :Runner
37
+ Adapter.register %w{smongrel swift}, :SwiftipliedMongrel
38
+ Adapter.register %w{thin}, :Thin
39
+ Adapter.register %w{thin-turbo}, :ThinTurbo
40
+ Adapter.register %w{webrick}, :WEBrick
39
41
 
40
42
  end # Rack
41
43
  end # Merb
@@ -7,10 +7,10 @@ module Merb
7
7
  # start an Ebb server on given host and port.
8
8
 
9
9
  # ==== Parameters
10
- # opts<Hash>:: Options for Thin (see below).
10
+ # opts<Hash>:: Options for Ebb (see below).
11
11
  #
12
12
  # ==== Options (opts)
13
- # :host<String>:: The hostname that Thin should serve.
13
+ # :host<String>:: The hostname that Ebb should serve.
14
14
  # :port<Fixnum>:: The port Ebb should bind to.
15
15
  # :app:: The application
16
16
  def self.start(opts={})
@@ -9,33 +9,43 @@ module Merb
9
9
  # String:: The generated URL.
10
10
  #
11
11
  # ==== Alternatives
12
- # If name is a hash, it will be merged with params.
12
+ # If name is a hash, it will be merged with params.
13
13
  def url(name, params={})
14
14
  Merb::Router.generate(name, params)
15
15
  end
16
-
16
+
17
17
  # Reloads classes using Merb::BootLoader::ReloadClasses.
18
18
  def reload!
19
19
  Merb::BootLoader::ReloadClasses.reload
20
20
  end
21
-
21
+
22
22
  # Prints all routes for the application.
23
23
  def show_routes
24
24
  seen = []
25
25
  unless Merb::Router.named_routes.empty?
26
- puts "Named Routes"
26
+ puts "==== Named routes"
27
27
  Merb::Router.named_routes.each do |name,route|
28
- puts " #{name}: #{route}"
28
+ # something weird happens when you combine sprintf and irb
29
+ puts "Helper : #{name}"
30
+ meth = $1.upcase if route.conditions[:method].to_s =~ /(get|post|put|delete)/
31
+ puts "HTTP method: #{meth || 'GET'}"
32
+ puts "Route : #{route}"
33
+ puts "Params : #{route.params.inspect}"
34
+ puts
29
35
  seen << route
30
36
  end
31
37
  end
32
- puts "Anonymous Routes"
38
+ puts "==== Anonymous routes"
33
39
  (Merb::Router.routes - seen).each do |route|
34
- puts " #{route}"
40
+ meth = $1.upcase if route.conditions[:method].to_s =~ /(get|post|put|delete)/
41
+ puts "HTTP method: #{meth || 'GET'}"
42
+ puts "Route : #{route}"
43
+ puts "Params : #{route.params.inspect}"
44
+ puts
35
45
  end
36
46
  nil
37
47
  end
38
-
48
+
39
49
  # Starts a sandboxed session (delegates to any Merb::Orms::* modules).
40
50
  #
41
51
  # An ORM should implement Merb::Orms::MyOrm#open_sandbox! to support this.
@@ -45,7 +55,7 @@ module Merb
45
55
  puts "Any modifications you make will be rolled back on exit"
46
56
  orm_modules.each { |orm| orm.open_sandbox! if orm.respond_to?(:open_sandbox!) }
47
57
  end
48
-
58
+
49
59
  # Ends a sandboxed session (delegates to any Merb::Orms::* modules).
50
60
  #
51
61
  # An ORM should implement Merb::Orms::MyOrm#close_sandbox! to support this.
@@ -54,14 +64,14 @@ module Merb
54
64
  orm_modules.each { |orm| orm.close_sandbox! if orm.respond_to?(:close_sandbox!) }
55
65
  puts "Modifications have been rolled back"
56
66
  end
57
-
67
+
58
68
  # Explictly show logger output during IRB session
59
69
  def trace_log!
60
70
  Merb.logger.auto_flush = true
61
71
  end
62
-
72
+
63
73
  private
64
-
74
+
65
75
  # ==== Returns
66
76
  # Array:: All Merb::Orms::* modules.
67
77
  def orm_modules
@@ -71,7 +81,7 @@ module Merb
71
81
  []
72
82
  end
73
83
  end
74
-
84
+
75
85
  end
76
86
 
77
87
  class Irb
@@ -85,11 +95,11 @@ module Merb
85
95
  def self.start(opts={})
86
96
  m = Merb::Rack::Console.new
87
97
  m.extend Merb::Test::RequestHelper
88
- Object.send(:define_method, :merb) { m }
89
- ARGV.clear # Avoid passing args to IRB
98
+ Object.send(:define_method, :merb) { m }
99
+ ARGV.clear # Avoid passing args to IRB
90
100
  m.open_sandbox! if sandboxed?
91
- require 'irb'
92
- require 'irb/completion'
101
+ require 'irb'
102
+ require 'irb/completion'
93
103
  if File.exists? ".irbrc"
94
104
  ENV['IRBRC'] = ".irbrc"
95
105
  end
@@ -97,12 +107,12 @@ module Merb
97
107
  at_exit do merb.close_sandbox! if sandboxed? end
98
108
  exit
99
109
  end
100
-
110
+
101
111
  private
102
-
112
+
103
113
  def self.sandboxed?
104
114
  Merb::Config[:sandbox]
105
- end
115
+ end
106
116
  end
107
117
  end
108
- end
118
+ end
@@ -0,0 +1,26 @@
1
+ require 'swiftcore/swiftiplied_mongrel'
2
+ require 'merb-core/rack/handler/mongrel'
3
+ module Merb
4
+ module Rack
5
+
6
+ class SwiftipliedMongrel < Mongrel
7
+ # Starts Mongrel as swift.
8
+ #
9
+ # ==== Parameters
10
+ # opts<Hash>:: Options for Mongrel (see below).
11
+ #
12
+ # ==== Options (opts)
13
+ # :host<String>:: The hostname that Mongrel should serve.
14
+ # :port<Fixnum>:: The port Mongrel should bind to.
15
+ # :app<String>>:: The application name.
16
+ def self.start(opts={})
17
+ Merb.logger.warn!("Using SwiftipliedMongrel adapter")
18
+ Merb::Dispatcher.use_mutex = false
19
+ server = ::Mongrel::HttpServer.new(opts[:host], opts[:port].to_i)
20
+ Merb::Server.change_privilege
21
+ server.register('/', ::Merb::Rack::Handler::Mongrel.new(opts[:app]))
22
+ server.run.join
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,28 +1,38 @@
1
- require 'thin'
1
+ require "thin"
2
+
2
3
  module Merb
3
-
4
+
4
5
  module Rack
5
6
 
6
7
  class Thin
7
8
  # start a Thin server on given host and port.
8
-
9
+
9
10
  # ==== Parameters
10
11
  # opts<Hash>:: Options for Thin (see below).
11
12
  #
12
13
  # ==== Options (opts)
13
14
  # :host<String>:: The hostname that Thin should serve.
14
15
  # :port<Fixnum>:: The port Thin should bind to.
16
+ # :socket<Fixnum>>:: The socket number that thin should bind to.
17
+ # :socket_file<String>>:: The socket file that thin should attach to.
15
18
  # :app<String>>:: The application name.
16
19
  def self.start(opts={})
17
- Merb.logger.warn!("Using Thin adapter")
18
20
  Merb::Dispatcher.use_mutex = false
19
- if opts[:host].include?('/')
20
- opts[:host] = "#{opts[:host]}-#{opts[:port]}"
21
- end
22
- server = ::Thin::Server.start(opts[:host], opts[:port].to_i, opts[:app])
21
+ if opts[:socket] || opts[:socket_file]
22
+ socket = opts[:socket] || "0"
23
+ socket_file = opts[:socket_file] || "#{Merb.root}/log/merb.#{socket}.sock"
24
+ Merb.logger.warn!("Using Thin adapter with socket file #{socket_file}.")
25
+ server = ::Thin::Server.new(socket_file, opts[:app], opts)
26
+ else
27
+ Merb.logger.warn!("Using Thin adapter on host #{opts[:host]} and port #{opts[:port]}.")
28
+ if opts[:host].include?('/')
29
+ opts[:host] = "#{opts[:host]}-#{opts[:port]}"
30
+ end
31
+ server = ::Thin::Server.new(opts[:host], opts[:port].to_i, opts[:app], opts)
32
+ end
23
33
  Merb::Server.change_privilege
24
34
  ::Thin::Logging.silent = true
25
- server.start!
35
+ server.start
26
36
  end
27
37
  end
28
38
  end
@@ -0,0 +1,24 @@
1
+ require "thin-turbo"
2
+
3
+ module Merb
4
+
5
+ module Rack
6
+
7
+ class ThinTurbo < Thin
8
+ # start a Thin Turbo server on given host and port.
9
+
10
+ # ==== Parameters
11
+ # opts<Hash>:: Options for Thin Turbo (see below).
12
+ #
13
+ # ==== Options (opts)
14
+ # :host<String>:: The hostname that Thin Turbo should serve.
15
+ # :port<Fixnum>:: The port Thin Turbo should bind to.
16
+ # :socket<Fixnum>>:: The socket number that thin should bind to.
17
+ # :socket_file<String>>:: The socket file that thin should attach to.
18
+ # :app<String>>:: The application name.
19
+ def self.start(opts={})
20
+ super(opts.merge(:backend => ::Thin::Backends::Turbo))
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,93 +1,18 @@
1
- module Merb
2
-
1
+ module Merb
3
2
  module Rack
4
-
5
3
  class Application
6
- # ==== Parameters
7
- # options<Hash>::
8
- # Options for creating a new application. Currently ignored.
9
- def initialize(options={})
10
- @static_server = ::Rack::File.new Merb.dir_for(:public)
11
- if prefix = ::Merb::Config[:path_prefix]
12
- @path_prefix = /^#{Regexp.escape(prefix)}/
13
- end
14
- end
15
4
 
16
- # ==== Parameters
17
- # env<Hash>:: Environment variables to pass on to the application.
18
- #
19
- # ==== Returns
20
- # true or false::
21
- def deferred?(env)
22
- strip_path_prefix(env) if @path_prefix # Strip out the path_prefix if one was set
23
- path = env['PATH_INFO'] ? env['PATH_INFO'].chomp('/') : ""
24
- if path =~ Merb.deferred_actions
25
- Merb.logger.info! "Deferring Request: #{path}"
26
- true
27
- else
28
- false
29
- end
30
- end
31
-
32
- # ==== Parameters
33
- # env<Hash>:: Environment variables to pass on to the application.
34
- #
35
- # ==== Returns
36
- # Array[Array]::
37
- # A 3 element tuple consisting of response status, headers and body.
38
5
  def call(env)
39
- strip_path_prefix(env) if @path_prefix # Strip out the path_prefix if one was set
40
- path = env['PATH_INFO'] ? env['PATH_INFO'].chomp('/') : ""
41
- cached_path = (path.empty? ? 'index' : path) + '.html'
42
- Merb.logger.info "Request: #{path}"
43
- if file_exist?(path) && env['REQUEST_METHOD'] =~ /GET|HEAD/ # Serve the file if it's there and the request method is GET or HEAD
44
- serve_static(env)
45
- elsif file_exist?(cached_path) && env['REQUEST_METHOD'] =~ /GET|HEAD/ # Serve the page cache if it's there and the request method is GET or HEAD
46
- env['PATH_INFO'] = cached_path
47
- serve_static(env)
48
- else # No static file, let Merb handle it
49
- if path =~ /favicon\.ico/
50
- return [404, {"Content-Type"=>"text/html"}, "404 Not Found."]
51
- end
52
- begin
53
- controller = ::Merb::Dispatcher.handle(env)
54
- rescue Object => e
55
- return [500, {"Content-Type"=>"text/html"}, e.message + "<br/>" + e.backtrace.join("<br/>")]
56
- end
57
- Merb.logger.info "\n\n"
58
- Merb.logger.flush
59
- [controller.status, controller.headers, controller.body]
60
- end
61
- end
62
-
63
- # ==== Parameters
64
- # path<String>:: The path to the file relative to the server root.
65
- #
66
- # ==== Returns
67
- # Boolean:: True if file exists under the server root and is readable.
68
- def file_exist?(path)
69
- full_path = ::File.join(@static_server.root, ::Merb::Request.unescape(path))
70
- ::File.file?(full_path) && ::File.readable?(full_path)
71
- end
72
-
73
- # ==== Parameters
74
- # env<Hash>:: Environment variables to pass on to the server.
75
- def serve_static(env)
76
- env["PATH_INFO"] = ::Merb::Request.unescape(env["PATH_INFO"])
77
- @static_server.call(env)
78
- end
79
-
80
- # ==== Parameters
81
- # env<Hash>:: Environment variables to pass on to the server.
82
- def strip_path_prefix(env)
83
- ['PATH_INFO', 'REQUEST_URI'].each do |path_key|
84
- if env[path_key] =~ @path_prefix
85
- env[path_key].sub!(@path_prefix, '')
86
- env[path_key] = '/' if env[path_key].empty?
87
- end
6
+ begin
7
+ controller = ::Merb::Dispatcher.handle(Merb::Request.new(env))
8
+ rescue Object => e
9
+ return [500, {"Content-Type"=>"text/html"}, e.message + "<br/>" + e.backtrace.join("<br/>")]
88
10
  end
11
+ Merb.logger.info "\n\n"
12
+ Merb.logger.flush
13
+ controller.rack_response
89
14
  end
90
15
 
91
16
  end
92
17
  end
93
- end
18
+ end
@@ -0,0 +1,26 @@
1
+ module Merb
2
+ module Rack
3
+ class Middleware
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def deferred?(env)
10
+ path = env['PATH_INFO'] ? env['PATH_INFO'].chomp('/') : ""
11
+ if path =~ Merb.deferred_actions
12
+ Merb.logger.info! "Deferring Request: #{path}"
13
+ true
14
+ else
15
+ false
16
+ end
17
+ end
18
+
19
+ def call(env)
20
+ @app.call(env)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+