roda-flow 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -27
- data/lib/roda/plugins/flow.rb +46 -30
- 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: b4d4b0303ce594d2a42f684180275547d9e11032
|
4
|
+
data.tar.gz: 510747bc0c24a158d2149db5575607721a92b862
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b3b29ef6f199663fed4ef668a3cac41204320bc975d6262e9dc2664bf4d28b0d379b902543e3776e02ad3beff391d2010660a97a3c9be3c6a3e748d5cd1c7f7
|
7
|
+
data.tar.gz: 8f92a3583f9c52bd3de118e0f3fb7548b9f6e417c12140320b518e1ac6d753add978328ff146f783bbb1a709748076d72fc2f4836dfb51cbfa31d19a124decc4
|
data/README.md
CHANGED
@@ -103,33 +103,35 @@ class App < Roda
|
|
103
103
|
plugin :flow
|
104
104
|
|
105
105
|
route do |r|
|
106
|
-
r.on 'users'
|
107
|
-
r.
|
108
|
-
r.
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
r.
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
106
|
+
r.on 'users' do
|
107
|
+
r.resolve 'repositories.user' do |user_repository| do
|
108
|
+
r.is do
|
109
|
+
r.get to: 'controllers.users#index', inject: [response, user_repository]
|
110
|
+
r.post(
|
111
|
+
to: 'controllers.users#create',
|
112
|
+
inject: [response, user_repository],
|
113
|
+
call_with: [r.params]
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
r.on :user_id do |user_id|
|
118
|
+
r.get(
|
119
|
+
to: 'controllers.users#show',
|
120
|
+
inject: [response, user_repository],
|
121
|
+
call_with: [user_id]
|
122
|
+
)
|
123
|
+
r.put(
|
124
|
+
to: 'controllers.users#update',
|
125
|
+
inject: [response, user_repository],
|
126
|
+
call_with: [user_id, r.params]
|
127
|
+
)
|
128
|
+
r.delete(
|
129
|
+
# to: can also be a registered proc, just omit the "#" and method name
|
130
|
+
to: 'controllers.users#destroy',
|
131
|
+
inject: [response, user_repository],
|
132
|
+
call_with: [user_id]
|
133
|
+
)
|
134
|
+
end
|
133
135
|
end
|
134
136
|
end
|
135
137
|
end
|
data/lib/roda/plugins/flow.rb
CHANGED
@@ -6,49 +6,65 @@ class Roda
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module RequestMethods
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
# nesting matchers won't mess with each other's captures.
|
13
|
-
@captures.clear
|
9
|
+
def resolve(*args, &block)
|
10
|
+
on(resolve: args, &block)
|
11
|
+
end
|
14
12
|
|
15
|
-
|
13
|
+
private
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
def match_resolve(resolve)
|
16
|
+
Array(resolve).flatten.each do |key|
|
17
|
+
@captures << roda_class.resolve(key)
|
19
18
|
end
|
19
|
+
end
|
20
20
|
|
21
|
-
|
21
|
+
def match_to(to)
|
22
|
+
container_key, @block_method = to.to_s.split('#')
|
23
|
+
@block_arg = roda_class.resolve(container_key)
|
24
|
+
end
|
22
25
|
|
23
|
-
|
26
|
+
def match_inject(inject)
|
27
|
+
@block_arg = @block_arg.call(*inject) if @block_arg
|
28
|
+
end
|
24
29
|
|
25
|
-
|
30
|
+
def match_call_with(call_with)
|
31
|
+
@captures.concat(call_with)
|
32
|
+
end
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
def if_match(*args, &block)
|
35
|
+
path = @remaining_path
|
36
|
+
# For every block, we make sure to reset captures so that
|
37
|
+
# nesting matchers won't mess with each other's captures.
|
38
|
+
@captures.clear
|
39
|
+
|
40
|
+
return unless match_all(args)
|
41
|
+
block_result(get_block(&block).call(*captures))
|
42
|
+
throw :halt, response.finish
|
43
|
+
ensure
|
44
|
+
@remaining_path = path
|
45
|
+
end
|
34
46
|
|
35
|
-
|
36
|
-
|
37
|
-
|
47
|
+
def always(&block)
|
48
|
+
super(&get_block(&block))
|
49
|
+
end
|
38
50
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
51
|
+
def get_block(&block)
|
52
|
+
if block_given?
|
53
|
+
block
|
54
|
+
elsif @block_arg
|
55
|
+
if @block_method
|
56
|
+
block_arg = @block_arg.method(@block_method)
|
43
57
|
else
|
44
|
-
|
58
|
+
block_arg = @block_arg
|
45
59
|
end
|
60
|
+
clear_block_args
|
61
|
+
block_arg
|
46
62
|
end
|
63
|
+
end
|
47
64
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@remaining_path = path
|
65
|
+
def clear_block_args
|
66
|
+
@block_arg = nil
|
67
|
+
@block_method = nil
|
52
68
|
end
|
53
69
|
end
|
54
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda-flow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Holland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|