merb 0.5.3 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (294) hide show
  1. data/LICENSE +0 -20
  2. data/README +0 -277
  3. data/Rakefile +80 -199
  4. data/TODO +0 -3
  5. metadata +19 -438
  6. data/SVN_REVISION +0 -1
  7. data/app_generators/merb/USAGE +0 -5
  8. data/app_generators/merb/merb_generator.rb +0 -108
  9. data/app_generators/merb/templates/Rakefile +0 -124
  10. data/app_generators/merb/templates/app/controllers/application.rb +0 -3
  11. data/app_generators/merb/templates/app/controllers/exceptions.rb +0 -13
  12. data/app_generators/merb/templates/app/helpers/global_helper.rb +0 -5
  13. data/app_generators/merb/templates/app/mailers/views/layout/application.html.erb +0 -1
  14. data/app_generators/merb/templates/app/mailers/views/layout/application.text.erb +0 -1
  15. data/app_generators/merb/templates/app/parts/views/layout/application.html.erb +0 -1
  16. data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +0 -216
  17. data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +0 -38
  18. data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +0 -40
  19. data/app_generators/merb/templates/app/views/layout/application.html.erb +0 -11
  20. data/app_generators/merb/templates/config/boot.rb +0 -11
  21. data/app_generators/merb/templates/config/dependencies.rb +0 -41
  22. data/app_generators/merb/templates/config/environments/development.rb +0 -1
  23. data/app_generators/merb/templates/config/environments/production.rb +0 -1
  24. data/app_generators/merb/templates/config/environments/test.rb +0 -1
  25. data/app_generators/merb/templates/config/merb.yml +0 -82
  26. data/app_generators/merb/templates/config/merb_init.rb +0 -17
  27. data/app_generators/merb/templates/config/plugins.yml +0 -1
  28. data/app_generators/merb/templates/config/router.rb +0 -35
  29. data/app_generators/merb/templates/config/upload.conf +0 -0
  30. data/app_generators/merb/templates/public/images/merb.jpg +0 -0
  31. data/app_generators/merb/templates/public/merb.fcgi +0 -6
  32. data/app_generators/merb/templates/public/stylesheets/master.css +0 -119
  33. data/app_generators/merb/templates/script/destroy +0 -32
  34. data/app_generators/merb/templates/script/generate +0 -32
  35. data/app_generators/merb/templates/script/stop_merb +0 -13
  36. data/app_generators/merb/templates/script/win_script.cmd +0 -1
  37. data/app_generators/merb/templates/spec/spec.opts +0 -6
  38. data/app_generators/merb/templates/spec/spec_helper.rb +0 -15
  39. data/app_generators/merb/templates/test/test_helper.rb +0 -14
  40. data/app_generators/merb_plugin/USAGE +0 -5
  41. data/app_generators/merb_plugin/merb_plugin_generator.rb +0 -68
  42. data/app_generators/merb_plugin/templates/LICENSE +0 -20
  43. data/app_generators/merb_plugin/templates/README +0 -4
  44. data/app_generators/merb_plugin/templates/Rakefile +0 -35
  45. data/app_generators/merb_plugin/templates/TODO +0 -5
  46. data/app_generators/merb_plugin/templates/merbtasks.rb +0 -6
  47. data/app_generators/merb_plugin/templates/sampleplugin.rb +0 -10
  48. data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +0 -7
  49. data/app_generators/merb_plugin/templates/spec_helper.rb +0 -2
  50. data/bin/merb +0 -4
  51. data/lib/autotest/discover.rb +0 -3
  52. data/lib/autotest/merb_rspec.rb +0 -80
  53. data/lib/merb.rb +0 -188
  54. data/lib/merb/abstract_controller.rb +0 -399
  55. data/lib/merb/assets.rb +0 -160
  56. data/lib/merb/assets.rb.orig +0 -119
  57. data/lib/merb/boot_loader.rb +0 -286
  58. data/lib/merb/boot_loader.rb.orig +0 -235
  59. data/lib/merb/caching.rb +0 -5
  60. data/lib/merb/caching/action_cache.rb +0 -92
  61. data/lib/merb/caching/fragment_cache.rb +0 -39
  62. data/lib/merb/caching/store/file_cache.rb +0 -90
  63. data/lib/merb/caching/store/memory_cache.rb +0 -85
  64. data/lib/merb/config.rb +0 -290
  65. data/lib/merb/constants.rb +0 -50
  66. data/lib/merb/controller.rb +0 -220
  67. data/lib/merb/cookies.rb +0 -95
  68. data/lib/merb/core_ext.rb +0 -15
  69. data/lib/merb/core_ext/array.rb +0 -0
  70. data/lib/merb/core_ext/class.rb +0 -180
  71. data/lib/merb/core_ext/enumerable.rb +0 -49
  72. data/lib/merb/core_ext/get_args.rb +0 -76
  73. data/lib/merb/core_ext/hash.rb +0 -306
  74. data/lib/merb/core_ext/inflections.rb +0 -112
  75. data/lib/merb/core_ext/inflector.rb +0 -275
  76. data/lib/merb/core_ext/kernel.rb +0 -242
  77. data/lib/merb/core_ext/mash.rb +0 -88
  78. data/lib/merb/core_ext/module.rb +0 -67
  79. data/lib/merb/core_ext/numeric.rb +0 -72
  80. data/lib/merb/core_ext/object.rb +0 -183
  81. data/lib/merb/core_ext/string.rb +0 -53
  82. data/lib/merb/core_ext/symbol.rb +0 -6
  83. data/lib/merb/dispatcher.rb +0 -109
  84. data/lib/merb/drb_server.rb +0 -19
  85. data/lib/merb/erubis_ext.rb +0 -10
  86. data/lib/merb/exceptions.rb +0 -192
  87. data/lib/merb/generators/merb_app/merb_app.rb +0 -22
  88. data/lib/merb/generators/merb_generator_helpers.rb +0 -318
  89. data/lib/merb/generators/merb_plugin.rb +0 -22
  90. data/lib/merb/logger.rb +0 -78
  91. data/lib/merb/mail_controller.rb +0 -268
  92. data/lib/merb/mailer.rb +0 -87
  93. data/lib/merb/mixins/basic_authentication.rb +0 -35
  94. data/lib/merb/mixins/controller.rb +0 -160
  95. data/lib/merb/mixins/erubis_capture.rb +0 -68
  96. data/lib/merb/mixins/general_controller.rb +0 -253
  97. data/lib/merb/mixins/inline_partial.rb +0 -32
  98. data/lib/merb/mixins/render.rb +0 -465
  99. data/lib/merb/mixins/responder.rb +0 -449
  100. data/lib/merb/mixins/view_context.rb +0 -558
  101. data/lib/merb/mixins/web_controller.rb +0 -36
  102. data/lib/merb/mongrel_handler.rb +0 -168
  103. data/lib/merb/part_controller.rb +0 -29
  104. data/lib/merb/plugins.rb +0 -16
  105. data/lib/merb/rack_adapter.rb +0 -37
  106. data/lib/merb/request.rb +0 -465
  107. data/lib/merb/router.rb +0 -646
  108. data/lib/merb/server.rb +0 -169
  109. data/lib/merb/session.rb +0 -23
  110. data/lib/merb/session/cookie_store.rb +0 -118
  111. data/lib/merb/session/mem_cache_session.rb +0 -131
  112. data/lib/merb/session/memory_session.rb +0 -176
  113. data/lib/merb/template.rb +0 -37
  114. data/lib/merb/template/erubis.rb +0 -68
  115. data/lib/merb/template/haml.rb +0 -87
  116. data/lib/merb/template/markaby.rb +0 -59
  117. data/lib/merb/template/xml_builder.rb +0 -50
  118. data/lib/merb/test/fake_request.rb +0 -74
  119. data/lib/merb/test/helper.rb +0 -260
  120. data/lib/merb/test/hpricot.rb +0 -136
  121. data/lib/merb/test/multipart.rb +0 -66
  122. data/lib/merb/test/rspec.rb +0 -18
  123. data/lib/merb/test/rspec_matchers/controller_matchers.rb +0 -117
  124. data/lib/merb/test/rspec_matchers/markup_matchers.rb +0 -98
  125. data/lib/merb/upload_handler.rb +0 -80
  126. data/lib/merb/upload_progress.rb +0 -48
  127. data/lib/merb/version.rb +0 -49
  128. data/lib/merb/view_context.rb +0 -79
  129. data/lib/tasks.rb +0 -7
  130. data/lib/tasks/merb.rake +0 -54
  131. data/merb_default_generators/model/USAGE +0 -0
  132. data/merb_default_generators/model/model_generator.rb +0 -16
  133. data/merb_default_generators/model/templates/new_model_template.erb +0 -5
  134. data/merb_default_generators/resource_controller/USAGE +0 -0
  135. data/merb_default_generators/resource_controller/resource_controller_generator.rb +0 -26
  136. data/merb_default_generators/resource_controller/templates/controller.rb +0 -30
  137. data/merb_default_generators/resource_controller/templates/edit.html.erb +0 -1
  138. data/merb_default_generators/resource_controller/templates/helper.rb +0 -5
  139. data/merb_default_generators/resource_controller/templates/index.html.erb +0 -1
  140. data/merb_default_generators/resource_controller/templates/new.html.erb +0 -1
  141. data/merb_default_generators/resource_controller/templates/show.html.erb +0 -1
  142. data/merb_generators/controller/USAGE +0 -5
  143. data/merb_generators/controller/controller_generator.rb +0 -16
  144. data/merb_generators/controller/templates/controller.rb +0 -8
  145. data/merb_generators/controller/templates/helper.rb +0 -5
  146. data/merb_generators/controller/templates/index.html.erb +0 -3
  147. data/merb_generators/part_controller/USAGE +0 -5
  148. data/merb_generators/part_controller/part_controller_generator.rb +0 -27
  149. data/merb_generators/part_controller/templates/controller.rb +0 -8
  150. data/merb_generators/part_controller/templates/helper.rb +0 -5
  151. data/merb_generators/part_controller/templates/index.html.erb +0 -3
  152. data/merb_generators/resource/USAGE +0 -0
  153. data/merb_generators/resource/resource_generator.rb +0 -67
  154. data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +0 -67
  155. data/rspec_generators/merb_controller_test/templates/controller_spec.rb +0 -8
  156. data/rspec_generators/merb_controller_test/templates/edit_spec.rb +0 -12
  157. data/rspec_generators/merb_controller_test/templates/helper_spec.rb +0 -5
  158. data/rspec_generators/merb_controller_test/templates/index_spec.rb +0 -12
  159. data/rspec_generators/merb_controller_test/templates/new_spec.rb +0 -12
  160. data/rspec_generators/merb_controller_test/templates/show_spec.rb +0 -5
  161. data/rspec_generators/merb_model_test/merb_model_test_generator.rb +0 -26
  162. data/rspec_generators/merb_model_test/templates/model_spec_template.erb +0 -7
  163. data/script/destroy +0 -14
  164. data/script/generate +0 -14
  165. data/spec/fixtures/config/environments/environment_config_test.yml +0 -1
  166. data/spec/fixtures/config/merb.yml +0 -18
  167. data/spec/fixtures/controllers/dispatch_spec_controllers.rb +0 -235
  168. data/spec/fixtures/controllers/render_spec_controllers.rb +0 -184
  169. data/spec/fixtures/foo.rb +0 -3
  170. data/spec/fixtures/mailers/views/layout/application.html.erb +0 -3
  171. data/spec/fixtures/mailers/views/layout/application.text.erb +0 -3
  172. data/spec/fixtures/mailers/views/test_mail_controller/eighth.html.erb +0 -1
  173. data/spec/fixtures/mailers/views/test_mail_controller/eighth.text.erb +0 -1
  174. data/spec/fixtures/mailers/views/test_mail_controller/first.html.erb +0 -1
  175. data/spec/fixtures/mailers/views/test_mail_controller/first.text.erb +0 -1
  176. data/spec/fixtures/mailers/views/test_mail_controller/ninth.html.erb +0 -1
  177. data/spec/fixtures/mailers/views/test_mail_controller/ninth.text.erb +0 -1
  178. data/spec/fixtures/mailers/views/test_mail_controller/second.text.erb +0 -1
  179. data/spec/fixtures/mailers/views/test_mail_controller/third.html.erb +0 -1
  180. data/spec/fixtures/models/router_spec_models.rb +0 -30
  181. data/spec/fixtures/parts/views/layout/todo_part.html.erb +0 -3
  182. data/spec/fixtures/parts/views/layout/todo_part.xml.erb +0 -3
  183. data/spec/fixtures/parts/views/todo_part/formatted_output.html.erb +0 -1
  184. data/spec/fixtures/parts/views/todo_part/formatted_output.js.erb +0 -1
  185. data/spec/fixtures/parts/views/todo_part/formatted_output.xml.erb +0 -1
  186. data/spec/fixtures/parts/views/todo_part/list.html.erb +0 -3
  187. data/spec/fixtures/sample.txt +0 -1
  188. data/spec/fixtures/views/erubis.html.erb +0 -1
  189. data/spec/fixtures/views/examples/_erubis.html.erb +0 -1
  190. data/spec/fixtures/views/examples/_haml.html.haml +0 -1
  191. data/spec/fixtures/views/examples/_markaby.html.mab +0 -1
  192. data/spec/fixtures/views/examples/_throw_content.html.erb +0 -6
  193. data/spec/fixtures/views/examples/hello.xml.builder +0 -1
  194. data/spec/fixtures/views/examples/js.js.erb +0 -1
  195. data/spec/fixtures/views/examples/template_catch_content.html.erb +0 -15
  196. data/spec/fixtures/views/examples/template_catch_content_from_partial.html.erb +0 -6
  197. data/spec/fixtures/views/examples/template_throw_content.html.erb +0 -10
  198. data/spec/fixtures/views/examples/template_throw_content_without_block.html.erb +0 -3
  199. data/spec/fixtures/views/exceptions/admin_access_required.html.erb +0 -1
  200. data/spec/fixtures/views/extension_template_controller/_nested_js.js.erb +0 -1
  201. data/spec/fixtures/views/extension_template_controller/_nested_xml.xml.erb +0 -1
  202. data/spec/fixtures/views/extension_template_controller/_render_partial_multiple_times.html.erb +0 -1
  203. data/spec/fixtures/views/extension_template_controller/erubis_templates.html.erb +0 -1
  204. data/spec/fixtures/views/extension_template_controller/erubis_templates.js.erb +0 -1
  205. data/spec/fixtures/views/extension_template_controller/erubis_templates.rhtml +0 -1
  206. data/spec/fixtures/views/extension_template_controller/erubis_templates.xml.erb +0 -1
  207. data/spec/fixtures/views/extension_template_controller/haml_index.html.haml +0 -0
  208. data/spec/fixtures/views/extension_template_controller/haml_templates.html.haml +0 -1
  209. data/spec/fixtures/views/extension_template_controller/haml_templates.js.haml +0 -1
  210. data/spec/fixtures/views/extension_template_controller/haml_templates.xml.haml +0 -1
  211. data/spec/fixtures/views/extension_template_controller/index.html.erb +0 -0
  212. data/spec/fixtures/views/extension_template_controller/markaby_index.html.mab +0 -0
  213. data/spec/fixtures/views/extension_template_controller/markaby_templates.html.mab +0 -1
  214. data/spec/fixtures/views/extension_template_controller/markaby_templates.js.mab +0 -1
  215. data/spec/fixtures/views/extension_template_controller/markaby_templates.xml.mab +0 -1
  216. data/spec/fixtures/views/extension_template_controller/render_multiple_partials.html.erb +0 -4
  217. data/spec/fixtures/views/extension_template_controller/render_nested_js.js.erb +0 -1
  218. data/spec/fixtures/views/extension_template_controller/render_nested_xml.xml.erb +0 -1
  219. data/spec/fixtures/views/haml.html.haml +0 -1
  220. data/spec/fixtures/views/haml.xml.haml +0 -2
  221. data/spec/fixtures/views/layout/application.html.erb +0 -1
  222. data/spec/fixtures/views/layout/application.xml.erb +0 -1
  223. data/spec/fixtures/views/layout/nested/example.html.erb +0 -1
  224. data/spec/fixtures/views/markaby.html.mab +0 -1
  225. data/spec/fixtures/views/nested/example/test.html.erb +0 -1
  226. data/spec/fixtures/views/partials/_erubis.html.erb +0 -1
  227. data/spec/fixtures/views/partials/_erubis_collection.html.erb +0 -1
  228. data/spec/fixtures/views/partials/_erubis_collection_with_locals.html.erb +0 -1
  229. data/spec/fixtures/views/partials/_erubis_new.html.erb +0 -1
  230. data/spec/fixtures/views/partials/_haml.html.haml +0 -1
  231. data/spec/fixtures/views/partials/_haml_collection.html.haml +0 -1
  232. data/spec/fixtures/views/partials/_haml_collection_with_locals.html.haml +0 -1
  233. data/spec/fixtures/views/partials/_haml_new.html.haml +0 -1
  234. data/spec/fixtures/views/partials/_markaby.html.mab +0 -1
  235. data/spec/fixtures/views/partials/_markaby_collection.html.mab +0 -1
  236. data/spec/fixtures/views/partials/_markaby_collection_with_locals.html.mab +0 -1
  237. data/spec/fixtures/views/partials/_markaby_new.html.mab +0 -1
  238. data/spec/fixtures/views/render_object_controller/render_object_with_template.html.erb +0 -1
  239. data/spec/fixtures/views/render_object_controller/render_object_with_template.js.erb +0 -1
  240. data/spec/fixtures/views/render_object_controller/render_object_with_template.xml.erb +0 -1
  241. data/spec/fixtures/views/template_views/interface__buffer_erubis.html.erb +0 -4
  242. data/spec/fixtures/views/template_views/interface__buffer_haml.html.haml +0 -7
  243. data/spec/fixtures/views/template_views/interface__buffer_markaby.html.mab +0 -7
  244. data/spec/fixtures/views/template_views/interface_capture_erubis.html.erb +0 -15
  245. data/spec/fixtures/views/template_views/interface_capture_haml.html.haml +0 -15
  246. data/spec/fixtures/views/template_views/interface_capture_markaby.html.mab +0 -4
  247. data/spec/fixtures/views/template_views/interface_concat_erubis.html.erb +0 -12
  248. data/spec/fixtures/views/template_views/interface_concat_haml.html.haml +0 -11
  249. data/spec/fixtures/views/template_views/interface_concat_markaby.html.mab +0 -14
  250. data/spec/fixtures/views/test.dir/the_template.html.erb +0 -1
  251. data/spec/merb/abstract_controller_spec.rb +0 -38
  252. data/spec/merb/assets_spec.rb +0 -207
  253. data/spec/merb/caching_spec.rb +0 -102
  254. data/spec/merb/config_spec.rb +0 -29
  255. data/spec/merb/controller_filters_spec.rb +0 -253
  256. data/spec/merb/controller_spec.rb +0 -126
  257. data/spec/merb/cookie_store_spec.rb +0 -72
  258. data/spec/merb/cookies_spec.rb +0 -96
  259. data/spec/merb/core_ext/class_spec.rb +0 -97
  260. data/spec/merb/core_ext/enumerable_spec.rb +0 -27
  261. data/spec/merb/core_ext/hash_spec.rb +0 -251
  262. data/spec/merb/core_ext/inflector_spec.rb +0 -34
  263. data/spec/merb/core_ext/kernel_spec.rb +0 -25
  264. data/spec/merb/core_ext/numeric_spec.rb +0 -26
  265. data/spec/merb/core_ext/object_spec.rb +0 -47
  266. data/spec/merb/core_ext/string_spec.rb +0 -22
  267. data/spec/merb/core_ext/symbol_spec.rb +0 -7
  268. data/spec/merb/dependency_spec.rb +0 -22
  269. data/spec/merb/dispatch_spec.rb +0 -528
  270. data/spec/merb/fake_request_spec.rb +0 -80
  271. data/spec/merb/generator_spec.rb +0 -248
  272. data/spec/merb/handler_spec.rb +0 -169
  273. data/spec/merb/mail_controller_spec.rb +0 -177
  274. data/spec/merb/mailer_spec.rb +0 -87
  275. data/spec/merb/multipart_spec.rb +0 -50
  276. data/spec/merb/part_controller_spec.rb +0 -124
  277. data/spec/merb/plugins_spec.rb +0 -80
  278. data/spec/merb/render_spec.rb +0 -469
  279. data/spec/merb/request_spec.rb +0 -287
  280. data/spec/merb/responder_spec.rb +0 -562
  281. data/spec/merb/router_spec.rb +0 -900
  282. data/spec/merb/server_spec.rb +0 -19
  283. data/spec/merb/template_spec.rb +0 -41
  284. data/spec/merb/upload_handler_spec.rb +0 -108
  285. data/spec/merb/version_spec.rb +0 -33
  286. data/spec/merb/view_context_spec.rb +0 -366
  287. data/spec/spec_generator_helper.rb +0 -34
  288. data/spec/spec_helper.rb +0 -101
  289. data/spec/spec_helpers/url_shared_behaviour.rb +0 -112
  290. data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +0 -53
  291. data/test_unit_generators/merb_controller_test/templates/functional_test.rb +0 -17
  292. data/test_unit_generators/merb_controller_test/templates/helper_test.rb +0 -9
  293. data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +0 -29
  294. data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +0 -9
data/lib/merb/server.rb DELETED
@@ -1,169 +0,0 @@
1
- require 'rubygems'
2
-
3
- # Make the app's "gems" directory a place where gems are loaded from
4
- # This needs to go here for using in a shared envirionment where Erubis may not
5
- # be available
6
- if File.exists?(File.join(Dir.pwd, "gems")) && File.directory?(File.join(Dir.pwd,"gems"))
7
- Gem.clear_paths
8
- Gem.path.unshift(File.join(Dir.pwd,"gems"))
9
- end
10
-
11
-
12
- require 'optparse'
13
- require 'ostruct'
14
- require 'fileutils'
15
- require 'yaml'
16
-
17
- # this is so we can test for HAML features for HAML partial inlining
18
- unless Gem.cache.search("haml").empty?
19
- gem "haml"
20
- require "haml"
21
- end
22
-
23
- require File.join(File.dirname(__FILE__), 'config')
24
-
25
- module Merb
26
-
27
- class Server
28
-
29
- class << self
30
-
31
- def run
32
- ::Merb::Config.parse_args
33
-
34
- if Merb::Config[:cluster]
35
- Merb::Config[:port].to_i.upto(Merb::Config[:port].to_i+Merb::Config[:cluster].to_i-1) do |port|
36
- unless alive?(port)
37
- delete_pidfiles(port)
38
- puts "Starting merb server on port: #{port}"
39
- start(port)
40
- else
41
- raise "Merb is already running on port: #{port}"
42
- end
43
- end
44
- elsif Merb::Config[:daemonize]
45
- unless alive?(Merb::Config[:port])
46
- delete_pidfiles(Merb::Config[:port])
47
- start(Merb::Config[:port])
48
- else
49
- raise "Merb is already running on port: #{port}"
50
- end
51
- else
52
- trap('TERM') { exit }
53
- mongrel_start(Merb::Config[:port])
54
- end
55
-
56
- end
57
-
58
- def store_pid(pid,port)
59
- File.open("#{Merb::Config[:merb_root]}/log/merb.#{port}.pid", 'w'){|f| f.write("#{Process.pid}\n")}
60
- end
61
-
62
- def alive?(port)
63
- f = Merb::Config[:merb_root] + "/log/merb.#{port}.pid"
64
- pid = IO.read(f).chomp.to_i
65
- Process.kill(0, pid)
66
- true
67
- rescue
68
- false
69
- end
70
-
71
- def kill(ports, sig=9)
72
- begin
73
- Dir[Merb::Config[:merb_root] + "/log/merb.#{ports == 'all' ? '*' : ports }.pid"].each do |f|
74
- pid = IO.read(f).chomp.to_i
75
- Process.kill(sig, pid)
76
- FileUtils.rm f
77
- puts "killed PID #{pid} with signal #{sig}"
78
- end
79
- rescue
80
- puts "Failed to kill! #{k}"
81
- ensure
82
- exit
83
- end
84
- end
85
-
86
- def start(port,what=:mongrel_start)
87
- fork do
88
- Process.setsid
89
- exit if fork
90
- File.umask 0000
91
- STDIN.reopen "/dev/null"
92
- STDOUT.reopen "/dev/null", "a"
93
- STDERR.reopen STDOUT
94
- trap("TERM") { exit }
95
- Dir.chdir Merb::Config[:merb_root]
96
- send(what, port)
97
- end
98
- end
99
-
100
- def webrick_start(port)
101
- Merb::BootLoader.initialize_merb
102
- store_pid(Process.pid, port)
103
- require 'rack'
104
- require 'merb/rack_adapter'
105
- ::Rack::Handler::WEBrick.run Merb::Rack::Adapter.new,
106
- :Port => port
107
- end
108
-
109
- def fastcgi_start
110
- Merb::BootLoader.initialize_merb
111
- require 'rack'
112
- require 'merb/rack_adapter'
113
- ::Rack::Handler::FastCGI.run Merb::Rack::Adapter.new
114
- end
115
-
116
- def delete_pidfiles(portor_star='*')
117
- Dir["#{Merb::Config[:merb_root]}/log/merb.#{portor_star}.pid"].each do |pid|
118
- FileUtils.rm(pid) rescue nil
119
- end
120
- end
121
-
122
- def drbserver_start(port)
123
- puts "Starting merb drb server on port: #{port}"
124
- require 'merb/drb_server'
125
- Merb::BootLoader.initialize_merb
126
- store_pid(Process.pid, "drb.#{port}")
127
- drb_init = File.join(Merb.root, "/config/drb_init")
128
- require drb_init if File.exist?(drb_init)
129
- DRb.start_service("druby://#{Merb::Config[:host]}:#{port}", Merb::DrbServiceProvider)
130
- DRb.thread.join
131
- end
132
-
133
- def mongrel_start(port)
134
- store_pid(Process.pid, port)
135
- Merb::Config[:port] = port
136
- unless Merb::Config[:generate] || Merb::Config[:console] || Merb::Config[:only_drb] || Merb::Config[:kill]
137
- puts %{Merb started with these options:}
138
- puts Merb::Config.to_yaml; puts
139
- end
140
- Merb::BootLoader.initialize_merb
141
-
142
- mconf_hash = {:host => (Merb::Config[:host]||"0.0.0.0"), :port => (port ||4000)}
143
- if Merb::Config[:user] and Merb::Config[:group]
144
- mconf_hash[:user] = Merb::Config[:user]
145
- mconf_hash[:group] = Merb::Config[:group]
146
- end
147
- mconfig = Mongrel::Configurator.new(mconf_hash) do
148
- listener do
149
- uri( "/", :handler => MerbUploadHandler.new(Merb::Config), :in_front => true) if Merb::Config[:upload_path_match]
150
- uri "/", :handler => MerbHandler.new(Merb.root+'/public', Merb::Config[:mongrel_x_sendfile])
151
- uri "/favicon.ico", :handler => Mongrel::Error404Handler.new("")
152
- end
153
- MerbHandler.path_prefix = Merb::Config[:path_prefix]
154
-
155
- trap("INT") { stop }
156
- run
157
- end
158
- mconfig.join
159
- end
160
-
161
- def config
162
- Merb::Config
163
- end
164
-
165
- end # class << self
166
-
167
- end # Server
168
-
169
- end # Merb
data/lib/merb/session.rb DELETED
@@ -1,23 +0,0 @@
1
- module Merb
2
- module SessionMixin
3
-
4
- def rand_uuid
5
- values = [
6
- rand(0x0010000),
7
- rand(0x0010000),
8
- rand(0x0010000),
9
- rand(0x0010000),
10
- rand(0x0010000),
11
- rand(0x1000000),
12
- rand(0x1000000),
13
- ]
14
- "%04x%04x%04x%04x%04x%06x%06x" % values
15
- end
16
-
17
- def needs_new_cookie!
18
- @_new_cookie = true
19
- end
20
-
21
- module_function :rand_uuid, :needs_new_cookie!
22
- end
23
- end
@@ -1,118 +0,0 @@
1
- require 'base64' # to convert Marshal.dump to ASCII
2
- require 'openssl' # to generate the HMAC message digest
3
-
4
- # Most of this code is taken from bitsweat's implementation in rails
5
-
6
- module Merb
7
-
8
- module SessionMixin #:nodoc:
9
- def setup_session
10
- Merb.logger.info("Setting Up Cookie Store Sessions")
11
- request.session = Merb::CookieStore.new(cookies[_session_id_key], session_secret_key)
12
- @original_session = request.session.read_cookie
13
- end
14
-
15
- def finalize_session
16
- Merb.logger.info("Finalize Cookie Store Session")
17
- new_session = request.session.read_cookie
18
-
19
- if @original_session != new_session
20
- set_cookie(_session_id_key, new_session, _session_expiry)
21
- end
22
- end
23
-
24
- def session_store_type
25
- "cookie"
26
- end
27
- end
28
-
29
- # If you have more than 4K of session data or don't want your data to be
30
- # visible to the user, pick another session store.
31
- #
32
- # CookieOverflow is raised if you attempt to store more than 4K of data.
33
- # TamperedWithCookie is raised if the data integrity check fails.
34
- #
35
- # A message digest is included with the cookie to ensure data integrity:
36
- # a user cannot alter session data without knowing the secret key included
37
- # in the hash.
38
- #
39
- # To use Cookie Sessions, set in config/merb.yml
40
- # :session_secret_key - your secret digest key
41
- # :session_store: cookie
42
- class CookieStore
43
- # TODO (maybe):
44
- # include request ip address
45
- # AES encrypt marshaled data
46
-
47
- # Raised when storing more than 4K of session data.
48
- class CookieOverflow < StandardError; end
49
-
50
- # Raised when the cookie fails its integrity check.
51
- class TamperedWithCookie < StandardError; end
52
-
53
- # Cookies can typically store 4096 bytes.
54
- MAX = 4096
55
- DIGEST = OpenSSL::Digest::Digest.new('SHA1') # or MD5, RIPEMD160, SHA256?
56
-
57
- attr_reader :data
58
-
59
- def initialize(cookie, secret)
60
- if secret.nil? or secret.blank?
61
- raise ArgumentError, 'A secret is required to generate an integrity hash for cookie session data.'
62
- end
63
- @secret = secret
64
- @data = unmarshal(cookie) || Hash.new
65
- end
66
-
67
- # return a cookie value. raises CookieOverflow if session contains too
68
- # much information
69
- def read_cookie
70
- unless @data.nil? or @data.empty?
71
- updated = marshal(@data)
72
- raise CookieOverflow if updated.size > MAX
73
- updated
74
- end
75
- end
76
-
77
- # assigns a key value pair
78
- def []=(k, v)
79
- @data[k] = v
80
- end
81
-
82
- def [](k)
83
- @data[k]
84
- end
85
-
86
- def each(&b)
87
- @data.each(&b)
88
- end
89
-
90
- private
91
-
92
- def method_missing(name, *args, &block)
93
- @data.send(name, *args, &block)
94
- end
95
-
96
- # Generate the HMAC keyed message digest. Uses SHA1.
97
- def generate_digest(data)
98
- OpenSSL::HMAC.hexdigest(DIGEST, @secret, data)
99
- end
100
-
101
- # Marshal a session hash into safe cookie data. Include an integrity hash.
102
- def marshal(session)
103
- data = Base64.encode64(Marshal.dump(session)).chop
104
- Mongrel::HttpRequest.escape "#{data}--#{generate_digest(data)}"
105
- end
106
-
107
- # Unmarshal cookie data to a hash and verify its integrity.
108
- def unmarshal(cookie)
109
- if cookie
110
- data, digest = Mongrel::HttpRequest.unescape(cookie).split('--')
111
- unless digest == generate_digest(data)
112
- raise TamperedWithCookie, "Maybe the site's session_secret_key has changed?"
113
- end
114
- Marshal.load(Base64.decode64(data))
115
- end
116
- end
117
- end
118
- end
@@ -1,131 +0,0 @@
1
- require 'memcache_util'
2
-
3
- module Merb
4
-
5
- module SessionMixin #:nodoc:
6
-
7
- def setup_session
8
- Merb.logger.info("Setting up session")
9
- before = cookies[_session_id_key]
10
- request.session, cookies[_session_id_key] = Merb::MemCacheSession.persist(cookies[_session_id_key])
11
- @_fingerprint = Marshal.dump(request.session.data).hash
12
- @_new_cookie = cookies[_session_id_key] != before
13
- end
14
-
15
- def finalize_session
16
- Merb.logger.info("Finalize session")
17
- if @_fingerprint != Marshal.dump(request.session.data).hash
18
- ::Cache.put("session:#{@_session.session_id}", request.session.data)
19
- end
20
- set_cookie(_session_id_key, request.session.session_id, _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
21
- end
22
-
23
- def session_store_type
24
- "memcache"
25
- end
26
- end
27
-
28
- ##
29
- # Sessions stored in memcached.
30
- #
31
- # Requires setup in your +merb_init.rb+:
32
- #
33
- # require 'memcache'
34
- # CACHE = MemCache.new('127.0.0.1:11211', { :namespace => 'my_app' })
35
- #
36
- # And a setting in +merb.yml+:
37
- #
38
- # :session_store: mem_cache
39
-
40
- class MemCacheSession
41
-
42
- attr_accessor :session_id
43
- attr_accessor :data
44
- attr_accessor :needs_new_cookie
45
-
46
- def initialize(session_id)
47
- @session_id = session_id
48
- @data = {}
49
- end
50
-
51
- class << self
52
- # Generates a new session ID and creates a row for the new session in the database.
53
- def generate
54
- sid = Merb::SessionMixin::rand_uuid
55
- new(sid)
56
- end
57
-
58
- # Gets the existing session based on the <tt>session_id</tt> available in cookies.
59
- # If none is found, generates a new session.
60
- def persist(session_id)
61
- unless session_id.blank?
62
- session = ::Cache.get("session:#{session_id}")
63
- if session.nil?
64
- # Not in memcached, but assume that cookie exists
65
- session = new(session_id)
66
- end
67
- else
68
- # No cookie...make a new session_id
69
- session = generate
70
- end
71
- if session.is_a?(MemCacheSession)
72
- [session, session.session_id]
73
- else
74
- # recreate using the rails session as the data
75
- session_object = MemCacheSession.new(session_id)
76
- session_object.data = session
77
- [session_object, session_object.session_id]
78
- end
79
-
80
- end
81
-
82
- # Don't try to reload in dev mode.
83
- def reloadable? #:nodoc:
84
- false
85
- end
86
-
87
- end
88
-
89
- # Regenerate the Session ID
90
- def regenerate
91
- @session_id = Merb::SessionMixin::rand_uuid
92
- self.needs_new_cookie=true
93
- end
94
-
95
- # Recreates the cookie with the default expiration time
96
- # Useful during log in for pushing back the expiration date
97
- def refresh_expiration
98
- self.needs_new_cookie=true
99
- end
100
-
101
- # Lazy-delete of session data
102
- def delete
103
- @data = {}
104
- end
105
-
106
- # Has the session been loaded yet?
107
- def loaded?
108
- !! @data
109
- end
110
-
111
- # assigns a key value pair
112
- def []=(k, v)
113
- @data[k] = v
114
- end
115
-
116
- def [](k)
117
- @data[k]
118
- end
119
-
120
- def each(&b)
121
- @data.each(&b)
122
- end
123
-
124
- private
125
- def method_missing(name, *args, &block)
126
- @data.send(name, *args, &block)
127
- end
128
-
129
- end
130
-
131
- end
@@ -1,176 +0,0 @@
1
- module Merb
2
-
3
- module SessionMixin #:nodoc:
4
-
5
- def setup_session
6
- Merb.logger.info("Setting up session")
7
- before = cookies[_session_id_key]
8
- request.session , cookies[_session_id_key] = Merb::MemorySession.persist(cookies[_session_id_key])
9
- @_new_cookie = cookies[_session_id_key] != before
10
- end
11
-
12
- def finalize_session
13
- Merb.logger.info("Finalize session")
14
- set_cookie(_session_id_key, request.session.session_id, _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
15
- end
16
-
17
- def session_store_type
18
- "memory"
19
- end
20
- end
21
-
22
- ##
23
- # Sessions stored in memory.
24
- #
25
- # And a setting in +merb.yml+:
26
- #
27
- # :session_store: mem_cache
28
- # :memory_session_ttl: 3600 (in seconds, one hour)
29
- #
30
- # Sessions will remain in memory until the server is stopped or the time
31
- # as set in :memory_session_ttl expires.
32
-
33
- class MemorySession
34
-
35
- attr_accessor :session_id
36
- attr_accessor :data
37
- attr_accessor :needs_new_cookie
38
-
39
- def initialize(session_id)
40
- @session_id = session_id
41
- @data = {}
42
- end
43
-
44
- class << self
45
- # Generates a new session ID and creates a row for the new session in the database.
46
- def generate
47
- sid = Merb::SessionMixin::rand_uuid
48
- MemorySessionContainer[sid] = new(sid)
49
- end
50
-
51
- # Gets the existing session based on the <tt>session_id</tt> available in cookies.
52
- # If none is found, generates a new session.
53
- def persist(session_id)
54
- if session_id
55
- session = MemorySessionContainer[session_id]
56
- end
57
- unless session
58
- session = generate
59
- end
60
- [session, session.session_id]
61
- end
62
-
63
- end
64
-
65
- # Regenerate the Session ID
66
- def regenerate
67
- new_sid = Merb::SessionMixin::rand_uuid
68
- old_sid = @session_id
69
- MemorySessionContainer[new_sid] = MemorySessionContainer[old_sid]
70
- @session_id = new_sid
71
- MemorySessionContainer.delete(old_sid)
72
- self.needs_new_cookie=true
73
- end
74
-
75
- # Recreates the cookie with the default expiration time
76
- # Useful during log in for pushing back the expiration date
77
- def refresh_expiration
78
- self.needs_new_cookie=true
79
- end
80
-
81
- # Lazy-delete of session data
82
- def delete
83
- @data = {}
84
- end
85
-
86
- # Has the session been loaded yet?
87
- def loaded?
88
- !! @data
89
- end
90
-
91
- # assigns a key value pair
92
- def []=(k, v)
93
- @data[k] = v
94
- end
95
-
96
- def [](k)
97
- @data[k]
98
- end
99
-
100
- def each(&b)
101
- @data.each(&b)
102
- end
103
-
104
- private
105
- def method_missing(name, *args, &block)
106
- @data.send(name, *args, &block)
107
- end
108
-
109
- end
110
-
111
- class MemorySessionContainer
112
- class << self
113
-
114
- def setup(ttl=nil)
115
- @sessions = Hash.new
116
- @timestamps = Hash.new
117
- @mutex = Mutex.new
118
- @session_ttl = ttl || 60*60 # default 1 hour
119
- start_timer
120
- self
121
- end
122
-
123
- def create(opts={})
124
- self[opts[:session_id]] = opts[:data]
125
- end
126
-
127
-
128
- def [](key)
129
- @mutex.synchronize {
130
- @timestamps[key] = Time.now
131
- @sessions[key]
132
- }
133
- end
134
-
135
- def []=(key, val)
136
- @mutex.synchronize {
137
- @timestamps[key] = Time.now
138
- @sessions[key] = val
139
- }
140
- end
141
-
142
- def delete(key)
143
- @mutex.synchronize {
144
- @sessions.delete(key)
145
- @timestamps.delete(key)
146
- }
147
- end
148
-
149
- def reap_old_sessions
150
- @timestamps.each do |key,stamp|
151
- if stamp + @session_ttl < Time.now
152
- delete(key)
153
- end
154
- end
155
- GC.start
156
- end
157
-
158
- def start_timer
159
- Thread.new do
160
- loop {
161
- sleep @session_ttl
162
- reap_old_sessions
163
- }
164
- end
165
- end
166
-
167
- def sessions
168
- @sessions
169
- end
170
-
171
- end # end singleton class
172
-
173
- end # end MemorySessionContainer
174
- end
175
-
176
- Merb::MemorySessionContainer.setup(Merb::Config[:memory_session_ttl])