hanami-controller 1.3.3 → 2.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -7
- data/README.md +295 -537
- data/hanami-controller.gemspec +3 -3
- data/lib/hanami/action.rb +653 -38
- data/lib/hanami/action/base_params.rb +2 -2
- data/lib/hanami/action/cache.rb +1 -139
- data/lib/hanami/action/cache/cache_control.rb +4 -4
- data/lib/hanami/action/cache/conditional_get.rb +4 -5
- data/lib/hanami/action/cache/directives.rb +1 -1
- data/lib/hanami/action/cache/expires.rb +3 -3
- data/lib/hanami/action/cookie_jar.rb +3 -3
- data/lib/hanami/action/cookies.rb +3 -62
- data/lib/hanami/action/flash.rb +2 -2
- data/lib/hanami/action/glue.rb +5 -31
- data/lib/hanami/action/halt.rb +12 -0
- data/lib/hanami/action/mime.rb +77 -491
- data/lib/hanami/action/params.rb +3 -3
- data/lib/hanami/action/rack/file.rb +1 -1
- data/lib/hanami/action/request.rb +30 -20
- data/lib/hanami/action/response.rb +174 -0
- data/lib/hanami/action/session.rb +8 -117
- data/lib/hanami/action/validatable.rb +2 -2
- data/lib/hanami/controller.rb +0 -210
- data/lib/hanami/controller/configuration.rb +51 -506
- data/lib/hanami/controller/version.rb +1 -1
- metadata +12 -21
- 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.rb +0 -126
- data/lib/hanami/action/exposable/guard.rb +0 -104
- data/lib/hanami/action/head.rb +0 -121
- data/lib/hanami/action/rack.rb +0 -411
- data/lib/hanami/action/rack/callable.rb +0 -47
- data/lib/hanami/action/rack/errors.rb +0 -53
- data/lib/hanami/action/redirect.rb +0 -59
- data/lib/hanami/action/throwable.rb +0 -169
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.0.alpha
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.0.alpha
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,14 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '12'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '12'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rspec
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,26 +119,17 @@ files:
|
|
119
119
|
- lib/hanami/action/cache/conditional_get.rb
|
120
120
|
- lib/hanami/action/cache/directives.rb
|
121
121
|
- lib/hanami/action/cache/expires.rb
|
122
|
-
- lib/hanami/action/callable.rb
|
123
|
-
- lib/hanami/action/callbacks.rb
|
124
|
-
- lib/hanami/action/configurable.rb
|
125
122
|
- lib/hanami/action/cookie_jar.rb
|
126
123
|
- lib/hanami/action/cookies.rb
|
127
|
-
- lib/hanami/action/exposable.rb
|
128
|
-
- lib/hanami/action/exposable/guard.rb
|
129
124
|
- lib/hanami/action/flash.rb
|
130
125
|
- lib/hanami/action/glue.rb
|
131
|
-
- lib/hanami/action/
|
126
|
+
- lib/hanami/action/halt.rb
|
132
127
|
- lib/hanami/action/mime.rb
|
133
128
|
- lib/hanami/action/params.rb
|
134
|
-
- lib/hanami/action/rack.rb
|
135
|
-
- lib/hanami/action/rack/callable.rb
|
136
|
-
- lib/hanami/action/rack/errors.rb
|
137
129
|
- lib/hanami/action/rack/file.rb
|
138
|
-
- lib/hanami/action/redirect.rb
|
139
130
|
- lib/hanami/action/request.rb
|
131
|
+
- lib/hanami/action/response.rb
|
140
132
|
- lib/hanami/action/session.rb
|
141
|
-
- lib/hanami/action/throwable.rb
|
142
133
|
- lib/hanami/action/validatable.rb
|
143
134
|
- lib/hanami/controller.rb
|
144
135
|
- lib/hanami/controller/configuration.rb
|
@@ -157,14 +148,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
148
|
requirements:
|
158
149
|
- - ">="
|
159
150
|
- !ruby/object:Gem::Version
|
160
|
-
version: 2.
|
151
|
+
version: 2.5.0
|
161
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
153
|
requirements:
|
163
|
-
- - "
|
154
|
+
- - ">"
|
164
155
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
156
|
+
version: 1.3.1
|
166
157
|
requirements: []
|
167
|
-
rubygems_version: 3.
|
158
|
+
rubygems_version: 3.0.2
|
168
159
|
signing_key:
|
169
160
|
specification_version: 4
|
170
161
|
summary: Complete, fast and testable actions for Rack and Hanami
|
@@ -1,92 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
module Action
|
3
|
-
module Callable
|
4
|
-
# Execute application logic.
|
5
|
-
# It implements the Rack protocol.
|
6
|
-
#
|
7
|
-
# The request params are passed as an argument to the `#call` method.
|
8
|
-
#
|
9
|
-
# If routed with Hanami::Router, it extracts the relevant bits from the
|
10
|
-
# Rack `env` (eg the requested `:id`).
|
11
|
-
#
|
12
|
-
# Otherwise everything it's passed as it is: the full Rack `env`
|
13
|
-
# in production, and the given `Hash` for unit tests. See the examples
|
14
|
-
# below.
|
15
|
-
#
|
16
|
-
# Application developers are forced to implement this method in their
|
17
|
-
# actions.
|
18
|
-
#
|
19
|
-
# @param env [Hash] the full Rack env or the params. This value may vary,
|
20
|
-
# see the examples below.
|
21
|
-
#
|
22
|
-
# @return [Array] a serialized Rack response (eg. `[200, {}, ["Hi!"]]`)
|
23
|
-
#
|
24
|
-
# @since 0.1.0
|
25
|
-
#
|
26
|
-
# @example with Hanami::Router
|
27
|
-
# require 'hanami/controller'
|
28
|
-
#
|
29
|
-
# class Show
|
30
|
-
# include Hanami::Action
|
31
|
-
#
|
32
|
-
# def call(params)
|
33
|
-
# # ...
|
34
|
-
# puts params # => { id: 23 } extracted from Rack env
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# @example Standalone
|
39
|
-
# require 'hanami/controller'
|
40
|
-
#
|
41
|
-
# class Show
|
42
|
-
# include Hanami::Action
|
43
|
-
#
|
44
|
-
# def call(params)
|
45
|
-
# # ...
|
46
|
-
# puts params
|
47
|
-
# # => { :"rack.version"=>[1, 2],
|
48
|
-
# # :"rack.input"=>#<StringIO:0x007fa563463948>, ... }
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# @example Unit Testing
|
53
|
-
# require 'hanami/controller'
|
54
|
-
#
|
55
|
-
# class Show
|
56
|
-
# include Hanami::Action
|
57
|
-
#
|
58
|
-
# def call(params)
|
59
|
-
# # ...
|
60
|
-
# puts params # => { id: 23, key: 'value' } passed as it is from testing
|
61
|
-
# end
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# action = Show.new
|
65
|
-
# response = action.call({ id: 23, key: 'value' })
|
66
|
-
def call(env)
|
67
|
-
_rescue do
|
68
|
-
@_env = env
|
69
|
-
@headers = ::Rack::Utils::HeaderHash.new(configuration.default_headers)
|
70
|
-
@params = self.class.params_class.new(@_env)
|
71
|
-
super @params
|
72
|
-
end
|
73
|
-
|
74
|
-
finish
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
# Prepare the Rack response before the control is returned to the
|
80
|
-
# webserver.
|
81
|
-
#
|
82
|
-
# @since 0.1.0
|
83
|
-
# @api private
|
84
|
-
#
|
85
|
-
# @see Hanami::Action#finish
|
86
|
-
def finish
|
87
|
-
super
|
88
|
-
response
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,214 +0,0 @@
|
|
1
|
-
require 'hanami/utils/class_attribute'
|
2
|
-
require 'hanami/utils/callbacks'
|
3
|
-
|
4
|
-
module Hanami
|
5
|
-
module Action
|
6
|
-
# Before and after callbacks
|
7
|
-
#
|
8
|
-
# @since 0.1.0
|
9
|
-
# @see Hanami::Action::ClassMethods#before
|
10
|
-
# @see Hanami::Action::ClassMethods#after
|
11
|
-
module Callbacks
|
12
|
-
# Override Ruby's hook for modules.
|
13
|
-
# It includes callbacks logic
|
14
|
-
#
|
15
|
-
# @param base [Class] the target action
|
16
|
-
#
|
17
|
-
# @since 0.1.0
|
18
|
-
# @api private
|
19
|
-
#
|
20
|
-
# @see http://www.ruby-doc.org/core/Module.html#method-i-included
|
21
|
-
def self.included(base)
|
22
|
-
base.class_eval do
|
23
|
-
extend ClassMethods
|
24
|
-
prepend InstanceMethods
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Callbacks API class methods
|
29
|
-
#
|
30
|
-
# @since 0.1.0
|
31
|
-
# @api private
|
32
|
-
module ClassMethods
|
33
|
-
# Override Ruby's hook for modules.
|
34
|
-
# It includes callbacks logic
|
35
|
-
#
|
36
|
-
# @param base [Class] the target action
|
37
|
-
#
|
38
|
-
# @since 0.1.0
|
39
|
-
# @api private
|
40
|
-
#
|
41
|
-
# @see http://www.ruby-doc.org/core/Module.html#method-i-extended
|
42
|
-
def self.extended(base)
|
43
|
-
base.class_eval do
|
44
|
-
include Utils::ClassAttribute
|
45
|
-
|
46
|
-
class_attribute :before_callbacks
|
47
|
-
self.before_callbacks = Utils::Callbacks::Chain.new
|
48
|
-
|
49
|
-
class_attribute :after_callbacks
|
50
|
-
self.after_callbacks = Utils::Callbacks::Chain.new
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Define a callback for an Action.
|
55
|
-
# The callback will be executed **before** the action is called, in the
|
56
|
-
# order they are added.
|
57
|
-
#
|
58
|
-
# @param callbacks [Symbol, Array<Symbol>] a single or multiple symbol(s)
|
59
|
-
# each of them is representing a name of a method available in the
|
60
|
-
# context of the Action.
|
61
|
-
#
|
62
|
-
# @param blk [Proc] an anonymous function to be executed
|
63
|
-
#
|
64
|
-
# @return [void]
|
65
|
-
#
|
66
|
-
# @since 0.3.2
|
67
|
-
#
|
68
|
-
# @see Hanami::Action::Callbacks::ClassMethods#append_after
|
69
|
-
#
|
70
|
-
# @example Method names (symbols)
|
71
|
-
# require 'hanami/controller'
|
72
|
-
#
|
73
|
-
# class Show
|
74
|
-
# include Hanami::Action
|
75
|
-
#
|
76
|
-
# before :authenticate, :set_article
|
77
|
-
#
|
78
|
-
# def call(params)
|
79
|
-
# end
|
80
|
-
#
|
81
|
-
# private
|
82
|
-
# def authenticate
|
83
|
-
# # ...
|
84
|
-
# end
|
85
|
-
#
|
86
|
-
# # `params` in the method signature is optional
|
87
|
-
# def set_article(params)
|
88
|
-
# @article = Article.find params[:id]
|
89
|
-
# end
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# # The order of execution will be:
|
93
|
-
# #
|
94
|
-
# # 1. #authenticate
|
95
|
-
# # 2. #set_article
|
96
|
-
# # 3. #call
|
97
|
-
#
|
98
|
-
# @example Anonymous functions (Procs)
|
99
|
-
# require 'hanami/controller'
|
100
|
-
#
|
101
|
-
# class Show
|
102
|
-
# include Hanami::Action
|
103
|
-
#
|
104
|
-
# before { ... } # 1 do some authentication stuff
|
105
|
-
# before {|params| @article = Article.find params[:id] } # 2
|
106
|
-
#
|
107
|
-
# def call(params)
|
108
|
-
# end
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
# # The order of execution will be:
|
112
|
-
# #
|
113
|
-
# # 1. authentication
|
114
|
-
# # 2. set the article
|
115
|
-
# # 3. #call
|
116
|
-
def append_before(*callbacks, &blk)
|
117
|
-
before_callbacks.append(*callbacks, &blk)
|
118
|
-
end
|
119
|
-
|
120
|
-
# @since 0.1.0
|
121
|
-
alias_method :before, :append_before
|
122
|
-
|
123
|
-
# Define a callback for an Action.
|
124
|
-
# The callback will be executed **after** the action is called, in the
|
125
|
-
# order they are added.
|
126
|
-
#
|
127
|
-
# @param callbacks [Symbol, Array<Symbol>] a single or multiple symbol(s)
|
128
|
-
# each of them is representing a name of a method available in the
|
129
|
-
# context of the Action.
|
130
|
-
#
|
131
|
-
# @param blk [Proc] an anonymous function to be executed
|
132
|
-
#
|
133
|
-
# @return [void]
|
134
|
-
#
|
135
|
-
# @since 0.3.2
|
136
|
-
#
|
137
|
-
# @see Hanami::Action::Callbacks::ClassMethods#append_before
|
138
|
-
def append_after(*callbacks, &blk)
|
139
|
-
after_callbacks.append(*callbacks, &blk)
|
140
|
-
end
|
141
|
-
|
142
|
-
# @since 0.1.0
|
143
|
-
alias_method :after, :append_after
|
144
|
-
|
145
|
-
# Define a callback for an Action.
|
146
|
-
# The callback will be executed **before** the action is called.
|
147
|
-
# It will add the callback at the beginning of the callbacks' chain.
|
148
|
-
#
|
149
|
-
# @param callbacks [Symbol, Array<Symbol>] a single or multiple symbol(s)
|
150
|
-
# each of them is representing a name of a method available in the
|
151
|
-
# context of the Action.
|
152
|
-
#
|
153
|
-
# @param blk [Proc] an anonymous function to be executed
|
154
|
-
#
|
155
|
-
# @return [void]
|
156
|
-
#
|
157
|
-
# @since 0.3.2
|
158
|
-
#
|
159
|
-
# @see Hanami::Action::Callbacks::ClassMethods#prepend_after
|
160
|
-
def prepend_before(*callbacks, &blk)
|
161
|
-
before_callbacks.prepend(*callbacks, &blk)
|
162
|
-
end
|
163
|
-
|
164
|
-
# Define a callback for an Action.
|
165
|
-
# The callback will be executed **after** the action is called.
|
166
|
-
# It will add the callback at the beginning of the callbacks' chain.
|
167
|
-
#
|
168
|
-
# @param callbacks [Symbol, Array<Symbol>] a single or multiple symbol(s)
|
169
|
-
# each of them is representing a name of a method available in the
|
170
|
-
# context of the Action.
|
171
|
-
#
|
172
|
-
# @param blk [Proc] an anonymous function to be executed
|
173
|
-
#
|
174
|
-
# @return [void]
|
175
|
-
#
|
176
|
-
# @since 0.3.2
|
177
|
-
#
|
178
|
-
# @see Hanami::Action::Callbacks::ClassMethods#prepend_before
|
179
|
-
def prepend_after(*callbacks, &blk)
|
180
|
-
after_callbacks.prepend(*callbacks, &blk)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
# Callbacks API instance methods
|
185
|
-
#
|
186
|
-
# @since 0.1.0
|
187
|
-
# @api private
|
188
|
-
module InstanceMethods
|
189
|
-
# Implements the Rack/Hanami::Action protocol
|
190
|
-
#
|
191
|
-
# @since 0.1.0
|
192
|
-
# @api private
|
193
|
-
def call(params)
|
194
|
-
_run_before_callbacks(params)
|
195
|
-
super
|
196
|
-
_run_after_callbacks(params)
|
197
|
-
end
|
198
|
-
|
199
|
-
private
|
200
|
-
# @since 0.1.0
|
201
|
-
# @api private
|
202
|
-
def _run_before_callbacks(params)
|
203
|
-
self.class.before_callbacks.run(self, params)
|
204
|
-
end
|
205
|
-
|
206
|
-
# @since 0.1.0
|
207
|
-
# @api private
|
208
|
-
def _run_after_callbacks(params)
|
209
|
-
self.class.after_callbacks.run(self, params)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'hanami/utils/class_attribute'
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
module Action
|
5
|
-
# Configuration API
|
6
|
-
#
|
7
|
-
# @since 0.2.0
|
8
|
-
#
|
9
|
-
# @see Hanami::Controller::Configuration
|
10
|
-
module Configurable
|
11
|
-
# Override Ruby's hook for modules.
|
12
|
-
# It includes configuration logic
|
13
|
-
#
|
14
|
-
# @param base [Class] the target action
|
15
|
-
#
|
16
|
-
# @since 0.2.0
|
17
|
-
# @api private
|
18
|
-
#
|
19
|
-
# @see http://www.ruby-doc.org/core-2.1.2/Module.html#method-i-included
|
20
|
-
#
|
21
|
-
# @example
|
22
|
-
# require 'hanami/controller'
|
23
|
-
#
|
24
|
-
# class Show
|
25
|
-
# include Hanami::Action
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# Show.configuration
|
29
|
-
def self.included(base)
|
30
|
-
config = Hanami::Controller::Configuration.for(base)
|
31
|
-
|
32
|
-
base.class_eval do
|
33
|
-
include Utils::ClassAttribute
|
34
|
-
|
35
|
-
class_attribute :configuration
|
36
|
-
self.configuration = config
|
37
|
-
end
|
38
|
-
|
39
|
-
config.copy!(base)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
# @since 0.2.0
|
45
|
-
def configuration
|
46
|
-
self.class.configuration
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|