flame 4.4.3 → 4.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flame/version.rb +1 -1
- metadata +6 -7
- data/lib/flame/dispatcher.bak.rb +0 -191
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69d780427429f1d54ad4a9f1928f3ccb8907527f
|
4
|
+
data.tar.gz: e8c23f6d69b272f635795ba25eea31145417dfe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21f9592e84f11005b3db6d0a60c34dd2eac8ef76c31611be27de607ad2908083e59397818aa8492c2e0e517e9054eaceefa461d9840f6b65021f54000b822036
|
7
|
+
data.tar.gz: 678c93cdd80f814a2e5026cc53e9e9df8e2240fce0edea7d18df838e9854c5fb4ff4554afa129e72d57899c109d11a844b61c5c9035d6fa57e31c61c7bd82b99
|
data/lib/flame/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.4.
|
4
|
+
version: 4.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -16,21 +16,21 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
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
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: tilt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.0'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '3'
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '2.0'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3'
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- lib/flame/application.rb
|
93
93
|
- lib/flame/controller.rb
|
94
94
|
- lib/flame/cookies.rb
|
95
|
-
- lib/flame/dispatcher.bak.rb
|
96
95
|
- lib/flame/dispatcher.rb
|
97
96
|
- lib/flame/errors.rb
|
98
97
|
- lib/flame/render.rb
|
data/lib/flame/dispatcher.bak.rb
DELETED
@@ -1,191 +0,0 @@
|
|
1
|
-
require 'gorilla-patch/hash'
|
2
|
-
|
3
|
-
require_relative 'cookies'
|
4
|
-
require_relative 'request'
|
5
|
-
require_relative 'response'
|
6
|
-
require_relative 'static'
|
7
|
-
|
8
|
-
module Flame
|
9
|
-
## Helpers for dispatch Flame::Application#call
|
10
|
-
class Dispatcher
|
11
|
-
attr_reader :request, :response
|
12
|
-
|
13
|
-
using GorillaPatch::HashExt
|
14
|
-
|
15
|
-
include Flame::Dispatcher::Static
|
16
|
-
|
17
|
-
## Initialize Dispatcher from Application#call
|
18
|
-
## @param app [Flame::Application] application object
|
19
|
-
## @param env Rack-environment object
|
20
|
-
def initialize(app, env)
|
21
|
-
@app = app
|
22
|
-
@env = env
|
23
|
-
@request = Flame::Request.new(env)
|
24
|
-
@response = Flame::Response.new
|
25
|
-
end
|
26
|
-
|
27
|
-
## Start of execution the request
|
28
|
-
def run!
|
29
|
-
catch :halt do
|
30
|
-
try_route ||
|
31
|
-
try_static ||
|
32
|
-
try_static(File.join(__dir__, '..', '..', 'public')) ||
|
33
|
-
not_found
|
34
|
-
end
|
35
|
-
response.write body
|
36
|
-
response.finish
|
37
|
-
end
|
38
|
-
|
39
|
-
## Acccess to the status of response
|
40
|
-
## @param value [Ineger, nil] integer value for new status
|
41
|
-
## @return [Integer] current status
|
42
|
-
## @example Set status value
|
43
|
-
## status 200
|
44
|
-
def status(value = nil)
|
45
|
-
response.status ||= 200
|
46
|
-
response.headers['X-Cascade'] = 'pass' if value == 404
|
47
|
-
value ? response.status = value : response.status
|
48
|
-
end
|
49
|
-
|
50
|
-
## Acccess to the body of response
|
51
|
-
## @param value [String, nil] string value for new body
|
52
|
-
## @return [String] current body
|
53
|
-
## @example Set body value
|
54
|
-
## body 'Hello World!'
|
55
|
-
def body(value = nil)
|
56
|
-
value ? @body = value : @body ||= ''
|
57
|
-
end
|
58
|
-
|
59
|
-
## Parameters of the request
|
60
|
-
def params
|
61
|
-
@params ||= request.params.merge(request.params.keys_to_sym(deep: true))
|
62
|
-
end
|
63
|
-
|
64
|
-
## Session object as Hash
|
65
|
-
def session
|
66
|
-
request.session
|
67
|
-
end
|
68
|
-
|
69
|
-
## Cookies object as Hash
|
70
|
-
def cookies
|
71
|
-
@cookies ||= Cookies.new(request.cookies, response)
|
72
|
-
end
|
73
|
-
|
74
|
-
## Application-config object as Hash
|
75
|
-
def config
|
76
|
-
@app.config
|
77
|
-
end
|
78
|
-
|
79
|
-
## Access to Content-Type header of response
|
80
|
-
def content_type(ext = nil)
|
81
|
-
return response[Rack::CONTENT_TYPE] unless ext
|
82
|
-
response[Rack::CONTENT_TYPE] = Rack::Mime.mime_type(ext)
|
83
|
-
end
|
84
|
-
|
85
|
-
## Build a path to the given controller and action, with any expected params
|
86
|
-
##
|
87
|
-
## @param ctrl [Flame::Controller] class of controller
|
88
|
-
## @param action [Symbol] method of controller
|
89
|
-
## @param args [Hash] parameters for method of controller
|
90
|
-
## @return [String] path for requested method, controller and parameters
|
91
|
-
## @example Path for `show(id)` method of `ArticlesController` with `id: 2`
|
92
|
-
## path_to ArticlesController, :show, id: 2 # => "/articles/show/2"
|
93
|
-
def path_to(ctrl, action = :index, args = {})
|
94
|
-
route = @app.class.router.find_route(controller: ctrl, action: action)
|
95
|
-
raise Errors::RouteNotFoundError.new(ctrl, action) unless route
|
96
|
-
path = route.assign_arguments(args)
|
97
|
-
path.empty? ? '/' : path
|
98
|
-
end
|
99
|
-
|
100
|
-
## Interrupt the execution of route, and set new optional data
|
101
|
-
## (otherwise using existing)
|
102
|
-
## @param new_status_or_body [Integer, String]
|
103
|
-
## set new HTTP status code or new body
|
104
|
-
## @param new_body [String] set new body
|
105
|
-
## @param new_headers [String] merge new headers
|
106
|
-
## @example Halt with 500, no change body
|
107
|
-
## halt 500
|
108
|
-
## @example Halt with 404, render template
|
109
|
-
## halt 404, render('errors/404')
|
110
|
-
## @example Halt with 200, set new headers
|
111
|
-
## halt 200, 'Cats!', 'Content-Type' => 'animal/cat'
|
112
|
-
def halt(new_status_or_body = nil, new_body = nil, new_headers = {})
|
113
|
-
case new_status_or_body
|
114
|
-
when String then new_body = new_status_or_body
|
115
|
-
when Integer then status new_status_or_body
|
116
|
-
end
|
117
|
-
# new_status.is_a?(String) ? () : (status new_status)
|
118
|
-
new_body = default_body if new_body.nil? && body.empty?
|
119
|
-
body new_body if new_body
|
120
|
-
response.headers.merge!(new_headers)
|
121
|
-
throw :halt
|
122
|
-
end
|
123
|
-
|
124
|
-
## Add error's backtrace to @env['rack.errors'] (terminal or file)
|
125
|
-
## @param error [Exception] exception for class, message and backtrace
|
126
|
-
def dump_error(error)
|
127
|
-
@error_message = [
|
128
|
-
"#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} - " \
|
129
|
-
"#{error.class} - #{error.message}:",
|
130
|
-
*error.backtrace
|
131
|
-
].join("\n\t")
|
132
|
-
@env['rack.errors'].puts(@error_message)
|
133
|
-
end
|
134
|
-
|
135
|
-
private
|
136
|
-
|
137
|
-
## Generate default body of error page
|
138
|
-
def default_body
|
139
|
-
## Return nil if must be no body for current HTTP status
|
140
|
-
return if Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status)
|
141
|
-
response.headers[Rack::CONTENT_TYPE] = 'text/html'
|
142
|
-
"<h1>#{Rack::Utils::HTTP_STATUS_CODES[status]}</h1>"
|
143
|
-
end
|
144
|
-
|
145
|
-
## Find route and try execute it
|
146
|
-
def try_route
|
147
|
-
route = @app.class.router.find_route(
|
148
|
-
method: request.http_method,
|
149
|
-
path_parts: request.path_parts
|
150
|
-
)
|
151
|
-
return nil unless route
|
152
|
-
execute_route(route)
|
153
|
-
end
|
154
|
-
|
155
|
-
## Execute route
|
156
|
-
## @param route [Flame::Route] route that must be executed
|
157
|
-
def execute_route(route)
|
158
|
-
status 200
|
159
|
-
params.merge!(route.arguments(request.path_parts))
|
160
|
-
# route.execute(self)
|
161
|
-
route_exec(route)
|
162
|
-
rescue => exception
|
163
|
-
# p 'rescue from dispatcher'
|
164
|
-
dump_error(exception) unless @error_message
|
165
|
-
halt 500
|
166
|
-
|
167
|
-
# p 're raise exception from dispatcher'
|
168
|
-
# raise exception
|
169
|
-
end
|
170
|
-
|
171
|
-
## Generate a response if the route is not found
|
172
|
-
def not_found
|
173
|
-
# p 'not found from dispatcher'
|
174
|
-
## Change the status of response to 404
|
175
|
-
status 404
|
176
|
-
## Find the nearest route by the parts of requested path
|
177
|
-
route = @app.router.find_nearest_route(request.path_parts)
|
178
|
-
## Halt with default body if the route not found
|
179
|
-
## or it's `not_found` method not defined
|
180
|
-
return halt unless route && route.controller.method_defined?(:not_found)
|
181
|
-
## Execute `not_found` method for the founded route
|
182
|
-
route_exec(route, :not_found)
|
183
|
-
end
|
184
|
-
|
185
|
-
## Create controller object and execute method
|
186
|
-
def route_exec(route, method = nil)
|
187
|
-
method ||= route.action
|
188
|
-
route.controller.new(self).send(:execute, method)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|