lotus-controller 0.4.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -1
- data/LICENSE.md +1 -1
- data/README.md +35 -2
- data/lib/lotus/action/head.rb +1 -1
- data/lib/lotus/action/mime.rb +10 -5
- data/lib/lotus/action/session.rb +0 -2
- data/lib/lotus/action/throwable.rb +15 -0
- data/lib/lotus/controller.rb +2 -1
- data/lib/lotus/controller/configuration.rb +8 -11
- data/lib/lotus/controller/error.rb +7 -0
- data/lib/lotus/controller/version.rb +1 -1
- data/lotus-controller.gemspec +2 -2
- metadata +8 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2ff1fea9be3ce5d7e3cb2fd0555efbf3928d0f7
|
4
|
+
data.tar.gz: a7eac7e0477f45078bf77172a9c179aa712be57a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaab2895b510bedd269fc9bb9147c50af9e742b7a99041a22bb35a767e9bd195955f377ecd8ba2e0c7452ae4776e7aba213d8f3bbfa230f8af21361658869632
|
7
|
+
data.tar.gz: b25f2829ca7b31440d2e768231d9ba2c5a88a85aa09c71ffe44cadcff7c396d35cab2a7387b0a04db4aacf62bcb6a9be9a4f36759f3ca47f577c3447df695a9a
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
# Lotus::Controller
|
2
2
|
Complete, fast and testable actions for Rack
|
3
3
|
|
4
|
+
## v0.5.0 - 2016-01-12
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Reference a raised exception in Rack env's `rack.exception`. Compatibility with exception reporting SaaS.
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- [Cainã Costa] Ensure Rack environment to be always available for sessions unit tests
|
10
|
+
- [Luca Guidi] Ensure superclass exceptions to not shadow subclasses during exception handling (eg. `CustomError` handler will take precedence over `StandardError`)
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- [Luca Guidi] Removed `Lotus::Controller::Configuration#default_format`
|
14
|
+
- [Cainã Costa] Made `Lotus::Action#session` a public method for improved unit testing
|
15
|
+
- [Karim Tarek] Introduced `Lotus::Controller::Error` and let all the framework exceptions to inherit from it.
|
16
|
+
|
4
17
|
## v0.4.6 - 2015-12-04
|
5
18
|
### Added
|
6
|
-
- [Luca Guidi] Allow to force custom headers for responses that shouldn't include them (eg 204). Override `#keep_response_header?(header)` in action
|
19
|
+
- [Luca Guidi] Allow to force custom headers for responses that according to RFC shouldn't include them (eg 204). Override `#keep_response_header?(header)` in action
|
7
20
|
|
8
21
|
## v0.4.5 - 2015-09-30
|
9
22
|
### Added
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -921,6 +921,37 @@ action.call({ 'HTTP_ACCEPT' => '*/*' }) # => Content-Type 'application/custom'
|
|
921
921
|
action.format # => :custom
|
922
922
|
```
|
923
923
|
|
924
|
+
### Streamed Responses
|
925
|
+
|
926
|
+
When the work to be done by the server takes time, it may be a good idea to stream your response. Here's an example of a streamed CSV.
|
927
|
+
|
928
|
+
```ruby
|
929
|
+
Lotus::Controller.configure do
|
930
|
+
format csv: 'text/csv'
|
931
|
+
middleware.use ::Rack::Chunked
|
932
|
+
end
|
933
|
+
|
934
|
+
class Csv
|
935
|
+
include Lotus::Action
|
936
|
+
|
937
|
+
def call(params)
|
938
|
+
self.format = :csv
|
939
|
+
self.body = Enumerator.new do |yielder|
|
940
|
+
yielder << csv_header
|
941
|
+
|
942
|
+
# Expensive operation is streamed as each line becomes available
|
943
|
+
csv_body.each_line do |line|
|
944
|
+
yielder << line
|
945
|
+
end
|
946
|
+
end
|
947
|
+
end
|
948
|
+
end
|
949
|
+
```
|
950
|
+
|
951
|
+
Note:
|
952
|
+
* In development, Lotus' code reloading needs to be disabled for streaming to work. This is because `Shotgun` interferes with the streaming action. You can disable it like this `lotus server --code-reloading=false`
|
953
|
+
* Streaming does not work with WEBrick as it buffers its response. We recommend using `puma`, though you may find success with other servers
|
954
|
+
|
924
955
|
### No rendering, please
|
925
956
|
|
926
957
|
Lotus::Controller is designed to be a pure HTTP endpoint, rendering belongs to other layers of MVC.
|
@@ -1131,7 +1162,9 @@ Articles::Create.new.call({})
|
|
1131
1162
|
### Thread safety
|
1132
1163
|
|
1133
1164
|
An Action is **mutable**. When used without Lotus::Router, be sure to instantiate an
|
1134
|
-
action for each request.
|
1165
|
+
action for each request. The same advice applies when using
|
1166
|
+
Lotus::Router but NOT routing to `mycontroller#myaction` but instead
|
1167
|
+
routing direct to a class.
|
1135
1168
|
|
1136
1169
|
```ruby
|
1137
1170
|
# config.ru
|
@@ -1169,4 +1202,4 @@ __Lotus::Controller__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
|
1169
1202
|
|
1170
1203
|
## Copyright
|
1171
1204
|
|
1172
|
-
Copyright © 2014-
|
1205
|
+
Copyright © 2014-2016 Luca Guidi – Released under MIT License
|
data/lib/lotus/action/head.rb
CHANGED
data/lib/lotus/action/mime.rb
CHANGED
@@ -473,12 +473,17 @@ module Lotus
|
|
473
473
|
[match, quality]
|
474
474
|
end.compact
|
475
475
|
|
476
|
-
|
477
|
-
|
478
|
-
|
476
|
+
if Lotus::Utils.jruby?
|
477
|
+
# See https://github.com/lotus/controller/issues/59
|
478
|
+
# See https://github.com/lotus/controller/issues/104
|
479
|
+
values.reverse!
|
480
|
+
else
|
481
|
+
# See https://github.com/jruby/jruby/issues/3004
|
482
|
+
values.sort!
|
483
|
+
end
|
479
484
|
|
480
|
-
value
|
481
|
-
(match.split('/', 2).count('*') * -10) + quality
|
485
|
+
value = values.sort_by do |match, quality|
|
486
|
+
(match.split('/'.freeze, 2).count('*'.freeze) * -10) + quality
|
482
487
|
end.last
|
483
488
|
|
484
489
|
value.first if value
|
data/lib/lotus/action/session.rb
CHANGED
@@ -15,6 +15,19 @@ module Lotus
|
|
15
15
|
# @api private
|
16
16
|
RACK_ERRORS = 'rack.errors'.freeze
|
17
17
|
|
18
|
+
# This isn't part of Rack SPEC
|
19
|
+
#
|
20
|
+
# Exception notifiers use <tt>rack.exception</tt> instead of
|
21
|
+
# <tt>rack.errors</tt>, so we need to support it.
|
22
|
+
#
|
23
|
+
# @since 0.5.0
|
24
|
+
# @api private
|
25
|
+
#
|
26
|
+
# @see Lotus::Action::Throwable::RACK_ERRORS
|
27
|
+
# @see http://www.rubydoc.info/github/rack/rack/file/SPEC#The_Error_Stream
|
28
|
+
# @see https://github.com/lotus/controller/issues/133
|
29
|
+
RACK_EXCEPTION = 'rack.exception'.freeze
|
30
|
+
|
18
31
|
def self.included(base)
|
19
32
|
base.extend ClassMethods
|
20
33
|
end
|
@@ -140,6 +153,8 @@ module Lotus
|
|
140
153
|
def _reference_in_rack_errors(exception)
|
141
154
|
return if configuration.handled_exception?(exception)
|
142
155
|
|
156
|
+
@_env[RACK_EXCEPTION] = exception
|
157
|
+
|
143
158
|
if errors = @_env[RACK_ERRORS]
|
144
159
|
errors.write(_dump_exception(exception))
|
145
160
|
errors.flush
|
data/lib/lotus/controller.rb
CHANGED
@@ -2,6 +2,7 @@ require 'lotus/utils/class_attribute'
|
|
2
2
|
require 'lotus/action'
|
3
3
|
require 'lotus/controller/configuration'
|
4
4
|
require 'lotus/controller/version'
|
5
|
+
require 'lotus/controller/error'
|
5
6
|
|
6
7
|
module Lotus
|
7
8
|
# A set of logically grouped actions
|
@@ -35,7 +36,7 @@ module Lotus
|
|
35
36
|
# @since 0.2.0
|
36
37
|
#
|
37
38
|
# @see Lotus::Action::Mime#format=
|
38
|
-
class UnknownFormatError < ::
|
39
|
+
class UnknownFormatError < Lotus::Controller::Error
|
39
40
|
def initialize(format)
|
40
41
|
super("Cannot find a corresponding Mime type for '#{ format }'. Please configure it with Lotus::Controller::Configuration#format.")
|
41
42
|
end
|
@@ -180,6 +180,7 @@ module Lotus
|
|
180
180
|
# end
|
181
181
|
def handle_exception(exception)
|
182
182
|
@handled_exceptions.merge!(exception)
|
183
|
+
_sort_handled_exceptions!
|
183
184
|
end
|
184
185
|
|
185
186
|
# Return a callable handler for the given exception
|
@@ -450,17 +451,6 @@ module Lotus
|
|
450
451
|
end
|
451
452
|
end
|
452
453
|
|
453
|
-
# Set a format as default fallback for all the requests without a strict
|
454
|
-
# requirement for the mime type.
|
455
|
-
#
|
456
|
-
# @since 0.2.0
|
457
|
-
#
|
458
|
-
# @deprecated Use {#default_request_format} instead.
|
459
|
-
def default_format(format = nil)
|
460
|
-
Lotus::Utils::Deprecation.new('default_format is deprecated, please use default_request_format')
|
461
|
-
default_request_format(format)
|
462
|
-
end
|
463
|
-
|
464
454
|
# Set a format to be used for all responses regardless of the request type.
|
465
455
|
#
|
466
456
|
# The given format must be coercible to a symbol, and be a valid mime type
|
@@ -693,6 +683,13 @@ module Lotus
|
|
693
683
|
end
|
694
684
|
|
695
685
|
protected
|
686
|
+
# @since 0.5.0
|
687
|
+
# @api private
|
688
|
+
def _sort_handled_exceptions!
|
689
|
+
@handled_exceptions = Hash[
|
690
|
+
@handled_exceptions.sort{|(ex1,_),(ex2,_)| ex1.ancestors.include?(ex2) ? -1 : 1 }
|
691
|
+
]
|
692
|
+
end
|
696
693
|
|
697
694
|
attr_accessor :handled_exceptions
|
698
695
|
attr_accessor :formats
|
data/lotus-controller.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.required_ruby_version = '>= 2.0.0'
|
21
21
|
|
22
22
|
spec.add_dependency 'rack', '~> 1.6', '>= 1.6.2'
|
23
|
-
spec.add_dependency 'lotus-utils', '~> 0.
|
24
|
-
spec.add_dependency 'lotus-validations', '~> 0.
|
23
|
+
spec.add_dependency 'lotus-utils', '~> 0.6'
|
24
|
+
spec.add_dependency 'lotus-validations', '~> 0.4'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
27
27
|
spec.add_development_dependency 'minitest', '~> 5'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|
@@ -38,34 +38,28 @@ dependencies:
|
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0.
|
41
|
+
version: '0.6'
|
42
42
|
type: :runtime
|
43
43
|
prerelease: false
|
44
44
|
version_requirements: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '0.
|
48
|
+
version: '0.6'
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: lotus-validations
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '0.
|
56
|
-
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: 0.3.3
|
55
|
+
version: '0.4'
|
59
56
|
type: :runtime
|
60
57
|
prerelease: false
|
61
58
|
version_requirements: !ruby/object:Gem::Requirement
|
62
59
|
requirements:
|
63
60
|
- - "~>"
|
64
61
|
- !ruby/object:Gem::Version
|
65
|
-
version: '0.
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.3.3
|
62
|
+
version: '0.4'
|
69
63
|
- !ruby/object:Gem::Dependency
|
70
64
|
name: bundler
|
71
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,6 +156,7 @@ files:
|
|
162
156
|
- lib/lotus/action/validatable.rb
|
163
157
|
- lib/lotus/controller.rb
|
164
158
|
- lib/lotus/controller/configuration.rb
|
159
|
+
- lib/lotus/controller/error.rb
|
165
160
|
- lib/lotus/controller/version.rb
|
166
161
|
- lib/lotus/http/status.rb
|
167
162
|
- lotus-controller.gemspec
|
@@ -185,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
180
|
version: '0'
|
186
181
|
requirements: []
|
187
182
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.5.1
|
189
184
|
signing_key:
|
190
185
|
specification_version: 4
|
191
186
|
summary: Complete, fast and testable actions for Rack and Lotus
|