flame 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flame/application.rb +1 -0
- data/lib/flame/dispatcher.rb +6 -5
- data/lib/flame/router.rb +16 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 132a976db3536271fcd021dea1158925d8d61db6
|
4
|
+
data.tar.gz: 413e4476ce2a9d76b52894d03088945a389eb299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e71747e2c149f2e06a8e3760e8dcef947e4c34ca4a26105a572fcaf2bd9651229264f08d05a5d7dfc2d4b813a2d69cf049fa56706d495ee5a03f33b1a2c6806f
|
7
|
+
data.tar.gz: ebeac2eb2732bcac1530a3b8c0d6994060696de7d82679c4073a23611460f047688c7f2146711a0b1b10082ee84468e01059f3da0609fdd9c2e0b5093a29c3fc
|
data/lib/flame/application.rb
CHANGED
data/lib/flame/dispatcher.rb
CHANGED
@@ -6,8 +6,6 @@ module Flame
|
|
6
6
|
## Class initialize when Application.call(env) invoked
|
7
7
|
## For new request and response
|
8
8
|
class Dispatcher
|
9
|
-
attr_reader :controller
|
10
|
-
|
11
9
|
def initialize(app, env)
|
12
10
|
@app = app
|
13
11
|
@env = env
|
@@ -103,10 +101,13 @@ module Flame
|
|
103
101
|
end
|
104
102
|
|
105
103
|
def execute_route(route)
|
106
|
-
|
107
|
-
singleton_class.include @controller
|
104
|
+
singleton_class.include route[:controller]
|
108
105
|
router.find_befores(route).each { |before| send(before) }
|
109
|
-
send(route[:action], *route.arranged_params(params))
|
106
|
+
result = send(route[:action], *route.arranged_params(params))
|
107
|
+
router.find_afters(route).each do |after|
|
108
|
+
result = send(after, result)
|
109
|
+
end
|
110
|
+
result
|
110
111
|
end
|
111
112
|
|
112
113
|
def try_static(dir = config[:public_dir])
|
data/lib/flame/router.rb
CHANGED
@@ -4,11 +4,11 @@ require_relative 'validators'
|
|
4
4
|
module Flame
|
5
5
|
## Router class for routing
|
6
6
|
class Router
|
7
|
-
attr_accessor :routes, :befores
|
7
|
+
attr_accessor :routes, :befores, :afters
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@routes = []
|
11
|
-
@befores = {}
|
11
|
+
@befores, @afters = Array.new(2) { {} }
|
12
12
|
end
|
13
13
|
|
14
14
|
def add_controller(ctrl, path, block = nil)
|
@@ -20,6 +20,7 @@ module Flame
|
|
20
20
|
ActionsValidator.new(ctrl_routes.routes, ctrl).valid?
|
21
21
|
routes.concat(ctrl_routes.routes)
|
22
22
|
befores[ctrl] = ctrl_routes.befores
|
23
|
+
afters[ctrl] = ctrl_routes.afters
|
23
24
|
end
|
24
25
|
|
25
26
|
## Find route by any attributes
|
@@ -33,12 +34,18 @@ module Flame
|
|
33
34
|
(befores[route[:controller]][route[:action]] || [])
|
34
35
|
end
|
35
36
|
|
37
|
+
## Find after hook by Route
|
38
|
+
def find_afters(route)
|
39
|
+
(afters[route[:controller]][:*] || []) +
|
40
|
+
(afters[route[:controller]][route[:action]] || [])
|
41
|
+
end
|
42
|
+
|
36
43
|
private
|
37
44
|
|
38
45
|
## Helper module for routing refine
|
39
46
|
class RouteRefine
|
40
47
|
attr_accessor :rest_routes
|
41
|
-
attr_reader :routes, :befores
|
48
|
+
attr_reader :routes, :befores, :afters
|
42
49
|
|
43
50
|
def self.http_methods
|
44
51
|
[:GET, :POST, :PUT, :DELETE]
|
@@ -58,7 +65,7 @@ module Flame
|
|
58
65
|
@ctrl = ctrl
|
59
66
|
@path = path || default_controller_path
|
60
67
|
@routes = []
|
61
|
-
@befores = {}
|
68
|
+
@befores, @afters = Array.new(2) { {} }
|
62
69
|
block.nil? ? defaults : instance_exec(&block)
|
63
70
|
# p @routes
|
64
71
|
@routes.sort! { |a, b| b[:path] <=> a[:path] }
|
@@ -76,6 +83,11 @@ module Flame
|
|
76
83
|
actions.each { |a| (@befores[a] ||= []).push(action) }
|
77
84
|
end
|
78
85
|
|
86
|
+
def after(actions, action)
|
87
|
+
actions = [actions] unless actions.is_a?(Array)
|
88
|
+
actions.each { |a| (@afters[a] ||= []).push(action) }
|
89
|
+
end
|
90
|
+
|
79
91
|
def defaults
|
80
92
|
rest
|
81
93
|
@ctrl.public_instance_methods(false).each do |action|
|
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: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|