flame 4.10.0 → 4.11.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flame/controller.rb +26 -23
- data/lib/flame/dispatcher.rb +9 -13
- data/lib/flame/render.rb +7 -2
- data/lib/flame/static.rb +4 -4
- data/lib/flame/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3091319c3472e5cbf2fd06a7f771df6b2728e9fb
|
4
|
+
data.tar.gz: 1f379f843e562ff2c734b8260e60e8c9aaf44132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 878cd581f5f128f2152e71e379cf2beff8cc162da4d5b9e3b26d6cf5022d6ece235e4076f211818b8e112f0d62fea683b5eab6aa83910c8ed60cf8adae6c1135
|
7
|
+
data.tar.gz: 0fefbfc57c4ef14a2899e700c9bfef0429ee500ace9d2bf28455cbb2df20f68fc302d77818b907ff5eb94e8b1e04291163d8e5355926862f224fb0d0017362e7
|
data/lib/flame/controller.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'forwardable'
|
3
4
|
require_relative 'render'
|
4
5
|
|
5
6
|
module Flame
|
6
7
|
## Class initialize when Dispatcher found route with it
|
7
8
|
## For new request and response
|
8
9
|
class Controller
|
10
|
+
extend Forwardable
|
11
|
+
|
9
12
|
## Shortcut for not-inherited public methods: actions
|
10
13
|
def self.actions
|
11
14
|
public_instance_methods(false)
|
12
15
|
end
|
13
16
|
|
17
|
+
def_delegators(
|
18
|
+
:@dispatcher,
|
19
|
+
:config, :request, :params, :halt, :session, :response, :status, :body,
|
20
|
+
:default_body, :content_type
|
21
|
+
)
|
22
|
+
|
14
23
|
## Initialize the controller for request execution
|
15
24
|
## @param dispatcher [Flame::Dispatcher] dispatcher object
|
16
25
|
def initialize(dispatcher)
|
@@ -54,7 +63,7 @@ module Flame
|
|
54
63
|
return unless filename
|
55
64
|
response[content_dis] << "; filename=\"#{File.basename(filename)}\""
|
56
65
|
ext = File.extname(filename)
|
57
|
-
content_type(ext) unless
|
66
|
+
content_type(ext) unless ext.empty?
|
58
67
|
end
|
59
68
|
|
60
69
|
## Render a template with `Flame::Render` (based on Tilt-engine)
|
@@ -73,38 +82,32 @@ module Flame
|
|
73
82
|
end
|
74
83
|
alias render view
|
75
84
|
|
85
|
+
protected
|
86
|
+
|
76
87
|
## Execute the method of the controller with hooks (may be overloaded)
|
77
88
|
## @param method [Symbol] name of the controller method
|
78
89
|
def execute(method)
|
79
90
|
# send method
|
80
|
-
body send(
|
81
|
-
method,
|
82
|
-
*params.values_at(
|
83
|
-
*self.class.instance_method(method).parameters.map { |par| par[1] }
|
84
|
-
)
|
85
|
-
)
|
86
|
-
rescue => exception
|
87
|
-
# p 'rescue from controller'
|
88
|
-
status 500
|
89
|
-
dump_error(exception)
|
90
|
-
|
91
|
-
## Re-raise exception for inherited controllers or `Flame::Dispatcher`
|
92
|
-
raise exception
|
91
|
+
body send(method, *select_args(method))
|
93
92
|
end
|
94
93
|
|
95
|
-
##
|
96
|
-
def
|
97
|
-
|
98
|
-
@dispatcher.send(m, *args, &block)
|
99
|
-
end
|
100
|
-
|
101
|
-
## Respond to Dispatcher methods
|
102
|
-
def respond_to_missing?(m, *)
|
103
|
-
@dispatcher.respond_to?(m) || super
|
94
|
+
## Default method for Internal Server Error, can be inherited
|
95
|
+
def server_error(_exception)
|
96
|
+
body default_body
|
104
97
|
end
|
105
98
|
|
106
99
|
private
|
107
100
|
|
101
|
+
def select_args(method)
|
102
|
+
parameters = self.class.instance_method(method).parameters
|
103
|
+
params_select = proc do |type|
|
104
|
+
params.values_at(
|
105
|
+
*parameters.select { |par| par.first == type }.map(&:last)
|
106
|
+
)
|
107
|
+
end
|
108
|
+
params_select.call(:req) + params_select.call(:opt).compact
|
109
|
+
end
|
110
|
+
|
108
111
|
def add_controller_class(args)
|
109
112
|
args.unshift(self.class) if args[0].is_a?(Symbol)
|
110
113
|
args.insert(1, :index) if args[0].is_a?(Class) && !args[1].is_a?(Symbol)
|
data/lib/flame/dispatcher.rb
CHANGED
@@ -25,7 +25,7 @@ module Flame
|
|
25
25
|
## Start of execution the request
|
26
26
|
def run!
|
27
27
|
catch :halt do
|
28
|
-
try_fix_slashes ||
|
28
|
+
# try_fix_slashes ||
|
29
29
|
try_route ||
|
30
30
|
try_static ||
|
31
31
|
try_static(File.join(__dir__, '..', '..', 'public')) ||
|
@@ -130,12 +130,12 @@ module Flame
|
|
130
130
|
## Add error's backtrace to @env['rack.errors'] (terminal or file)
|
131
131
|
## @param error [Exception] exception for class, message and backtrace
|
132
132
|
def dump_error(error)
|
133
|
-
|
133
|
+
error_message = [
|
134
134
|
"#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} - " \
|
135
135
|
"#{error.class} - #{error.message}:",
|
136
136
|
*error.backtrace
|
137
137
|
].join("\n\t")
|
138
|
-
@env['rack.errors'].puts(
|
138
|
+
@env['rack.errors'].puts(error_message)
|
139
139
|
end
|
140
140
|
|
141
141
|
## Generate default body of error page
|
@@ -168,12 +168,13 @@ module Flame
|
|
168
168
|
status 200
|
169
169
|
params.merge!(route.arguments(request.path_parts))
|
170
170
|
# route.execute(self)
|
171
|
-
|
171
|
+
controller = route.controller.new(self)
|
172
|
+
controller.send(:execute, route.action)
|
172
173
|
rescue => exception
|
173
174
|
# p 'rescue from dispatcher'
|
174
|
-
dump_error(exception)
|
175
|
-
|
176
|
-
|
175
|
+
dump_error(exception)
|
176
|
+
status 500
|
177
|
+
controller.send(:server_error, exception)
|
177
178
|
# p 're raise exception from dispatcher'
|
178
179
|
# raise exception
|
179
180
|
end
|
@@ -188,13 +189,8 @@ module Flame
|
|
188
189
|
## or it's `default_body` method not defined
|
189
190
|
return default_body unless route
|
190
191
|
## Execute `default_body` method for the founded route
|
191
|
-
|
192
|
+
route.controller.new(self).send(:execute, :default_body)
|
192
193
|
body default_body if body.empty?
|
193
194
|
end
|
194
|
-
|
195
|
-
## Create controller object and execute method with arguments
|
196
|
-
def route_exec(route, method = route.action)
|
197
|
-
route.controller.new(self).send(:execute, method)
|
198
|
-
end
|
199
195
|
end
|
200
196
|
end
|
data/lib/flame/render.rb
CHANGED
@@ -67,9 +67,14 @@ module Flame
|
|
67
67
|
paths = [path]
|
68
68
|
paths.push(dirs.last) if path.to_sym == :index
|
69
69
|
dirs.push(nil)
|
70
|
-
Dir[
|
70
|
+
files = Dir[
|
71
71
|
File.join(views_dir, "{#{dirs.join(',')}}", "{#{paths.join(',')}}.*")
|
72
|
-
]
|
72
|
+
]
|
73
|
+
clean_paths files
|
74
|
+
end
|
75
|
+
|
76
|
+
def clean_paths(paths)
|
77
|
+
paths.map! { |path| Pathname.new(path).cleanpath.to_s }.uniq
|
73
78
|
end
|
74
79
|
|
75
80
|
## Find template-file by path
|
data/lib/flame/static.rb
CHANGED
@@ -2,6 +2,8 @@ module Flame
|
|
2
2
|
class Dispatcher
|
3
3
|
## Module for working with static files
|
4
4
|
module Static
|
5
|
+
private
|
6
|
+
|
5
7
|
## Find static files and try return it
|
6
8
|
def try_static(dir = config[:public_dir])
|
7
9
|
file = File.join(dir, URI.decode(request.path_info))
|
@@ -18,11 +20,9 @@ module Flame
|
|
18
20
|
file_time = File.mtime(file)
|
19
21
|
halt 304 if static_cached?(file_time)
|
20
22
|
content_type File.extname(file)
|
23
|
+
response[Rack::CACHE_CONTROL] = 'no-cache'
|
21
24
|
response['Last-Modified'] = file_time.httpdate
|
22
|
-
|
23
|
-
# "filename=\"#{File.basename(static_file)}\"",
|
24
|
-
# 'Content-Length' => File.size?(static_file).to_s
|
25
|
-
halt 200, File.read(file)
|
25
|
+
body File.read(file)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
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
|
+
version: 4.11.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.6.
|
158
|
+
rubygems_version: 2.6.10
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Web-framework, based on MVC-pattern
|