merb 0.5.3 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +0 -20
- data/README +0 -277
- data/Rakefile +80 -199
- data/TODO +0 -3
- metadata +19 -438
- data/SVN_REVISION +0 -1
- data/app_generators/merb/USAGE +0 -5
- data/app_generators/merb/merb_generator.rb +0 -108
- data/app_generators/merb/templates/Rakefile +0 -124
- data/app_generators/merb/templates/app/controllers/application.rb +0 -3
- data/app_generators/merb/templates/app/controllers/exceptions.rb +0 -13
- data/app_generators/merb/templates/app/helpers/global_helper.rb +0 -5
- data/app_generators/merb/templates/app/mailers/views/layout/application.html.erb +0 -1
- data/app_generators/merb/templates/app/mailers/views/layout/application.text.erb +0 -1
- data/app_generators/merb/templates/app/parts/views/layout/application.html.erb +0 -1
- data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +0 -216
- data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +0 -38
- data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +0 -40
- data/app_generators/merb/templates/app/views/layout/application.html.erb +0 -11
- data/app_generators/merb/templates/config/boot.rb +0 -11
- data/app_generators/merb/templates/config/dependencies.rb +0 -41
- data/app_generators/merb/templates/config/environments/development.rb +0 -1
- data/app_generators/merb/templates/config/environments/production.rb +0 -1
- data/app_generators/merb/templates/config/environments/test.rb +0 -1
- data/app_generators/merb/templates/config/merb.yml +0 -82
- data/app_generators/merb/templates/config/merb_init.rb +0 -17
- data/app_generators/merb/templates/config/plugins.yml +0 -1
- data/app_generators/merb/templates/config/router.rb +0 -35
- data/app_generators/merb/templates/config/upload.conf +0 -0
- data/app_generators/merb/templates/public/images/merb.jpg +0 -0
- data/app_generators/merb/templates/public/merb.fcgi +0 -6
- data/app_generators/merb/templates/public/stylesheets/master.css +0 -119
- data/app_generators/merb/templates/script/destroy +0 -32
- data/app_generators/merb/templates/script/generate +0 -32
- data/app_generators/merb/templates/script/stop_merb +0 -13
- data/app_generators/merb/templates/script/win_script.cmd +0 -1
- data/app_generators/merb/templates/spec/spec.opts +0 -6
- data/app_generators/merb/templates/spec/spec_helper.rb +0 -15
- data/app_generators/merb/templates/test/test_helper.rb +0 -14
- data/app_generators/merb_plugin/USAGE +0 -5
- data/app_generators/merb_plugin/merb_plugin_generator.rb +0 -68
- data/app_generators/merb_plugin/templates/LICENSE +0 -20
- data/app_generators/merb_plugin/templates/README +0 -4
- data/app_generators/merb_plugin/templates/Rakefile +0 -35
- data/app_generators/merb_plugin/templates/TODO +0 -5
- data/app_generators/merb_plugin/templates/merbtasks.rb +0 -6
- data/app_generators/merb_plugin/templates/sampleplugin.rb +0 -10
- data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +0 -7
- data/app_generators/merb_plugin/templates/spec_helper.rb +0 -2
- data/bin/merb +0 -4
- data/lib/autotest/discover.rb +0 -3
- data/lib/autotest/merb_rspec.rb +0 -80
- data/lib/merb.rb +0 -188
- data/lib/merb/abstract_controller.rb +0 -399
- data/lib/merb/assets.rb +0 -160
- data/lib/merb/assets.rb.orig +0 -119
- data/lib/merb/boot_loader.rb +0 -286
- data/lib/merb/boot_loader.rb.orig +0 -235
- data/lib/merb/caching.rb +0 -5
- data/lib/merb/caching/action_cache.rb +0 -92
- data/lib/merb/caching/fragment_cache.rb +0 -39
- data/lib/merb/caching/store/file_cache.rb +0 -90
- data/lib/merb/caching/store/memory_cache.rb +0 -85
- data/lib/merb/config.rb +0 -290
- data/lib/merb/constants.rb +0 -50
- data/lib/merb/controller.rb +0 -220
- data/lib/merb/cookies.rb +0 -95
- data/lib/merb/core_ext.rb +0 -15
- data/lib/merb/core_ext/array.rb +0 -0
- data/lib/merb/core_ext/class.rb +0 -180
- data/lib/merb/core_ext/enumerable.rb +0 -49
- data/lib/merb/core_ext/get_args.rb +0 -76
- data/lib/merb/core_ext/hash.rb +0 -306
- data/lib/merb/core_ext/inflections.rb +0 -112
- data/lib/merb/core_ext/inflector.rb +0 -275
- data/lib/merb/core_ext/kernel.rb +0 -242
- data/lib/merb/core_ext/mash.rb +0 -88
- data/lib/merb/core_ext/module.rb +0 -67
- data/lib/merb/core_ext/numeric.rb +0 -72
- data/lib/merb/core_ext/object.rb +0 -183
- data/lib/merb/core_ext/string.rb +0 -53
- data/lib/merb/core_ext/symbol.rb +0 -6
- data/lib/merb/dispatcher.rb +0 -109
- data/lib/merb/drb_server.rb +0 -19
- data/lib/merb/erubis_ext.rb +0 -10
- data/lib/merb/exceptions.rb +0 -192
- data/lib/merb/generators/merb_app/merb_app.rb +0 -22
- data/lib/merb/generators/merb_generator_helpers.rb +0 -318
- data/lib/merb/generators/merb_plugin.rb +0 -22
- data/lib/merb/logger.rb +0 -78
- data/lib/merb/mail_controller.rb +0 -268
- data/lib/merb/mailer.rb +0 -87
- data/lib/merb/mixins/basic_authentication.rb +0 -35
- data/lib/merb/mixins/controller.rb +0 -160
- data/lib/merb/mixins/erubis_capture.rb +0 -68
- data/lib/merb/mixins/general_controller.rb +0 -253
- data/lib/merb/mixins/inline_partial.rb +0 -32
- data/lib/merb/mixins/render.rb +0 -465
- data/lib/merb/mixins/responder.rb +0 -449
- data/lib/merb/mixins/view_context.rb +0 -558
- data/lib/merb/mixins/web_controller.rb +0 -36
- data/lib/merb/mongrel_handler.rb +0 -168
- data/lib/merb/part_controller.rb +0 -29
- data/lib/merb/plugins.rb +0 -16
- data/lib/merb/rack_adapter.rb +0 -37
- data/lib/merb/request.rb +0 -465
- data/lib/merb/router.rb +0 -646
- data/lib/merb/server.rb +0 -169
- data/lib/merb/session.rb +0 -23
- data/lib/merb/session/cookie_store.rb +0 -118
- data/lib/merb/session/mem_cache_session.rb +0 -131
- data/lib/merb/session/memory_session.rb +0 -176
- data/lib/merb/template.rb +0 -37
- data/lib/merb/template/erubis.rb +0 -68
- data/lib/merb/template/haml.rb +0 -87
- data/lib/merb/template/markaby.rb +0 -59
- data/lib/merb/template/xml_builder.rb +0 -50
- data/lib/merb/test/fake_request.rb +0 -74
- data/lib/merb/test/helper.rb +0 -260
- data/lib/merb/test/hpricot.rb +0 -136
- data/lib/merb/test/multipart.rb +0 -66
- data/lib/merb/test/rspec.rb +0 -18
- data/lib/merb/test/rspec_matchers/controller_matchers.rb +0 -117
- data/lib/merb/test/rspec_matchers/markup_matchers.rb +0 -98
- data/lib/merb/upload_handler.rb +0 -80
- data/lib/merb/upload_progress.rb +0 -48
- data/lib/merb/version.rb +0 -49
- data/lib/merb/view_context.rb +0 -79
- data/lib/tasks.rb +0 -7
- data/lib/tasks/merb.rake +0 -54
- data/merb_default_generators/model/USAGE +0 -0
- data/merb_default_generators/model/model_generator.rb +0 -16
- data/merb_default_generators/model/templates/new_model_template.erb +0 -5
- data/merb_default_generators/resource_controller/USAGE +0 -0
- data/merb_default_generators/resource_controller/resource_controller_generator.rb +0 -26
- data/merb_default_generators/resource_controller/templates/controller.rb +0 -30
- data/merb_default_generators/resource_controller/templates/edit.html.erb +0 -1
- data/merb_default_generators/resource_controller/templates/helper.rb +0 -5
- data/merb_default_generators/resource_controller/templates/index.html.erb +0 -1
- data/merb_default_generators/resource_controller/templates/new.html.erb +0 -1
- data/merb_default_generators/resource_controller/templates/show.html.erb +0 -1
- data/merb_generators/controller/USAGE +0 -5
- data/merb_generators/controller/controller_generator.rb +0 -16
- data/merb_generators/controller/templates/controller.rb +0 -8
- data/merb_generators/controller/templates/helper.rb +0 -5
- data/merb_generators/controller/templates/index.html.erb +0 -3
- data/merb_generators/part_controller/USAGE +0 -5
- data/merb_generators/part_controller/part_controller_generator.rb +0 -27
- data/merb_generators/part_controller/templates/controller.rb +0 -8
- data/merb_generators/part_controller/templates/helper.rb +0 -5
- data/merb_generators/part_controller/templates/index.html.erb +0 -3
- data/merb_generators/resource/USAGE +0 -0
- data/merb_generators/resource/resource_generator.rb +0 -67
- data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +0 -67
- data/rspec_generators/merb_controller_test/templates/controller_spec.rb +0 -8
- data/rspec_generators/merb_controller_test/templates/edit_spec.rb +0 -12
- data/rspec_generators/merb_controller_test/templates/helper_spec.rb +0 -5
- data/rspec_generators/merb_controller_test/templates/index_spec.rb +0 -12
- data/rspec_generators/merb_controller_test/templates/new_spec.rb +0 -12
- data/rspec_generators/merb_controller_test/templates/show_spec.rb +0 -5
- data/rspec_generators/merb_model_test/merb_model_test_generator.rb +0 -26
- data/rspec_generators/merb_model_test/templates/model_spec_template.erb +0 -7
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/fixtures/config/environments/environment_config_test.yml +0 -1
- data/spec/fixtures/config/merb.yml +0 -18
- data/spec/fixtures/controllers/dispatch_spec_controllers.rb +0 -235
- data/spec/fixtures/controllers/render_spec_controllers.rb +0 -184
- data/spec/fixtures/foo.rb +0 -3
- data/spec/fixtures/mailers/views/layout/application.html.erb +0 -3
- data/spec/fixtures/mailers/views/layout/application.text.erb +0 -3
- data/spec/fixtures/mailers/views/test_mail_controller/eighth.html.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/eighth.text.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/first.html.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/first.text.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/ninth.html.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/ninth.text.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/second.text.erb +0 -1
- data/spec/fixtures/mailers/views/test_mail_controller/third.html.erb +0 -1
- data/spec/fixtures/models/router_spec_models.rb +0 -30
- data/spec/fixtures/parts/views/layout/todo_part.html.erb +0 -3
- data/spec/fixtures/parts/views/layout/todo_part.xml.erb +0 -3
- data/spec/fixtures/parts/views/todo_part/formatted_output.html.erb +0 -1
- data/spec/fixtures/parts/views/todo_part/formatted_output.js.erb +0 -1
- data/spec/fixtures/parts/views/todo_part/formatted_output.xml.erb +0 -1
- data/spec/fixtures/parts/views/todo_part/list.html.erb +0 -3
- data/spec/fixtures/sample.txt +0 -1
- data/spec/fixtures/views/erubis.html.erb +0 -1
- data/spec/fixtures/views/examples/_erubis.html.erb +0 -1
- data/spec/fixtures/views/examples/_haml.html.haml +0 -1
- data/spec/fixtures/views/examples/_markaby.html.mab +0 -1
- data/spec/fixtures/views/examples/_throw_content.html.erb +0 -6
- data/spec/fixtures/views/examples/hello.xml.builder +0 -1
- data/spec/fixtures/views/examples/js.js.erb +0 -1
- data/spec/fixtures/views/examples/template_catch_content.html.erb +0 -15
- data/spec/fixtures/views/examples/template_catch_content_from_partial.html.erb +0 -6
- data/spec/fixtures/views/examples/template_throw_content.html.erb +0 -10
- data/spec/fixtures/views/examples/template_throw_content_without_block.html.erb +0 -3
- data/spec/fixtures/views/exceptions/admin_access_required.html.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/_nested_js.js.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/_nested_xml.xml.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/_render_partial_multiple_times.html.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/erubis_templates.html.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/erubis_templates.js.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/erubis_templates.rhtml +0 -1
- data/spec/fixtures/views/extension_template_controller/erubis_templates.xml.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/haml_index.html.haml +0 -0
- data/spec/fixtures/views/extension_template_controller/haml_templates.html.haml +0 -1
- data/spec/fixtures/views/extension_template_controller/haml_templates.js.haml +0 -1
- data/spec/fixtures/views/extension_template_controller/haml_templates.xml.haml +0 -1
- data/spec/fixtures/views/extension_template_controller/index.html.erb +0 -0
- data/spec/fixtures/views/extension_template_controller/markaby_index.html.mab +0 -0
- data/spec/fixtures/views/extension_template_controller/markaby_templates.html.mab +0 -1
- data/spec/fixtures/views/extension_template_controller/markaby_templates.js.mab +0 -1
- data/spec/fixtures/views/extension_template_controller/markaby_templates.xml.mab +0 -1
- data/spec/fixtures/views/extension_template_controller/render_multiple_partials.html.erb +0 -4
- data/spec/fixtures/views/extension_template_controller/render_nested_js.js.erb +0 -1
- data/spec/fixtures/views/extension_template_controller/render_nested_xml.xml.erb +0 -1
- data/spec/fixtures/views/haml.html.haml +0 -1
- data/spec/fixtures/views/haml.xml.haml +0 -2
- data/spec/fixtures/views/layout/application.html.erb +0 -1
- data/spec/fixtures/views/layout/application.xml.erb +0 -1
- data/spec/fixtures/views/layout/nested/example.html.erb +0 -1
- data/spec/fixtures/views/markaby.html.mab +0 -1
- data/spec/fixtures/views/nested/example/test.html.erb +0 -1
- data/spec/fixtures/views/partials/_erubis.html.erb +0 -1
- data/spec/fixtures/views/partials/_erubis_collection.html.erb +0 -1
- data/spec/fixtures/views/partials/_erubis_collection_with_locals.html.erb +0 -1
- data/spec/fixtures/views/partials/_erubis_new.html.erb +0 -1
- data/spec/fixtures/views/partials/_haml.html.haml +0 -1
- data/spec/fixtures/views/partials/_haml_collection.html.haml +0 -1
- data/spec/fixtures/views/partials/_haml_collection_with_locals.html.haml +0 -1
- data/spec/fixtures/views/partials/_haml_new.html.haml +0 -1
- data/spec/fixtures/views/partials/_markaby.html.mab +0 -1
- data/spec/fixtures/views/partials/_markaby_collection.html.mab +0 -1
- data/spec/fixtures/views/partials/_markaby_collection_with_locals.html.mab +0 -1
- data/spec/fixtures/views/partials/_markaby_new.html.mab +0 -1
- data/spec/fixtures/views/render_object_controller/render_object_with_template.html.erb +0 -1
- data/spec/fixtures/views/render_object_controller/render_object_with_template.js.erb +0 -1
- data/spec/fixtures/views/render_object_controller/render_object_with_template.xml.erb +0 -1
- data/spec/fixtures/views/template_views/interface__buffer_erubis.html.erb +0 -4
- data/spec/fixtures/views/template_views/interface__buffer_haml.html.haml +0 -7
- data/spec/fixtures/views/template_views/interface__buffer_markaby.html.mab +0 -7
- data/spec/fixtures/views/template_views/interface_capture_erubis.html.erb +0 -15
- data/spec/fixtures/views/template_views/interface_capture_haml.html.haml +0 -15
- data/spec/fixtures/views/template_views/interface_capture_markaby.html.mab +0 -4
- data/spec/fixtures/views/template_views/interface_concat_erubis.html.erb +0 -12
- data/spec/fixtures/views/template_views/interface_concat_haml.html.haml +0 -11
- data/spec/fixtures/views/template_views/interface_concat_markaby.html.mab +0 -14
- data/spec/fixtures/views/test.dir/the_template.html.erb +0 -1
- data/spec/merb/abstract_controller_spec.rb +0 -38
- data/spec/merb/assets_spec.rb +0 -207
- data/spec/merb/caching_spec.rb +0 -102
- data/spec/merb/config_spec.rb +0 -29
- data/spec/merb/controller_filters_spec.rb +0 -253
- data/spec/merb/controller_spec.rb +0 -126
- data/spec/merb/cookie_store_spec.rb +0 -72
- data/spec/merb/cookies_spec.rb +0 -96
- data/spec/merb/core_ext/class_spec.rb +0 -97
- data/spec/merb/core_ext/enumerable_spec.rb +0 -27
- data/spec/merb/core_ext/hash_spec.rb +0 -251
- data/spec/merb/core_ext/inflector_spec.rb +0 -34
- data/spec/merb/core_ext/kernel_spec.rb +0 -25
- data/spec/merb/core_ext/numeric_spec.rb +0 -26
- data/spec/merb/core_ext/object_spec.rb +0 -47
- data/spec/merb/core_ext/string_spec.rb +0 -22
- data/spec/merb/core_ext/symbol_spec.rb +0 -7
- data/spec/merb/dependency_spec.rb +0 -22
- data/spec/merb/dispatch_spec.rb +0 -528
- data/spec/merb/fake_request_spec.rb +0 -80
- data/spec/merb/generator_spec.rb +0 -248
- data/spec/merb/handler_spec.rb +0 -169
- data/spec/merb/mail_controller_spec.rb +0 -177
- data/spec/merb/mailer_spec.rb +0 -87
- data/spec/merb/multipart_spec.rb +0 -50
- data/spec/merb/part_controller_spec.rb +0 -124
- data/spec/merb/plugins_spec.rb +0 -80
- data/spec/merb/render_spec.rb +0 -469
- data/spec/merb/request_spec.rb +0 -287
- data/spec/merb/responder_spec.rb +0 -562
- data/spec/merb/router_spec.rb +0 -900
- data/spec/merb/server_spec.rb +0 -19
- data/spec/merb/template_spec.rb +0 -41
- data/spec/merb/upload_handler_spec.rb +0 -108
- data/spec/merb/version_spec.rb +0 -33
- data/spec/merb/view_context_spec.rb +0 -366
- data/spec/spec_generator_helper.rb +0 -34
- data/spec/spec_helper.rb +0 -101
- data/spec/spec_helpers/url_shared_behaviour.rb +0 -112
- data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +0 -53
- data/test_unit_generators/merb_controller_test/templates/functional_test.rb +0 -17
- data/test_unit_generators/merb_controller_test/templates/helper_test.rb +0 -9
- data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +0 -29
- data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +0 -9
data/lib/merb/caching.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
module Merb
|
2
|
-
module Caching
|
3
|
-
|
4
|
-
|
5
|
-
# Action caching provides the ability to cache the output of individual actions. This output will be stored using fragment caching
|
6
|
-
# (Merb::Caching::Fragment). The output is stored based on a multipart key, which is comprised of the following pieces, in this order:
|
7
|
-
# * controller
|
8
|
-
# * action
|
9
|
-
# * parameters (represented as a list of parameter name/value pairs, sorted by name)
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# === Examples
|
13
|
-
#
|
14
|
-
# class UserController < Merb::Controller
|
15
|
-
# cache_action(:show, :index)
|
16
|
-
#
|
17
|
-
# def show
|
18
|
-
# ... do some work to show a user ...
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# def index
|
22
|
-
# ... get the list of users ...
|
23
|
-
# end
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# In this case, we would expect show to take an :id parameter, and index to take no parameters, so the fragment stored for this action
|
27
|
-
# will be represented thus:
|
28
|
-
# get :show, :id => 25 => [:user_controller, :show, :id, 25]
|
29
|
-
# get :index => [:user_controller, :index]
|
30
|
-
#
|
31
|
-
# Action caches are expired based on the action alone (TODO: We need to modify expire action to allow expiration for specific parameter values).
|
32
|
-
# expire_action(:show) => This will expire all cached show actions (i.e. All users, in this case)
|
33
|
-
|
34
|
-
module Actions
|
35
|
-
|
36
|
-
def self.included(base) # :nodoc:
|
37
|
-
|
38
|
-
base.extend(ClassMethods)
|
39
|
-
end
|
40
|
-
|
41
|
-
module ClassMethods
|
42
|
-
|
43
|
-
# Cache the specific actions. If those actions take parameters, then those parameters will be considered part of the key.
|
44
|
-
#
|
45
|
-
def cache_action(*actions)
|
46
|
-
before :_get_action_fragment, :only => actions
|
47
|
-
after :_store_action_fragment, :only => actions
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
# Expire all cached content for the specific action, or array of actions.
|
54
|
-
def expire_action(*actions)
|
55
|
-
return unless _caching_enabled?
|
56
|
-
for action in [actions].flatten
|
57
|
-
::Merb::Caching::Fragment.expire_fragment(params_key(:action => action))
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def _caching_enabled?
|
65
|
-
::Merb::Config[:cache_templates]
|
66
|
-
end
|
67
|
-
|
68
|
-
def _get_action_fragment
|
69
|
-
return unless _caching_enabled?
|
70
|
-
if fragment = ::Merb::Caching::Fragment.get(params_key)
|
71
|
-
throw :halt, fragment
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def _store_action_fragment
|
76
|
-
return unless _caching_enabled?
|
77
|
-
::Merb::Caching::Fragment.put(params_key, body)
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
def params_key(overrides = {})
|
82
|
-
key = []
|
83
|
-
additional_parameters = params.clone.merge(overrides)
|
84
|
-
key << additional_parameters.delete(:controller).to_s.snake_case
|
85
|
-
key << additional_parameters.delete(:action).to_s.snake_case
|
86
|
-
key << additional_parameters.keys.sort{|a,b| a.to_s <=> b.to_s}.collect{|k| [k.to_s, additional_parameters[k].to_s]}.flatten
|
87
|
-
key.flatten
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Merb
|
2
|
-
module Caching
|
3
|
-
module Fragment
|
4
|
-
class << self
|
5
|
-
def cache
|
6
|
-
@cache ||= determine_cache_store
|
7
|
-
end
|
8
|
-
|
9
|
-
def clear
|
10
|
-
cache.clear
|
11
|
-
@cache = nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def get(name)
|
15
|
-
cache.get(name)
|
16
|
-
end
|
17
|
-
|
18
|
-
def put(name, content = nil)
|
19
|
-
cache.put(name, content)
|
20
|
-
content
|
21
|
-
end
|
22
|
-
|
23
|
-
def expire_fragment(name)
|
24
|
-
cache.delete(name)
|
25
|
-
end
|
26
|
-
|
27
|
-
def determine_cache_store
|
28
|
-
if ::Merb::Config[:cache_store].to_s == "file"
|
29
|
-
require 'merb/caching/store/file_cache'
|
30
|
-
::Merb::Caching::Store::FileCache.new
|
31
|
-
else
|
32
|
-
require 'merb/caching/store/memory_cache'
|
33
|
-
::Merb::Caching::Store::MemoryCache.new
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'tmpdir'
|
4
|
-
|
5
|
-
module Merb
|
6
|
-
module Caching
|
7
|
-
module Store
|
8
|
-
|
9
|
-
class FileCache
|
10
|
-
|
11
|
-
def initialize(name = "cache", keepalive = nil)
|
12
|
-
@path = File.join(Merb.root, name)
|
13
|
-
@keepalive = keepalive
|
14
|
-
end
|
15
|
-
|
16
|
-
def []=(key,val)
|
17
|
-
key = escape_filenames([key].flatten)
|
18
|
-
FileUtils.mkdir_p(File.join(@path, *key[0..-2]), :mode => 0700)
|
19
|
-
fn = File.join(@path, *key )
|
20
|
-
encode_file(fn, val)
|
21
|
-
end
|
22
|
-
alias :put :[]=
|
23
|
-
alias :write :[]=
|
24
|
-
|
25
|
-
def [](key)
|
26
|
-
key = escape_filenames([key].flatten)
|
27
|
-
fn = File.join(@path, *key )
|
28
|
-
return nil unless File.exists?(fn)
|
29
|
-
decode_file(fn)
|
30
|
-
end
|
31
|
-
alias :get :[]
|
32
|
-
alias_method :read, :[]
|
33
|
-
|
34
|
-
def delete(key)
|
35
|
-
key = escape_filenames([key].flatten)
|
36
|
-
f = File.join(@path, *key)
|
37
|
-
FileUtils.rm_rf(f)
|
38
|
-
end
|
39
|
-
|
40
|
-
def gc!
|
41
|
-
return unless @keepalive
|
42
|
-
|
43
|
-
now = Time.now
|
44
|
-
all.each do |fn|
|
45
|
-
expire_time = File.stat(fn).atime + @keepalive
|
46
|
-
File.delete(fn) if now > expire_time
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def clear
|
51
|
-
all.each{|file| delete(File.basename(file)) }
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def decode_file(fn)
|
57
|
-
val = nil
|
58
|
-
File.open(fn,"r+b") do |f|
|
59
|
-
f.flock(File::LOCK_EX)
|
60
|
-
val = Marshal.load( f.read )
|
61
|
-
f.flock(File::LOCK_UN)
|
62
|
-
end
|
63
|
-
return val
|
64
|
-
end
|
65
|
-
|
66
|
-
def encode_file(fn, value)
|
67
|
-
File.open(fn, "wb") do |f|
|
68
|
-
f.flock(File::LOCK_EX)
|
69
|
-
f.chmod(0600)
|
70
|
-
f.write(Marshal.dump(value))
|
71
|
-
f.flock(File::LOCK_UN)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def all
|
76
|
-
Dir.glob( File.join(@path, '*' ) )
|
77
|
-
end
|
78
|
-
# need this for fat filesystems
|
79
|
-
def escape_filenames(fns)
|
80
|
-
fns.collect do |fn|
|
81
|
-
URI.escape(fn.to_s, /["\/:;|=,\[\]]/)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
@@ -1,85 +0,0 @@
|
|
1
|
-
module Merb
|
2
|
-
module Caching
|
3
|
-
module Store
|
4
|
-
|
5
|
-
class MemoryCache
|
6
|
-
|
7
|
-
def initialize(opts={})
|
8
|
-
@opts = opts
|
9
|
-
@cache = Hash.new
|
10
|
-
@timestamps = Hash.new
|
11
|
-
@mutex = Mutex.new
|
12
|
-
@cache_ttl = @opts.fetch(:session_ttl, 30*60) # default 30 minutes
|
13
|
-
end
|
14
|
-
|
15
|
-
def [](key)
|
16
|
-
key = [key].flatten.collect{|k| k.to_s}
|
17
|
-
@mutex.synchronize {
|
18
|
-
@timestamps[key] = Time.now
|
19
|
-
sub_cache = @cache
|
20
|
-
key[0..-2].each do |subkey|
|
21
|
-
sub_cache = (sub_cache[subkey] ||= {})
|
22
|
-
end
|
23
|
-
sub_cache[key[-1]]
|
24
|
-
}
|
25
|
-
end
|
26
|
-
alias_method :get, :[]
|
27
|
-
alias_method :read, :[]
|
28
|
-
|
29
|
-
def []=(key, val)
|
30
|
-
key = [key].flatten.collect{|k| k.to_s}
|
31
|
-
@mutex.synchronize {
|
32
|
-
sub_cache = @cache
|
33
|
-
key[0..-2].each do |subkey|
|
34
|
-
sub_cache = (sub_cache[subkey] ||= {})
|
35
|
-
end
|
36
|
-
sub_cache[key[-1]] = val
|
37
|
-
@timestamps[key] = Time.now
|
38
|
-
}
|
39
|
-
end
|
40
|
-
alias_method :put, :[]=
|
41
|
-
alias_method :write, :[]=
|
42
|
-
|
43
|
-
def delete(key)
|
44
|
-
key = [key].flatten.collect{|k| k.to_s}
|
45
|
-
@mutex.synchronize {
|
46
|
-
sub_cache = @cache
|
47
|
-
key[0..-2].each do |subkey|
|
48
|
-
sub_cache = (sub_cache[subkey] ||= {})
|
49
|
-
end
|
50
|
-
sub_cache.delete(key[-1])
|
51
|
-
}
|
52
|
-
end
|
53
|
-
alias_method :remove, :delete
|
54
|
-
|
55
|
-
def delete_if(&block)
|
56
|
-
@hash.delete_if(&block)
|
57
|
-
end
|
58
|
-
|
59
|
-
def reap_old_caches
|
60
|
-
@timestamps.each do |key,stamp|
|
61
|
-
if stamp + @cache_ttl < Time.now
|
62
|
-
delete(key)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
GC.start
|
66
|
-
end
|
67
|
-
|
68
|
-
def cache
|
69
|
-
@cache
|
70
|
-
end
|
71
|
-
|
72
|
-
def keys
|
73
|
-
@cache.keys
|
74
|
-
end
|
75
|
-
|
76
|
-
def clear
|
77
|
-
@cache = Hash.new
|
78
|
-
@timestamps = Hash.new
|
79
|
-
@mutex = Mutex.new
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/lib/merb/config.rb
DELETED
@@ -1,290 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'erubis_ext')
|
2
|
-
require File.join(File.dirname(__FILE__), 'version')
|
3
|
-
require File.join(File.dirname(__FILE__), 'boot_loader')
|
4
|
-
module Merb
|
5
|
-
class Config
|
6
|
-
class << self
|
7
|
-
|
8
|
-
def defaults
|
9
|
-
@defaults ||= {
|
10
|
-
:host => "0.0.0.0",
|
11
|
-
:port => "4000",
|
12
|
-
:reloader => true,
|
13
|
-
:cache_templates => false,
|
14
|
-
:merb_root => Dir.pwd,
|
15
|
-
:use_mutex => true,
|
16
|
-
:session_id_cookie_only => true,
|
17
|
-
:query_string_whitelist => [],
|
18
|
-
:mongrel_x_sendfile => true
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def [](key)
|
23
|
-
(@configuration||={})[key]
|
24
|
-
end
|
25
|
-
|
26
|
-
def []=(key,val)
|
27
|
-
@configuration[key] = val
|
28
|
-
end
|
29
|
-
def delete(key)
|
30
|
-
@configuration.delete key
|
31
|
-
end
|
32
|
-
|
33
|
-
def fetch(key, default)
|
34
|
-
@configuration.fetch key, default
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_yaml
|
38
|
-
@configuration.to_yaml
|
39
|
-
end
|
40
|
-
|
41
|
-
def setup(global_merb_yml = nil)
|
42
|
-
@configuration ||= {}
|
43
|
-
if FileTest.exist? "#{defaults[:merb_root]}/framework"
|
44
|
-
$LOAD_PATH.unshift( "#{defaults[:merb_root]}/framework" )
|
45
|
-
end
|
46
|
-
global_merb_yml ||= "#{defaults[:merb_root]}/config/merb.yml"
|
47
|
-
apply_configuration_from_file defaults, global_merb_yml
|
48
|
-
end
|
49
|
-
|
50
|
-
def apply_configuration_from_file(configuration, file)
|
51
|
-
if File.exists?(file)
|
52
|
-
configuration.merge(Erubis.load_yaml_file(file))
|
53
|
-
else
|
54
|
-
configuration
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def parse_args(argv = ARGV)
|
59
|
-
@configuration ||= {}
|
60
|
-
# Our primary configuration hash for the length of this method
|
61
|
-
options = {}
|
62
|
-
|
63
|
-
# Environment variables always win
|
64
|
-
options[:environment] = ENV['MERB_ENV'] if ENV['MERB_ENV']
|
65
|
-
|
66
|
-
# Build a parser for the command line arguments
|
67
|
-
opts = OptionParser.new do |opts|
|
68
|
-
opts.version = Merb::VERSION
|
69
|
-
opts.release = Merb::RELEASE
|
70
|
-
|
71
|
-
opts.banner = "Usage: merb [fdcepghmisluMG] [argument]"
|
72
|
-
opts.define_head "Merb Mongrel+ Erb. Lightweight replacement for ActionPack."
|
73
|
-
opts.separator '*'*80
|
74
|
-
opts.separator 'If no flags are given, Merb starts in the foreground on port 4000.'
|
75
|
-
opts.separator '*'*80
|
76
|
-
|
77
|
-
opts.on("-u", "--user USER", "This flag is for having merb run as a user other than the one currently logged in. Note: if you set this you must also provide a --group option for it to take effect.") do |config|
|
78
|
-
options[:user] = config
|
79
|
-
end
|
80
|
-
|
81
|
-
opts.on("-G", "--group GROUP", "This flag is for having merb run as a group other than the one currently logged in. Note: if you set this you must also provide a --user option for it to take effect.") do |config|
|
82
|
-
options[:group] = config
|
83
|
-
end
|
84
|
-
|
85
|
-
opts.on("-f", "--config-file FILENAME", "This flag is for adding extra config files for things like the upload progress module.") do |config|
|
86
|
-
options[:config] = config
|
87
|
-
end
|
88
|
-
|
89
|
-
opts.on("-d", "--daemonize", "This will run a single merb in the background.") do |config|
|
90
|
-
options[:daemonize] = true
|
91
|
-
end
|
92
|
-
|
93
|
-
opts.on("-c", "--cluster-nodes NUM_MERBS", "Number of merb daemons to run.") do |nodes|
|
94
|
-
options[:cluster] = nodes
|
95
|
-
end
|
96
|
-
|
97
|
-
opts.on("-p", "--port PORTNUM", "Port to run merb on, defaults to 4000.") do |port|
|
98
|
-
options[:port] = port
|
99
|
-
end
|
100
|
-
|
101
|
-
opts.on("-h", "--host HOSTNAME", "Host to bind to (default is all IP's).") do |host|
|
102
|
-
options[:host] = host
|
103
|
-
end
|
104
|
-
|
105
|
-
opts.on("-m", "--merb-root Merb.root", "The path to the Merb.root for the app you want to run (default is current working dir).") do |Merb.root|
|
106
|
-
options[:merb_root] = File.expand_path(Merb.root)
|
107
|
-
end
|
108
|
-
|
109
|
-
opts.on("-i", "--irb-console", "This flag will start merb in irb console mode. All your models and other classes will be available for you in an irb session.") do |console|
|
110
|
-
::Merb::BootLoader.initialize_merb
|
111
|
-
_merb = Class.new do
|
112
|
-
class << self
|
113
|
-
include Merb::GeneralControllerMixin
|
114
|
-
def params() {} end
|
115
|
-
end
|
116
|
-
def self.show_routes(all_opts = false)
|
117
|
-
seen = []
|
118
|
-
unless Merb::Router.named_routes.empty?
|
119
|
-
puts "Named Routes"
|
120
|
-
Merb::Router.named_routes.each do |name,route|
|
121
|
-
puts " #{name}: #{route}"
|
122
|
-
seen << route
|
123
|
-
end
|
124
|
-
end
|
125
|
-
puts "Anonymous Routes"
|
126
|
-
(Merb::Router.routes - seen).each do |route|
|
127
|
-
puts " #{route}"
|
128
|
-
end
|
129
|
-
nil
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
Object.send(:define_method, :merb) {
|
134
|
-
_merb
|
135
|
-
}
|
136
|
-
ARGV.clear # Avoid passing args to IRB
|
137
|
-
require 'irb'
|
138
|
-
require 'irb/completion'
|
139
|
-
def exit
|
140
|
-
exit!
|
141
|
-
end
|
142
|
-
if File.exists? ".irbrc"
|
143
|
-
ENV['IRBRC'] = ".irbrc"
|
144
|
-
end
|
145
|
-
IRB.start
|
146
|
-
exit!
|
147
|
-
end
|
148
|
-
|
149
|
-
opts.on("-s", "--start-drb PORTNUM", "This is the port number to run the drb daemon on for sessions and upload progress monitoring.") do |drb_port|
|
150
|
-
puts "Starting merb drb server on port: #{Merb::Config[:drb_server_port]}"
|
151
|
-
Merb::Server.start(drb_port, :drbserver_start)
|
152
|
-
exit if Merb::Config[:only_drb]
|
153
|
-
end
|
154
|
-
|
155
|
-
opts.on("-l", "--log-level LEVEL", "Log levels can be set to any of these options: DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN") do |loglevel|
|
156
|
-
options[:log_level] = loglevel
|
157
|
-
end
|
158
|
-
|
159
|
-
opts.on("-e", "--environment STRING", "Run merb in the correct mode(development, production, testing)") do |env|
|
160
|
-
options[:environment] ||= env
|
161
|
-
end
|
162
|
-
|
163
|
-
opts.on("-r", "--script-runner ['RUBY CODE'| FULL_SCRIPT_PATH]",
|
164
|
-
"Command-line option to run scripts and/or code in the merb app.") do |code_or_file|
|
165
|
-
::Merb::BootLoader.initialize_merb
|
166
|
-
if File.exists?(code_or_file)
|
167
|
-
eval(File.read(code_or_file))
|
168
|
-
else
|
169
|
-
eval(code_or_file)
|
170
|
-
end
|
171
|
-
exit!
|
172
|
-
end
|
173
|
-
|
174
|
-
opts.on("-P","--generate-plugin PATH", "Generate a fresh merb plugin at PATH.") do |path|
|
175
|
-
require 'merb/generators/merb_plugin'
|
176
|
-
::Merb::PluginGenerator.run path || Dir.pwd
|
177
|
-
exit
|
178
|
-
end
|
179
|
-
|
180
|
-
opts.on("-K", "--graceful PORT or all", "Gracefully kill one merb proceses by port number. Use merb -K all to gracefully kill all merbs.") do |ports|
|
181
|
-
@configuration = defaults.merge(options)
|
182
|
-
Merb::Server.kill(ports, 1)
|
183
|
-
end
|
184
|
-
|
185
|
-
opts.on("-k", "--kill PORT or all", "Kill one merb proceses by port number. Use merb -k all to kill all merbs.") do |ports|
|
186
|
-
@configuration = defaults.merge(options)
|
187
|
-
Merb::Server.kill(ports, 9)
|
188
|
-
end
|
189
|
-
|
190
|
-
opts.on("-M", "--merb-config FILENAME", "This flag is for explicitly declaring the merb app's config file.") do |config|
|
191
|
-
options[:merb_config] = config
|
192
|
-
end
|
193
|
-
|
194
|
-
opts.on("-w", "--webrick", "Run merb using Webrick Rack Adapter instead of mongrel.") do |webport|
|
195
|
-
puts "Starting merb webrick server on port: #{Merb::Config[:port]}"
|
196
|
-
trap('TERM') { exit }
|
197
|
-
Merb::Server.webrick_start(Merb::Config[:port])
|
198
|
-
end
|
199
|
-
|
200
|
-
opts.on("-F", "--fastcgi", "Run merb using FastCGI Rack Adapter instead of mongrel.") do
|
201
|
-
trap('TERM') { exit }
|
202
|
-
Merb::Server.fastcgi_start
|
203
|
-
end
|
204
|
-
|
205
|
-
opts.on("-X", "--mutex on/off", "This flag is for turning the mutex lock on and off.") do |mutex|
|
206
|
-
if mutex == 'off'
|
207
|
-
options[:use_mutex] = false
|
208
|
-
else
|
209
|
-
options[:use_mutex] = true
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
opts.on("-D", "--debugger", "Run merb using rDebug.") do
|
214
|
-
begin
|
215
|
-
require 'ruby-debug'
|
216
|
-
Debugger.start
|
217
|
-
Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
|
218
|
-
puts "Debugger enabled"
|
219
|
-
rescue LoadError
|
220
|
-
puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
|
221
|
-
exit
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
opts.on("-?", "-H", "--help", "Show this help message") do
|
226
|
-
puts opts
|
227
|
-
exit
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
# If we run merb with no arguments and we are not inside a merb root
|
232
|
-
# show the help message
|
233
|
-
if !defined?(Merb.framework_root) && (argv.size == 0) && !File.exists?("#{options[:merb_root] || Merb::Config.defaults[:merb_root]}/config/merb_init.rb")
|
234
|
-
puts "You are not in the root of a merb application...\n"
|
235
|
-
puts opts
|
236
|
-
exit
|
237
|
-
end
|
238
|
-
|
239
|
-
# Parse what we have on the command line
|
240
|
-
opts.parse!(argv)
|
241
|
-
|
242
|
-
# merb <argument> is same as merb -g <argument>
|
243
|
-
if argv.size == 1
|
244
|
-
require 'merb/generators/merb_app/merb_app'
|
245
|
-
::Merb::AppGenerator.run File.expand_path(argv.last)
|
246
|
-
exit!
|
247
|
-
end
|
248
|
-
|
249
|
-
# Load up the configuration from file, but keep the command line
|
250
|
-
# options that may have been chosen. Also, pass-through if we have
|
251
|
-
# a new merb_config path.
|
252
|
-
options = Merb::Config.setup(options[:merb_config]).merge(options)
|
253
|
-
|
254
|
-
# Finally, if all else fails... set the environment to 'development'
|
255
|
-
options[:environment] ||= 'development'
|
256
|
-
|
257
|
-
environment_merb_yml = "#{options[:merb_root]}/config/environments/#{options[:environment]}.yml"
|
258
|
-
|
259
|
-
@configuration = Merb::Config.apply_configuration_from_file options, environment_merb_yml
|
260
|
-
|
261
|
-
case Merb::Config[:environment].to_s
|
262
|
-
when 'production'
|
263
|
-
Merb::Config[:reloader] = Merb::Config.fetch(:reloader, false)
|
264
|
-
Merb::Config[:exception_details] = Merb::Config.fetch(:exception_details, false)
|
265
|
-
Merb::Config[:cache_templates] = true
|
266
|
-
else
|
267
|
-
Merb::Config[:reloader] = Merb::Config.fetch(:reloader, true)
|
268
|
-
Merb::Config[:exception_details] = Merb::Config.fetch(:exception_details, true)
|
269
|
-
end
|
270
|
-
|
271
|
-
Merb::Config[:reloader_time] ||= 0.5 if Merb::Config[:reloader] == true
|
272
|
-
|
273
|
-
|
274
|
-
if Merb::Config[:reloader]
|
275
|
-
Thread.abort_on_exception = true
|
276
|
-
Thread.new do
|
277
|
-
loop do
|
278
|
-
sleep( Merb::Config[:reloader_time] )
|
279
|
-
::Merb::BootLoader.reload if ::Merb::BootLoader.app_loaded?
|
280
|
-
end
|
281
|
-
Thread.exit
|
282
|
-
end
|
283
|
-
end
|
284
|
-
@configuration
|
285
|
-
end
|
286
|
-
|
287
|
-
end # class << self
|
288
|
-
end # Config
|
289
|
-
|
290
|
-
end
|