waves 0.7.3 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/app/Rakefile +11 -19
- data/app/bin/waves-console +3 -5
- data/app/bin/waves-server +3 -5
- data/app/configurations/development.rb.erb +19 -11
- data/app/configurations/mapping.rb.erb +4 -5
- data/app/configurations/production.rb.erb +18 -13
- data/app/{doc/EMTPY → controllers/.gitignore} +0 -0
- data/app/{public/css/EMPTY → doc/.gitignore} +0 -0
- data/app/{public/flash/EMPTY → helpers/.gitignore} +0 -0
- data/app/lib/application.rb.erb +4 -51
- data/app/{public/images/EMPTY → lib/tasks/.gitignore} +0 -0
- data/app/{public/javascript/EMPTY → log/.gitignore} +0 -0
- data/app/{tmp/sessions/EMPTY → models/.gitignore} +0 -0
- data/app/public/css/.gitignore +0 -0
- data/app/public/flash/.gitignore +0 -0
- data/app/public/images/.gitignore +0 -0
- data/app/public/javascript/.gitignore +0 -0
- data/app/schema/migrations/.gitignore +0 -0
- data/app/startup.rb +5 -0
- data/app/templates/layouts/default.mab +2 -2
- data/app/tmp/sessions/.gitignore +0 -0
- data/app/views/.gitignore +0 -0
- data/bin/waves +38 -27
- data/bin/waves-console +3 -25
- data/bin/waves-server +4 -45
- data/lib/commands/waves-console.rb +21 -0
- data/lib/commands/waves-server.rb +55 -0
- data/lib/controllers/base.rb +11 -0
- data/lib/controllers/mixin.rb +130 -102
- data/lib/dispatchers/base.rb +65 -50
- data/lib/dispatchers/default.rb +79 -52
- data/lib/foundations/default.rb +26 -0
- data/lib/foundations/simple.rb +30 -0
- data/lib/helpers/common.rb +60 -56
- data/lib/helpers/default.rb +13 -0
- data/lib/helpers/form.rb +39 -38
- data/lib/helpers/formatting.rb +11 -11
- data/lib/helpers/model.rb +12 -12
- data/lib/helpers/view.rb +13 -13
- data/lib/layers/default_errors.rb +29 -0
- data/lib/layers/mvc.rb +58 -0
- data/lib/layers/orm/active_record.rb +41 -0
- data/lib/layers/orm/active_record/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/active_record/tasks/schema.rb +30 -0
- data/lib/layers/orm/data_mapper.rb +42 -0
- data/lib/layers/orm/filebase.rb +22 -0
- data/lib/layers/orm/migration.rb +70 -0
- data/lib/layers/orm/sequel.rb +82 -0
- data/lib/layers/orm/sequel/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/sequel/tasks/schema.rb +24 -0
- data/lib/layers/simple.rb +39 -0
- data/lib/layers/simple_errors.rb +26 -0
- data/lib/mapping/mapping.rb +222 -120
- data/lib/mapping/pretty_urls.rb +42 -41
- data/lib/renderers/erubis.rb +54 -31
- data/lib/renderers/markaby.rb +28 -28
- data/lib/renderers/mixin.rb +49 -52
- data/lib/runtime/application.rb +66 -48
- data/lib/runtime/blackboard.rb +57 -0
- data/lib/runtime/configuration.rb +117 -101
- data/lib/runtime/console.rb +19 -20
- data/lib/runtime/debugger.rb +9 -0
- data/lib/runtime/logger.rb +43 -37
- data/lib/runtime/mime_types.rb +19 -19
- data/lib/runtime/request.rb +72 -46
- data/lib/runtime/response.rb +37 -37
- data/lib/runtime/response_mixin.rb +26 -23
- data/lib/runtime/response_proxy.rb +25 -24
- data/lib/runtime/server.rb +99 -80
- data/lib/runtime/session.rb +63 -53
- data/lib/tasks/cluster.rb +26 -0
- data/lib/tasks/gem.rb +31 -0
- data/lib/tasks/generate.rb +80 -0
- data/lib/utilities/hash.rb +22 -0
- data/lib/utilities/inflect.rb +194 -0
- data/lib/utilities/integer.rb +15 -12
- data/lib/utilities/kernel.rb +32 -32
- data/lib/utilities/module.rb +11 -4
- data/lib/utilities/object.rb +5 -5
- data/lib/utilities/proc.rb +10 -0
- data/lib/utilities/string.rb +44 -38
- data/lib/utilities/symbol.rb +4 -4
- data/lib/views/base.rb +9 -0
- data/lib/views/mixin.rb +91 -89
- data/lib/waves.rb +29 -9
- metadata +52 -26
- data/app/configurations/default.rb.erb +0 -8
- data/app/controllers/default.rb.erb +0 -29
- data/app/helpers/default.rb.erb +0 -13
- data/app/lib/startup.rb.erb +0 -3
- data/app/lib/tasks/cluster.rb +0 -24
- data/app/lib/tasks/generate.rb +0 -15
- data/app/lib/tasks/schema.rb +0 -29
- data/app/models/default.rb.erb +0 -13
- data/app/schema/migrations/templates/empty.rb.erb +0 -9
- data/app/views/default.rb.erb +0 -13
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'choice'
|
2
|
+
|
3
|
+
Choice.options do
|
4
|
+
header 'Run a waves application server.'
|
5
|
+
header ''
|
6
|
+
option :port do
|
7
|
+
short '-p'
|
8
|
+
long '--port=PORT'
|
9
|
+
desc 'Port to listen on.'
|
10
|
+
desc 'Defaults to value given in configuration.'
|
11
|
+
cast Integer
|
12
|
+
end
|
13
|
+
separator ''
|
14
|
+
option :host do
|
15
|
+
short '-h'
|
16
|
+
long '--host=HOST'
|
17
|
+
desc 'Host or IP address of the host to bind.'
|
18
|
+
desc 'Defaults to value given in configuration.'
|
19
|
+
end
|
20
|
+
separator ''
|
21
|
+
option :mode do
|
22
|
+
short '-c'
|
23
|
+
long '--config=CONFIG'
|
24
|
+
desc 'Configuration to use.'
|
25
|
+
desc 'Defaults to development.'
|
26
|
+
cast Symbol
|
27
|
+
end
|
28
|
+
separator ''
|
29
|
+
option :directory do
|
30
|
+
short '-D'
|
31
|
+
long '--dir=DIR'
|
32
|
+
desc 'Directory containing the application.'
|
33
|
+
desc 'Defaults to the current directory.'
|
34
|
+
end
|
35
|
+
separator ''
|
36
|
+
option :daemon do
|
37
|
+
short '-d'
|
38
|
+
long '--daemon'
|
39
|
+
desc 'Run as a daemon.'
|
40
|
+
end
|
41
|
+
separator ''
|
42
|
+
option :debugger do
|
43
|
+
short '-u'
|
44
|
+
long '--debugger'
|
45
|
+
desc 'Enable ruby-debug.'
|
46
|
+
end
|
47
|
+
separator ''
|
48
|
+
option :startup do
|
49
|
+
short '-s'
|
50
|
+
long '--startup'
|
51
|
+
desc 'Startup file to load.'
|
52
|
+
desc 'Defaults to "lib/startup.rb"'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
Waves::Server.run( Choice.choices )
|
data/lib/controllers/mixin.rb
CHANGED
@@ -1,131 +1,159 @@
|
|
1
1
|
module Waves
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
|
-
# Controllers in Waves are simply classes that provide a request / response
|
4
|
+
# Controllers in Waves are simply classes that provide a request / response
|
5
|
+
# context for operating on a model. While models are essentially just a way
|
6
|
+
# to manage data in an application, controllers manage data in response to
|
7
|
+
# a request. For example, a controller updates a model instance using
|
8
|
+
# parameters from the request.
|
5
9
|
#
|
6
|
-
#
|
10
|
+
# Public controller methods simply return data (a resource), if necessary, that
|
11
|
+
# can be then used by views to determine how to render that data.
|
12
|
+
# Controllers do not determine which view will be invoked. They are
|
13
|
+
# independent of the view; one controller method might be suitable for
|
14
|
+
# several different views. In some cases, controllers can choose to
|
15
|
+
# directly modify the response and possibly even short-circuit the view
|
16
|
+
# entirely. A good example of this is a redirect.
|
7
17
|
#
|
8
|
-
# Controllers, like Views and Mappings, use the Waves::ResponseMixin to
|
18
|
+
# Controllers, like Views and Mappings, use the Waves::ResponseMixin to
|
19
|
+
# provide a rich context for working with the request and response objects.
|
20
|
+
# They can even call other controllers or views using the controllers method.
|
21
|
+
# In addition, they provide some basic reflection (access to the model and
|
22
|
+
# model_name that corresponds to the class name for the given model) and
|
23
|
+
# automatic parameter destructuring. This allows controller methods to access
|
24
|
+
# the request parameters as a hash, so that a POST variable named
|
25
|
+
# <tt>entry.title</tt> is accessed as <tt>params[:entry][:title]</tt>.
|
9
26
|
#
|
10
|
-
# Controllers often do not have to be explicitly defined. Instead, one or more
|
27
|
+
# Controllers often do not have to be explicitly defined. Instead, one or more
|
28
|
+
# default controllers can be defined that are used as exemplars for a given
|
29
|
+
# model. By default, the +waves+ command generates a single default, placed in
|
30
|
+
# the application's <tt>controllers/default.rb</tt> file. This can be modified
|
31
|
+
# to change the default behavior for all controllers. Alternatively, the
|
32
|
+
# <tt>rake generate:controller</tt> command can be used to explicitly define a
|
33
|
+
# controller.
|
11
34
|
#
|
12
35
|
# As an example, the code for the default controller is below for the Blog application.
|
13
36
|
#
|
14
37
|
# module Blog
|
15
|
-
#
|
16
|
-
#
|
38
|
+
# module Controllers
|
39
|
+
# class Default
|
17
40
|
#
|
18
41
|
# # Pick up the default controller methods, like param, url, etc.
|
19
|
-
#
|
42
|
+
# include Waves::Controllers::Mixin
|
20
43
|
#
|
21
44
|
# # This gets me the parameters associated with this model
|
22
|
-
#
|
45
|
+
# def attributes; params[model_name.singular.intern]; end
|
23
46
|
#
|
24
47
|
# # A simple generic delegator to the model
|
25
|
-
#
|
48
|
+
# def all; model.all; end
|
26
49
|
#
|
27
50
|
# # Find a specific instance based on a name or raise a 404
|
28
|
-
#
|
51
|
+
# def find( name ); model[ :name => name ] or not_found; end
|
29
52
|
#
|
30
53
|
# # Create a new instance based on the request params
|
31
|
-
#
|
54
|
+
# def create; model.create( attributes ); end
|
32
55
|
#
|
33
56
|
# # Update an existing record. find will raise a 404 if not found.
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
57
|
+
# def update( name )
|
58
|
+
# instance = find( name )
|
59
|
+
# instance.set( attributes )
|
60
|
+
# instance.save_changes
|
61
|
+
# end
|
39
62
|
#
|
40
63
|
# # Find and delete - or will raise a 404 if it doesn't exist
|
41
|
-
#
|
64
|
+
# def delete( name ); find( name ).destroy; end
|
42
65
|
#
|
43
|
-
#
|
44
|
-
#
|
66
|
+
# end
|
67
|
+
# end
|
45
68
|
# end
|
46
69
|
#
|
47
|
-
# Since the mapping file handles "glueing" controllers to views, controllers
|
70
|
+
# Since the mapping file handles "glueing" controllers to views, controllers
|
71
|
+
# don't have to be at all concerned with views. They don't have to set
|
72
|
+
# instance variables, layouts, or contain logic to select the appropriate
|
73
|
+
# view based on the request. All they do is worry about updating the model
|
74
|
+
# when necessary based on the request.
|
48
75
|
|
49
|
-
|
76
|
+
module Controllers
|
50
77
|
|
51
78
|
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
79
|
+
# Waves::Controllers::Mixin adapts a controller class for use in mappings and provides utility methods.
|
80
|
+
# It is included in controllers autocreated by the Default foundation, so you do not need to include
|
81
|
+
# it in subclasses of the same.
|
82
|
+
#
|
83
|
+
# The utility methods include simple reflection to allow controller methods
|
84
|
+
# to be written generically (i.e., without reference to a specific model) and
|
85
|
+
# parameter destructuring for the request parameters.
|
86
|
+
#
|
87
|
+
|
88
|
+
module Mixin
|
89
|
+
|
90
|
+
attr_reader :request
|
91
|
+
|
92
|
+
include Waves::ResponseMixin
|
93
|
+
|
94
|
+
# When this mixin is included it adds a class method named +process+,
|
95
|
+
# which accepts a request object and a block. The +process+ method initializes the
|
96
|
+
# controller with the request, then evaluates the block using +instance_eval+. This allows the
|
97
|
+
# controller to be used from within a mapping lambda (i.e. a ResponseProxy).
|
98
|
+
|
99
|
+
def self.included( mod )
|
100
|
+
def mod.process( request, &block )
|
101
|
+
self.new( request ).instance_eval( &block )
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def initialize( request )
|
106
|
+
@request = request
|
107
|
+
end
|
108
|
+
|
109
|
+
# The params variable is taken from the request object and "destructured", so that
|
110
|
+
# a parameter named 'blog.title' becomes:
|
111
|
+
#
|
112
|
+
# params['blog']['title']
|
113
|
+
#
|
114
|
+
# If you want to access the original parameters object, you can still do so using
|
115
|
+
# +request.params+ instead of simply +params+.
|
116
|
+
def params; @params ||= destructure(request.params); end
|
117
|
+
|
118
|
+
# Returns the name of the model corresponding to this controller by taking the basename
|
119
|
+
# of the module and converting it to snake case. If the model plurality is different than
|
120
|
+
# the controller, this will not, in fact, be the model name.
|
121
|
+
def model_name; self.class.basename.snake_case; end
|
122
|
+
|
123
|
+
# Returns the model corresponding to this controller by naively assuming that
|
124
|
+
# +model_name+ must be correct. This allows you to write generic controller methods such as:
|
125
|
+
#
|
126
|
+
# model.find( name )
|
127
|
+
#
|
128
|
+
# to find an instance of a given model. Again, the plurality of the controller and
|
129
|
+
# model must be the same for this to work.
|
130
|
+
def model; Waves.application.models[ model_name.intern ]; end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
def destructure(hash)
|
135
|
+
rval = {}
|
136
|
+
hash.keys.map{ |key|key.split('.') }.each do |keys|
|
137
|
+
destructure_with_array_keys(hash,'',keys,rval)
|
138
|
+
end
|
139
|
+
rval
|
140
|
+
end
|
141
|
+
|
142
|
+
def destructure_with_array_keys(hash,prefix,keys,rval)
|
143
|
+
if keys.length == 1
|
144
|
+
val = hash[prefix+keys.first]
|
145
|
+
rval[keys.first.intern] = case val
|
146
|
+
when String then val.strip
|
147
|
+
when Hash then val
|
148
|
+
end
|
149
|
+
else
|
150
|
+
rval = ( rval[keys.first.intern] ||= {} )
|
151
|
+
destructure_with_array_keys(hash,(keys.shift<<'.'),keys,rval)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
data/lib/dispatchers/base.rb
CHANGED
@@ -1,52 +1,67 @@
|
|
1
1
|
module Waves
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
3
|
+
module Dispatchers
|
4
|
+
|
5
|
+
# A NotFoundError means what you think it means. The dispatchers included with Waves do not
|
6
|
+
# natively intercept this exception. Instead an exception handler must be registered in the application
|
7
|
+
# mappings. The Simple foundation registers a minimal handler, while the Default foundation registers
|
8
|
+
# a slightly fleshier one.
|
9
|
+
class NotFoundError < Exception ; end
|
10
|
+
|
11
|
+
# Redirect exceptions are rescued by the Waves dispatcher and used to set the
|
12
|
+
# response status and location.
|
13
|
+
class Redirect < Exception
|
14
|
+
attr_reader :path, :status
|
15
|
+
def initialize( path, status = '302' )
|
16
|
+
@path = path
|
17
|
+
@status = status
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Waves::Dispatchers::Base provides the basic request processing structure.
|
22
|
+
# All other Waves dispatchers should inherit from it. It creates a Waves request,
|
23
|
+
# determines whether to enclose the request processing in a mutex, benchmarks it,
|
24
|
+
# logs it, and handles common exceptions and redirects. Derived classes need only
|
25
|
+
# process the request within the +safe+ method, which must take a Waves::Request and return a Waves::Response.
|
26
|
+
|
27
|
+
class Base
|
28
|
+
|
29
|
+
# As with any Rack application, a Waves dispatcher must provide a call method
|
30
|
+
# that takes an +env+ parameter.
|
31
|
+
def call( env )
|
32
|
+
if Waves.config.synchronize?
|
33
|
+
Waves::Application.instance.synchronize { _call( env ) }
|
34
|
+
else
|
35
|
+
_call( env )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Called by event driven servers like thin and ebb. Returns true if
|
40
|
+
# the server should run the request in a separate thread, as determined by
|
41
|
+
# Configurations::Mapping#threaded?
|
42
|
+
def deferred?( env )
|
43
|
+
Waves::Application.instance.mapping.threaded?( env )
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def _call( env )
|
49
|
+
request = Waves::Request.new( env )
|
50
|
+
response = request.response
|
51
|
+
t = Benchmark.realtime do
|
52
|
+
begin
|
53
|
+
safe( request )
|
54
|
+
rescue Dispatchers::Redirect => redirect
|
55
|
+
response.status = redirect.status
|
56
|
+
response.location = redirect.path
|
57
|
+
end
|
58
|
+
end
|
59
|
+
Waves::Logger.info "#{request.method}: #{request.url} handled in #{(t*1000).round} ms."
|
60
|
+
response.finish
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/lib/dispatchers/default.rb
CHANGED
@@ -1,54 +1,81 @@
|
|
1
1
|
module Waves
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
2
|
+
|
3
|
+
module Dispatchers
|
4
|
+
|
5
|
+
#
|
6
|
+
# Waves::Dispatchers::Default matches requests against an application's mappings to
|
7
|
+
# determine what main action to take, as well as what before, after, always, and exception-handling
|
8
|
+
# blocks must run.
|
9
|
+
#
|
10
|
+
# The default dispatcher also attempts to set the content type based on the
|
11
|
+
# file extension used in the request URL. It does this using the class defined in
|
12
|
+
# the current configuration's +mime_types+ attribute, which defaults to Mongrel's
|
13
|
+
# MIME type handler.
|
14
|
+
#
|
15
|
+
# You can write your own dispatcher and use it in your application's configuration
|
16
|
+
# file. By default, they use the default dispatcher, like this:
|
17
|
+
#
|
18
|
+
# application do
|
19
|
+
# use Rack::ShowExceptions
|
20
|
+
# run Waves::Dispatchers::Default.new
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
|
24
|
+
class Default < Base
|
25
|
+
|
26
|
+
# All dispatchers using the Dispatchers::Base to provide thread-safety, logging, etc.
|
27
|
+
# must provide a +safe+ method to handle creating a response from a request.
|
28
|
+
# Takes a Waves::Request and returns a Waves::Reponse
|
29
|
+
def safe( request )
|
30
|
+
|
31
|
+
response = request.response
|
32
|
+
|
33
|
+
Waves::Application.instance.reload if Waves::Application.instance.debug?
|
34
|
+
response.content_type = Waves::Application.instance.config.mime_types[ request.path ] || 'text/html'
|
35
|
+
|
36
|
+
mapping = Waves::Application.instance.mapping[ request ]
|
37
|
+
|
38
|
+
begin
|
39
|
+
|
40
|
+
mapping[:before].each do | block, args |
|
41
|
+
ResponseProxy.new(request).instance_exec(*args,&block)
|
42
|
+
end
|
43
|
+
|
44
|
+
request.not_found unless mapping[:action]
|
45
|
+
|
46
|
+
block, args = mapping[:action]
|
47
|
+
response.write( ResponseProxy.new(request).instance_exec(*args, &block) )
|
48
|
+
|
49
|
+
mapping[:after].each do | block, args |
|
50
|
+
ResponseProxy.new(request).instance_exec(*args,&block)
|
51
|
+
end
|
52
|
+
|
53
|
+
rescue Exception => e
|
54
|
+
|
55
|
+
handler = mapping[:handlers].detect do | exception, block, args |
|
56
|
+
e.is_a? exception
|
57
|
+
end
|
58
|
+
if handler
|
59
|
+
ResponseProxy.new(request).instance_exec(*handler[2], &handler[1])
|
60
|
+
else
|
61
|
+
raise e
|
62
|
+
end
|
63
|
+
|
64
|
+
ensure
|
65
|
+
mapping[:always].each do | block, args |
|
66
|
+
begin
|
67
|
+
ResponseProxy.new(request).instance_exec(*args,&block)
|
68
|
+
rescue Exception => e
|
69
|
+
Waves::Logger.info e.to_s
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
54
81
|
end
|