roda-flow 0.3.1 → 0.4.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/README.md +30 -26
- data/lib/roda/plugins/flow.rb +57 -7
- 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: 480bc546b4bf68f5b31d38fb3c948b9f051e796c
|
4
|
+
data.tar.gz: c6e8b194c79d7e85a823ec5dcb94f35d67104cac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc02a87ab0d85340acde77d09e273dabf7a6764ae76ad0c5adb9c5d4e2c1fd955ebdb39b2528a9e3ab33f6db492b1df798e6428418129abd1a6a39aa85fa7cd9
|
7
|
+
data.tar.gz: a89efaef010bdb5ef4e481d695ea4302952ee290c2329acf7e9108237cdfd68c49f490f0880f221368f6cbdf73ef921ec4fd76f0adfe6136ed5ba02d72637fc4
|
data/README.md
CHANGED
@@ -120,32 +120,36 @@ class App < Roda
|
|
120
120
|
route do |r|
|
121
121
|
r.on 'users' do
|
122
122
|
r.resolve 'repositories.user' do |user_repository| do
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
r.
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
123
|
+
# You can set the default options passed when
|
124
|
+
# mapping a route to a container item with
|
125
|
+
# flow_defaults, i.e.
|
126
|
+
flow_defaults inject: [response, user_repository] do
|
127
|
+
r.is do
|
128
|
+
r.get to: 'controllers.users#index'
|
129
|
+
r.post(
|
130
|
+
to: 'controllers.users#create',
|
131
|
+
# The following line is implied because of
|
132
|
+
# the call to flow_defaults above
|
133
|
+
# inject: [response, user_repository],
|
134
|
+
call_with: [r.params]
|
135
|
+
)
|
136
|
+
end
|
137
|
+
|
138
|
+
r.on :user_id do |user_id|
|
139
|
+
r.get(
|
140
|
+
to: 'controllers.users#show',
|
141
|
+
call_with: [user_id]
|
142
|
+
)
|
143
|
+
r.put(
|
144
|
+
to: 'controllers.users#update',
|
145
|
+
call_with: [user_id, r.params]
|
146
|
+
)
|
147
|
+
r.delete(
|
148
|
+
# to: can also be a registered proc, just omit the "#" and method name
|
149
|
+
to: 'controllers.users#destroy',
|
150
|
+
call_with: [user_id]
|
151
|
+
)
|
152
|
+
end
|
149
153
|
end
|
150
154
|
end
|
151
155
|
end
|
data/lib/roda/plugins/flow.rb
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
class Roda
|
2
2
|
module RodaPlugins
|
3
3
|
module Flow
|
4
|
+
|
5
|
+
KEY = 'flow.defaults'.freeze
|
6
|
+
|
7
|
+
module InstanceMethods
|
8
|
+
def flow_defaults(args = {}, &block)
|
9
|
+
if block_given?
|
10
|
+
defaults.merge!(args)
|
11
|
+
yield
|
12
|
+
else
|
13
|
+
raise RodaError 'must pass a block when using flow defaults'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def defaults
|
20
|
+
env[KEY] ||= {}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
4
24
|
module RequestMethods
|
5
25
|
def resolve(*keys)
|
6
26
|
yield *keys.map { |key| roda_class.resolve(key) }
|
@@ -14,24 +34,27 @@ class Roda
|
|
14
34
|
end
|
15
35
|
|
16
36
|
def match_inject(inject)
|
17
|
-
@block_arg = @block_arg.call(*inject)
|
37
|
+
@block_arg = @block_arg.call(*inject)
|
18
38
|
end
|
19
39
|
|
20
40
|
def match_call_with(call_with)
|
21
41
|
@captures.concat(call_with)
|
22
42
|
end
|
23
43
|
|
24
|
-
|
44
|
+
|
45
|
+
def if_match(args, &block)
|
25
46
|
path = @remaining_path
|
26
47
|
# For every block, we make sure to reset captures so that
|
27
48
|
# nesting matchers won't mess with each other's captures.
|
28
49
|
@captures.clear
|
29
50
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
51
|
+
if match_all(args)
|
52
|
+
block_result(get_block(&block).call(*captures))
|
53
|
+
throw :halt, response.finish
|
54
|
+
else
|
55
|
+
@remaining_path = path
|
56
|
+
false
|
57
|
+
end
|
35
58
|
end
|
36
59
|
|
37
60
|
def always(&block)
|
@@ -56,7 +79,34 @@ class Roda
|
|
56
79
|
@block_arg = nil
|
57
80
|
@block_method = nil
|
58
81
|
end
|
82
|
+
|
83
|
+
def _match_hash(hash)
|
84
|
+
if hash.keys.include?(:to)
|
85
|
+
hash = merge_defaults(hash)
|
86
|
+
end
|
87
|
+
|
88
|
+
super(hash)
|
89
|
+
end
|
90
|
+
|
91
|
+
def merge_defaults(hash)
|
92
|
+
hash = defaults.merge(hash)
|
93
|
+
hash = hash.delete_if { |k,v| v == false }
|
94
|
+
|
95
|
+
# Order matters...
|
96
|
+
sorted = %i[to inject call_with].inject({}) do |retval, key|
|
97
|
+
retval[key] = hash[key] if hash[key]
|
98
|
+
retval
|
99
|
+
end
|
100
|
+
|
101
|
+
sorted
|
102
|
+
end
|
103
|
+
|
104
|
+
def defaults
|
105
|
+
env[KEY] || {}
|
106
|
+
end
|
107
|
+
|
59
108
|
end
|
109
|
+
|
60
110
|
end
|
61
111
|
|
62
112
|
register_plugin(:flow, Flow)
|
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.4.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:
|
11
|
+
date: 2018-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.6.
|
113
|
+
rubygems_version: 2.6.13
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: ''
|