hanami-controller 1.3.3 → 2.0.0.alpha4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +82 -0
- data/LICENSE.md +1 -1
- data/README.md +299 -537
- data/hanami-controller.gemspec +4 -3
- data/lib/hanami/action/application_action.rb +131 -0
- data/lib/hanami/action/application_configuration/content_security_policy.rb +118 -0
- data/lib/hanami/action/application_configuration/cookies.rb +29 -0
- data/lib/hanami/action/application_configuration/sessions.rb +46 -0
- data/lib/hanami/action/application_configuration.rb +90 -0
- data/lib/hanami/action/base_params.rb +2 -2
- data/lib/hanami/action/cache/cache_control.rb +4 -4
- data/lib/hanami/action/cache/conditional_get.rb +3 -1
- data/lib/hanami/action/cache/directives.rb +1 -1
- data/lib/hanami/action/cache/expires.rb +3 -3
- data/lib/hanami/action/cache.rb +1 -139
- data/lib/hanami/action/configuration.rb +428 -0
- data/lib/hanami/action/cookie_jar.rb +3 -3
- data/lib/hanami/action/cookies.rb +3 -62
- data/lib/hanami/action/csrf_protection.rb +214 -0
- data/lib/hanami/action/flash.rb +102 -207
- data/lib/hanami/action/glue.rb +5 -31
- data/lib/hanami/action/halt.rb +12 -0
- data/lib/hanami/action/mime.rb +78 -485
- data/lib/hanami/action/params.rb +2 -2
- data/lib/hanami/action/rack/file.rb +1 -1
- data/lib/hanami/action/request.rb +30 -20
- data/lib/hanami/action/response.rb +193 -0
- data/lib/hanami/action/session.rb +11 -128
- data/lib/hanami/action/standalone_action.rb +578 -0
- data/lib/hanami/action/validatable.rb +1 -1
- data/lib/hanami/action/view_name_inferrer.rb +46 -0
- data/lib/hanami/action.rb +129 -73
- data/lib/hanami/controller/version.rb +1 -1
- data/lib/hanami/controller.rb +0 -227
- data/lib/hanami/http/status.rb +2 -2
- metadata +44 -26
- data/lib/hanami/action/callable.rb +0 -92
- data/lib/hanami/action/callbacks.rb +0 -214
- data/lib/hanami/action/configurable.rb +0 -50
- data/lib/hanami/action/exposable/guard.rb +0 -104
- data/lib/hanami/action/exposable.rb +0 -126
- data/lib/hanami/action/head.rb +0 -121
- data/lib/hanami/action/rack/callable.rb +0 -47
- data/lib/hanami/action/rack/errors.rb +0 -53
- data/lib/hanami/action/rack.rb +0 -411
- data/lib/hanami/action/redirect.rb +0 -59
- data/lib/hanami/action/throwable.rb +0 -169
- data/lib/hanami/controller/configuration.rb +0 -763
- data/lib/hanami-controller.rb +0 -1
@@ -1,169 +0,0 @@
|
|
1
|
-
require 'hanami/utils/class_attribute'
|
2
|
-
require 'hanami/http/status'
|
3
|
-
require 'hanami/action/rack/errors'
|
4
|
-
|
5
|
-
module Hanami
|
6
|
-
module Action
|
7
|
-
# Throw API
|
8
|
-
#
|
9
|
-
# @since 0.1.0
|
10
|
-
#
|
11
|
-
# @see Hanami::Action::Throwable::ClassMethods#handle_exception
|
12
|
-
# @see Hanami::Action::Throwable#halt
|
13
|
-
# @see Hanami::Action::Throwable#status
|
14
|
-
module Throwable
|
15
|
-
# @since 0.1.0
|
16
|
-
# @api private
|
17
|
-
def self.included(base)
|
18
|
-
base.extend ClassMethods
|
19
|
-
end
|
20
|
-
|
21
|
-
# Throw API class methods
|
22
|
-
#
|
23
|
-
# @since 0.1.0
|
24
|
-
# @api private
|
25
|
-
module ClassMethods
|
26
|
-
private
|
27
|
-
|
28
|
-
# Handle the given exception with an HTTP status code.
|
29
|
-
#
|
30
|
-
# When the exception is raise during #call execution, it will be
|
31
|
-
# translated into the associated HTTP status.
|
32
|
-
#
|
33
|
-
# This is a fine grained control, for a global configuration see
|
34
|
-
# Hanami::Action.handled_exceptions
|
35
|
-
#
|
36
|
-
# @param exception [Hash] the exception class must be the key and the
|
37
|
-
# HTTP status the value of the hash
|
38
|
-
#
|
39
|
-
# @since 0.1.0
|
40
|
-
#
|
41
|
-
# @see Hanami::Action.handled_exceptions
|
42
|
-
#
|
43
|
-
# @example
|
44
|
-
# require 'hanami/controller'
|
45
|
-
#
|
46
|
-
# class Show
|
47
|
-
# include Hanami::Action
|
48
|
-
# handle_exception RecordNotFound => 404
|
49
|
-
#
|
50
|
-
# def call(params)
|
51
|
-
# # ...
|
52
|
-
# raise RecordNotFound.new
|
53
|
-
# end
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# Show.new.call({id: 1}) # => [404, {}, ['Not Found']]
|
57
|
-
def handle_exception(exception)
|
58
|
-
configuration.handle_exception(exception)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
protected
|
63
|
-
|
64
|
-
# Halt the action execution with the given HTTP status code and message.
|
65
|
-
#
|
66
|
-
# When used, the execution of a callback or of an action is interrupted
|
67
|
-
# and the control returns to the framework, that decides how to handle
|
68
|
-
# the event.
|
69
|
-
#
|
70
|
-
# If a message is provided, it sets the response body with the message.
|
71
|
-
# Otherwise, it sets the response body with the default message associated
|
72
|
-
# to the code (eg 404 will set `"Not Found"`).
|
73
|
-
#
|
74
|
-
# @param code [Fixnum] a valid HTTP status code
|
75
|
-
# @param message [String] the response body
|
76
|
-
#
|
77
|
-
# @since 0.2.0
|
78
|
-
#
|
79
|
-
# @see Hanami::Controller#handled_exceptions
|
80
|
-
# @see Hanami::Action::Throwable#handle_exception
|
81
|
-
# @see Hanami::Http::Status:ALL
|
82
|
-
#
|
83
|
-
# @example Basic usage
|
84
|
-
# require 'hanami/controller'
|
85
|
-
#
|
86
|
-
# class Show
|
87
|
-
# def call(params)
|
88
|
-
# halt 404
|
89
|
-
# end
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# # => [404, {}, ["Not Found"]]
|
93
|
-
#
|
94
|
-
# @example Custom message
|
95
|
-
# require 'hanami/controller'
|
96
|
-
#
|
97
|
-
# class Show
|
98
|
-
# def call(params)
|
99
|
-
# halt 404, "This is not the droid you're looking for."
|
100
|
-
# end
|
101
|
-
# end
|
102
|
-
#
|
103
|
-
# # => [404, {}, ["This is not the droid you're looking for."]]
|
104
|
-
def halt(code, message = nil)
|
105
|
-
message ||= Http::Status.message_for(code)
|
106
|
-
status(code, message)
|
107
|
-
|
108
|
-
throw :halt
|
109
|
-
end
|
110
|
-
|
111
|
-
# Sets the given code and message for the response
|
112
|
-
#
|
113
|
-
# @param code [Fixnum] a valid HTTP status code
|
114
|
-
# @param message [String] the response body
|
115
|
-
#
|
116
|
-
# @since 0.1.0
|
117
|
-
# @see Hanami::Http::Status:ALL
|
118
|
-
def status(code, message)
|
119
|
-
self.status = code
|
120
|
-
self.body = message
|
121
|
-
end
|
122
|
-
|
123
|
-
private
|
124
|
-
# @since 0.1.0
|
125
|
-
# @api private
|
126
|
-
def _rescue
|
127
|
-
catch :halt do
|
128
|
-
begin
|
129
|
-
yield
|
130
|
-
rescue => exception
|
131
|
-
_reference_in_rack_errors(exception)
|
132
|
-
_handle_exception(exception)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# @since 0.2.0
|
138
|
-
# @api private
|
139
|
-
def _reference_in_rack_errors(exception)
|
140
|
-
return if configuration.handled_exception?(exception)
|
141
|
-
|
142
|
-
Hanami::Action::Rack::Errors.set(@_env, exception)
|
143
|
-
end
|
144
|
-
|
145
|
-
# @since 0.1.0
|
146
|
-
# @api private
|
147
|
-
def _handle_exception(exception)
|
148
|
-
raise unless configuration.handle_exceptions
|
149
|
-
|
150
|
-
instance_exec(
|
151
|
-
exception,
|
152
|
-
&_exception_handler(exception)
|
153
|
-
)
|
154
|
-
end
|
155
|
-
|
156
|
-
# @since 0.3.0
|
157
|
-
# @api private
|
158
|
-
def _exception_handler(exception)
|
159
|
-
handler = configuration.exception_handler(exception)
|
160
|
-
|
161
|
-
if respond_to?(handler.to_s, true)
|
162
|
-
method(handler)
|
163
|
-
else
|
164
|
-
->(ex) { halt handler }
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|