web_function 0.4.0 → 0.4.1
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/lib/web_function/pipeline.rb +46 -9
- data/lib/web_function/promise.rb +57 -20
- data/lib/web_function/version.rb +1 -1
- data/lib/web_function.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc10b3e4f558c7bec819e5f9029f672df3e37e5e5c66790df2e1159d2b06acec
|
|
4
|
+
data.tar.gz: deb73a647c14e886ef7b3be4e69a5a080fead74ef00119b56af86b57462452d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 37b3060aefd75b936ce0c5e9f3e1ec7e20f84ab118840f262d4631b020cebba24aaa9df251c1bb37560ff881df42412c688b6c6f519bacfe377aa4a5230676d3
|
|
7
|
+
data.tar.gz: 6240884af37b04edf66426653b9d8de19445be9817c93b624bccbb2ed0ca290ccce6dd98669ea2c2d7c114c8ec03c4b6c0fee1871c33e36fb7aeeb65d92517fb
|
|
@@ -3,23 +3,60 @@ module WebFunction
|
|
|
3
3
|
def initialize(url)
|
|
4
4
|
@url = url
|
|
5
5
|
@steps = []
|
|
6
|
+
@promises = []
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
def add_step(step)
|
|
9
|
-
n = @
|
|
10
|
+
n = @promises.count
|
|
11
|
+
promise = Promise.new(self, "$[#{n}]")
|
|
12
|
+
|
|
10
13
|
@steps << step
|
|
11
|
-
|
|
14
|
+
@promises << promise
|
|
15
|
+
|
|
16
|
+
promise
|
|
12
17
|
end
|
|
13
18
|
|
|
14
|
-
def execute(returns:
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
def execute(returns: :all)
|
|
20
|
+
case returns
|
|
21
|
+
when :all
|
|
22
|
+
responses = Endpoint.invoke(@url, args: {
|
|
23
|
+
steps: @steps,
|
|
24
|
+
returns: "$",
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
responses.each_with_index do |response, index|
|
|
28
|
+
@promises[index].value = response
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
reset!
|
|
32
|
+
|
|
33
|
+
responses
|
|
34
|
+
when :last
|
|
35
|
+
response = Endpoint.invoke(@url, args: {
|
|
36
|
+
steps: @steps,
|
|
37
|
+
returns: "$[-1:]",
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
@promises.last.value = response
|
|
41
|
+
|
|
42
|
+
reset!
|
|
43
|
+
|
|
44
|
+
response
|
|
45
|
+
else
|
|
46
|
+
response = Endpoint.invoke(@url, args: {
|
|
47
|
+
steps: @steps,
|
|
48
|
+
returns: returns,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
reset!
|
|
52
|
+
|
|
53
|
+
response
|
|
17
54
|
end
|
|
55
|
+
end
|
|
18
56
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
57
|
+
def reset!
|
|
58
|
+
@steps = []
|
|
59
|
+
@promises = []
|
|
23
60
|
end
|
|
24
61
|
end
|
|
25
62
|
end
|
data/lib/web_function/promise.rb
CHANGED
|
@@ -2,44 +2,81 @@ module WebFunction
|
|
|
2
2
|
class Promise
|
|
3
3
|
def initialize(pipeline, path)
|
|
4
4
|
@pipeline = pipeline
|
|
5
|
-
@path = path
|
|
5
|
+
@path = Path.new(path)
|
|
6
|
+
@value = nil
|
|
6
7
|
end
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
class Path
|
|
10
|
+
def initialize(path)
|
|
11
|
+
@path = path
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_s
|
|
15
|
+
@path
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_json(*args)
|
|
19
|
+
@path.to_json(*args)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def [](key)
|
|
23
|
+
case key
|
|
24
|
+
when String, Symbol
|
|
25
|
+
mutate("#{@path}.#{key}")
|
|
26
|
+
when Integer
|
|
27
|
+
mutate("#{@path}[#{key}]")
|
|
28
|
+
else
|
|
29
|
+
raise ArgumentError
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def mutate(path)
|
|
34
|
+
Path.new(path)
|
|
35
|
+
end
|
|
10
36
|
end
|
|
11
37
|
|
|
12
|
-
|
|
13
|
-
|
|
38
|
+
attr_writer :value
|
|
39
|
+
|
|
40
|
+
def to_s
|
|
41
|
+
if @value
|
|
42
|
+
@value.to_s
|
|
43
|
+
else
|
|
44
|
+
@path.to_s
|
|
45
|
+
end
|
|
14
46
|
end
|
|
15
47
|
|
|
16
|
-
def
|
|
17
|
-
@
|
|
48
|
+
def to_json(*args)
|
|
49
|
+
if @value
|
|
50
|
+
@value.to_json(*args)
|
|
51
|
+
else
|
|
52
|
+
@path.to_json(*args)
|
|
53
|
+
end
|
|
18
54
|
end
|
|
19
55
|
|
|
20
56
|
def [](key)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
mutate("#{@path}[\"#{key}\"]")
|
|
24
|
-
when Integer
|
|
25
|
-
mutate("#{@path}[#{key}]")
|
|
57
|
+
if @value
|
|
58
|
+
@value[key]
|
|
26
59
|
else
|
|
27
|
-
|
|
60
|
+
@path[key]
|
|
28
61
|
end
|
|
29
62
|
end
|
|
30
63
|
|
|
31
|
-
def
|
|
32
|
-
|
|
33
|
-
|
|
64
|
+
def value
|
|
65
|
+
unless @value
|
|
66
|
+
raise UnresolvedPromise
|
|
34
67
|
end
|
|
35
68
|
|
|
36
|
-
|
|
69
|
+
@value
|
|
37
70
|
end
|
|
38
71
|
|
|
39
|
-
|
|
72
|
+
def resolve
|
|
73
|
+
if @value
|
|
74
|
+
return @value
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
@pipeline.execute
|
|
40
78
|
|
|
41
|
-
|
|
42
|
-
Promise.new(@pipeline, path)
|
|
79
|
+
value
|
|
43
80
|
end
|
|
44
81
|
end
|
|
45
82
|
end
|
data/lib/web_function/version.rb
CHANGED
data/lib/web_function.rb
CHANGED