lotus-controller 0.2.0 → 0.3.0
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 +65 -127
- data/README.md +289 -89
- data/lib/lotus/action.rb +12 -6
- data/lib/lotus/action/cache.rb +174 -0
- data/lib/lotus/action/cache/cache_control.rb +70 -0
- data/lib/lotus/action/cache/conditional_get.rb +93 -0
- data/lib/lotus/action/cache/directives.rb +99 -0
- data/lib/lotus/action/cache/expires.rb +73 -0
- data/lib/lotus/action/callable.rb +3 -2
- data/lib/lotus/action/callbacks.rb +8 -0
- data/lib/lotus/action/configurable.rb +3 -2
- data/lib/lotus/action/cookies.rb +13 -12
- data/lib/lotus/action/exposable.rb +31 -4
- data/lib/lotus/action/flash.rb +141 -0
- data/lib/lotus/action/glue.rb +35 -0
- data/lib/lotus/action/mime.rb +82 -4
- data/lib/lotus/action/params.rb +87 -3
- data/lib/lotus/action/rack.rb +66 -51
- data/lib/lotus/action/redirect.rb +21 -3
- data/lib/lotus/action/session.rb +97 -0
- data/lib/lotus/action/throwable.rb +24 -4
- data/lib/lotus/action/validatable.rb +128 -0
- data/lib/lotus/controller.rb +11 -25
- data/lib/lotus/controller/configuration.rb +117 -66
- data/lib/lotus/controller/version.rb +1 -1
- data/lib/lotus/http/status.rb +5 -1
- data/lib/rack-patch.rb +8 -2
- data/lotus-controller.gemspec +6 -4
- metadata +54 -21
- data/lib/lotus/controller/dsl.rb +0 -56
data/lib/lotus/http/status.rb
CHANGED
@@ -14,6 +14,9 @@ module Lotus
|
|
14
14
|
ALL = ::Rack::Utils::HTTP_STATUS_CODES.dup.merge({
|
15
15
|
103 => 'Checkpoint',
|
16
16
|
122 => 'Request-URI too long',
|
17
|
+
413 => 'Payload Too Large', # Rack 1.5 compat
|
18
|
+
414 => 'URI Too Long', # Rack 1.5 compat
|
19
|
+
416 => 'Range Not Satisfiable', # Rack 1.5 compat
|
17
20
|
418 => 'I\'m a teapot',
|
18
21
|
420 => 'Enhance Your Calm',
|
19
22
|
444 => 'No Response',
|
@@ -21,6 +24,7 @@ module Lotus
|
|
21
24
|
450 => 'Blocked by Windows Parental Controls',
|
22
25
|
451 => 'Wrong Exchange server',
|
23
26
|
499 => 'Client Closed Request',
|
27
|
+
506 => 'Variant Also Negotiates', # Rack 1.5 compat
|
24
28
|
598 => 'Network read timeout error',
|
25
29
|
599 => 'Network connect timeout error'
|
26
30
|
}).freeze
|
@@ -37,7 +41,7 @@ module Lotus
|
|
37
41
|
# @example
|
38
42
|
# require 'lotus/http/status'
|
39
43
|
#
|
40
|
-
# Lotus::Http::Status.for_code(418) # => [418, "I'm a teapot
|
44
|
+
# Lotus::Http::Status.for_code(418) # => [418, "I'm a teapot"]
|
41
45
|
def self.for_code(code)
|
42
46
|
ALL.assoc(code)
|
43
47
|
end
|
data/lib/rack-patch.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# see https://github.com/rack/rack/pull/659
|
2
2
|
require 'rack'
|
3
|
+
require 'lotus/utils'
|
3
4
|
|
4
5
|
if Rack.release <= '1.5'
|
5
6
|
require 'rack/utils'
|
@@ -8,11 +9,16 @@ if Rack.release <= '1.5'
|
|
8
9
|
def self.best_q_match(q_value_header, available_mimes)
|
9
10
|
values = q_values(q_value_header)
|
10
11
|
|
11
|
-
|
12
|
+
values = values.map do |req_mime, quality|
|
12
13
|
match = available_mimes.find { |am| Rack::Mime.match?(am, req_mime) }
|
13
14
|
next unless match
|
14
15
|
[match, quality]
|
15
|
-
end.compact
|
16
|
+
end.compact
|
17
|
+
|
18
|
+
# See https://github.com/lotus/controller/issues/59
|
19
|
+
values = values.reverse if RUBY_VERSION >= '2.2.0' || Lotus::Utils.rubinius?
|
20
|
+
|
21
|
+
value = values.sort_by do |match, quality|
|
16
22
|
(match.split('/', 2).count('*') * -10) + quality
|
17
23
|
end.last
|
18
24
|
|
data/lotus-controller.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Lotus::Controller::VERSION
|
9
9
|
spec.authors = ['Luca Guidi']
|
10
10
|
spec.email = ['me@lucaguidi.com']
|
11
|
-
spec.description = %q{
|
12
|
-
spec.summary = %q{
|
11
|
+
spec.description = %q{Complete, fast and testable actions for Rack}
|
12
|
+
spec.summary = %q{Complete, fast and testable actions for Rack and Lotus}
|
13
13
|
spec.homepage = 'http://lotusrb.org'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -17,9 +17,11 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = []
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
|
+
spec.required_ruby_version = '>= 2.0.0'
|
20
21
|
|
21
|
-
spec.add_dependency 'rack',
|
22
|
-
spec.add_dependency 'lotus-utils',
|
22
|
+
spec.add_dependency 'rack', '~> 1.5'
|
23
|
+
spec.add_dependency 'lotus-utils', '~> 0.3', '>= 0.3.2'
|
24
|
+
spec.add_dependency 'lotus-validations', '~> 0.2', '>= 0.2.1'
|
23
25
|
|
24
26
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
27
|
spec.add_development_dependency 'minitest', '~> 5'
|
metadata
CHANGED
@@ -1,100 +1,126 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: lotus-utils
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.3'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.3.2
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.3'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.3.2
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: lotus-validations
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
32
52
|
- !ruby/object:Gem::Version
|
33
53
|
version: '0.2'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.2.1
|
34
57
|
type: :runtime
|
35
58
|
prerelease: false
|
36
59
|
version_requirements: !ruby/object:Gem::Requirement
|
37
60
|
requirements:
|
38
|
-
- - ~>
|
61
|
+
- - "~>"
|
39
62
|
- !ruby/object:Gem::Version
|
40
63
|
version: '0.2'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.2.1
|
41
67
|
- !ruby/object:Gem::Dependency
|
42
68
|
name: bundler
|
43
69
|
requirement: !ruby/object:Gem::Requirement
|
44
70
|
requirements:
|
45
|
-
- - ~>
|
71
|
+
- - "~>"
|
46
72
|
- !ruby/object:Gem::Version
|
47
73
|
version: '1.6'
|
48
74
|
type: :development
|
49
75
|
prerelease: false
|
50
76
|
version_requirements: !ruby/object:Gem::Requirement
|
51
77
|
requirements:
|
52
|
-
- - ~>
|
78
|
+
- - "~>"
|
53
79
|
- !ruby/object:Gem::Version
|
54
80
|
version: '1.6'
|
55
81
|
- !ruby/object:Gem::Dependency
|
56
82
|
name: minitest
|
57
83
|
requirement: !ruby/object:Gem::Requirement
|
58
84
|
requirements:
|
59
|
-
- - ~>
|
85
|
+
- - "~>"
|
60
86
|
- !ruby/object:Gem::Version
|
61
87
|
version: '5'
|
62
88
|
type: :development
|
63
89
|
prerelease: false
|
64
90
|
version_requirements: !ruby/object:Gem::Requirement
|
65
91
|
requirements:
|
66
|
-
- - ~>
|
92
|
+
- - "~>"
|
67
93
|
- !ruby/object:Gem::Version
|
68
94
|
version: '5'
|
69
95
|
- !ruby/object:Gem::Dependency
|
70
96
|
name: rack-test
|
71
97
|
requirement: !ruby/object:Gem::Requirement
|
72
98
|
requirements:
|
73
|
-
- - ~>
|
99
|
+
- - "~>"
|
74
100
|
- !ruby/object:Gem::Version
|
75
101
|
version: '0.6'
|
76
102
|
type: :development
|
77
103
|
prerelease: false
|
78
104
|
version_requirements: !ruby/object:Gem::Requirement
|
79
105
|
requirements:
|
80
|
-
- - ~>
|
106
|
+
- - "~>"
|
81
107
|
- !ruby/object:Gem::Version
|
82
108
|
version: '0.6'
|
83
109
|
- !ruby/object:Gem::Dependency
|
84
110
|
name: rake
|
85
111
|
requirement: !ruby/object:Gem::Requirement
|
86
112
|
requirements:
|
87
|
-
- - ~>
|
113
|
+
- - "~>"
|
88
114
|
- !ruby/object:Gem::Version
|
89
115
|
version: '10'
|
90
116
|
type: :development
|
91
117
|
prerelease: false
|
92
118
|
version_requirements: !ruby/object:Gem::Requirement
|
93
119
|
requirements:
|
94
|
-
- - ~>
|
120
|
+
- - "~>"
|
95
121
|
- !ruby/object:Gem::Version
|
96
122
|
version: '10'
|
97
|
-
description:
|
123
|
+
description: Complete, fast and testable actions for Rack
|
98
124
|
email:
|
99
125
|
- me@lucaguidi.com
|
100
126
|
executables: []
|
@@ -106,21 +132,28 @@ files:
|
|
106
132
|
- README.md
|
107
133
|
- lib/lotus-controller.rb
|
108
134
|
- lib/lotus/action.rb
|
135
|
+
- lib/lotus/action/cache.rb
|
136
|
+
- lib/lotus/action/cache/cache_control.rb
|
137
|
+
- lib/lotus/action/cache/conditional_get.rb
|
138
|
+
- lib/lotus/action/cache/directives.rb
|
139
|
+
- lib/lotus/action/cache/expires.rb
|
109
140
|
- lib/lotus/action/callable.rb
|
110
141
|
- lib/lotus/action/callbacks.rb
|
111
142
|
- lib/lotus/action/configurable.rb
|
112
143
|
- lib/lotus/action/cookie_jar.rb
|
113
144
|
- lib/lotus/action/cookies.rb
|
114
145
|
- lib/lotus/action/exposable.rb
|
146
|
+
- lib/lotus/action/flash.rb
|
147
|
+
- lib/lotus/action/glue.rb
|
115
148
|
- lib/lotus/action/mime.rb
|
116
149
|
- lib/lotus/action/params.rb
|
117
150
|
- lib/lotus/action/rack.rb
|
118
151
|
- lib/lotus/action/redirect.rb
|
119
152
|
- lib/lotus/action/session.rb
|
120
153
|
- lib/lotus/action/throwable.rb
|
154
|
+
- lib/lotus/action/validatable.rb
|
121
155
|
- lib/lotus/controller.rb
|
122
156
|
- lib/lotus/controller/configuration.rb
|
123
|
-
- lib/lotus/controller/dsl.rb
|
124
157
|
- lib/lotus/controller/version.rb
|
125
158
|
- lib/lotus/http/status.rb
|
126
159
|
- lib/rack-patch.rb
|
@@ -135,19 +168,19 @@ require_paths:
|
|
135
168
|
- lib
|
136
169
|
required_ruby_version: !ruby/object:Gem::Requirement
|
137
170
|
requirements:
|
138
|
-
- -
|
171
|
+
- - ">="
|
139
172
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
173
|
+
version: 2.0.0
|
141
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
175
|
requirements:
|
143
|
-
- -
|
176
|
+
- - ">="
|
144
177
|
- !ruby/object:Gem::Version
|
145
178
|
version: '0'
|
146
179
|
requirements: []
|
147
180
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
181
|
+
rubygems_version: 2.2.2
|
149
182
|
signing_key:
|
150
183
|
specification_version: 4
|
151
|
-
summary:
|
184
|
+
summary: Complete, fast and testable actions for Rack and Lotus
|
152
185
|
test_files: []
|
153
186
|
has_rdoc:
|
data/lib/lotus/controller/dsl.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
module Lotus
|
2
|
-
module Controller
|
3
|
-
# Public DSL
|
4
|
-
#
|
5
|
-
# @since 0.1.0
|
6
|
-
module Dsl
|
7
|
-
def self.included(base)
|
8
|
-
base.extend ClassMethods
|
9
|
-
end
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
# Define an action for the given name.
|
13
|
-
# It generates a concrete class for the action, for this reason the name
|
14
|
-
# MUST be a valid name for Ruby.
|
15
|
-
#
|
16
|
-
# @param name [String] the name of the action
|
17
|
-
# @param blk [Proc] the code of the action
|
18
|
-
#
|
19
|
-
# @raise TypeError when the name isn't a valid Ruby name
|
20
|
-
#
|
21
|
-
# @since 0.1.0
|
22
|
-
#
|
23
|
-
# @see Lotus::Controller::Configuration#action_module
|
24
|
-
#
|
25
|
-
# @example
|
26
|
-
# require 'lotus/controller'
|
27
|
-
#
|
28
|
-
# class ArticlesController
|
29
|
-
# include Lotus::Controller
|
30
|
-
#
|
31
|
-
# action 'Index' do
|
32
|
-
# def call(params)
|
33
|
-
# # ...
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# action 'Show' do
|
38
|
-
# def call(params)
|
39
|
-
# # ...
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
def action(name, &blk)
|
44
|
-
config = configuration.duplicate
|
45
|
-
const_set(name, Class.new)
|
46
|
-
|
47
|
-
const_get(name).tap do |klass|
|
48
|
-
klass.class_eval { include config.action_module }
|
49
|
-
klass.configuration = config
|
50
|
-
klass.class_eval(&blk)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|