proc 0.1.2 → 0.2.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/lib/proc.rb +8 -0
- data/lib/proc/callable.rb +9 -8
- data/lib/proc/client.rb +13 -7
- data/lib/proc/composition.rb +21 -16
- data/lib/proc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75ef8a4c8d8b8f07682996ca70c0263f5e0b6d123493137a07f92717c9c16eab
|
4
|
+
data.tar.gz: 48d2b0b5a4e453366ec4fc99536f98d875f804cb705ff5fde9a8b4b2d46e74c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fca54bd564be4fa0ac560ee4c81c9f6d81421b6fe26a6a7038ac97c4b2a17da34359949ba9d1d02191370022d916727793bda08e3d5a3c6d50d577acfaea17b
|
7
|
+
data.tar.gz: 7a7bba01f304f8866ff2cd69b779c4a4995b966d0ec835d78da29f577704c89d848d79b83b516c5b53df59c0352fb7a038f4f28e2a2d02fab5337048cbfb6fff
|
data/lib/proc.rb
CHANGED
data/lib/proc/callable.rb
CHANGED
@@ -4,8 +4,8 @@ class Proc
|
|
4
4
|
class Callable
|
5
5
|
attr_reader :proc, :input, :arguments
|
6
6
|
|
7
|
-
def initialize(proc, client:, input:
|
8
|
-
@proc = proc
|
7
|
+
def initialize(proc, client:, input: Proc.undefined, arguments: {})
|
8
|
+
@proc = proc.to_s
|
9
9
|
@client = client
|
10
10
|
@input = input
|
11
11
|
@arguments = arguments
|
@@ -44,12 +44,13 @@ class Proc
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def serialize
|
47
|
-
{
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
wrapped = {"[]" => [[@proc, serialized_arguments]]}
|
48
|
+
|
49
|
+
unless Proc.undefined?(@input)
|
50
|
+
wrapped["<<"] = serialized_input
|
51
|
+
end
|
52
|
+
|
53
|
+
{"{}" => wrapped}
|
53
54
|
end
|
54
55
|
|
55
56
|
def serialized_input
|
data/lib/proc/client.rb
CHANGED
@@ -71,7 +71,11 @@ class Proc
|
|
71
71
|
|
72
72
|
def call(proc = nil, input = nil, **arguments)
|
73
73
|
Async(logger: NullLogger) { |task|
|
74
|
-
body = {
|
74
|
+
body = {}
|
75
|
+
|
76
|
+
unless Proc.undefined?(input)
|
77
|
+
body["<<"] = serialize_value(input)
|
78
|
+
end
|
75
79
|
|
76
80
|
arguments.each_pair do |key, value|
|
77
81
|
body[key.to_s] = serialize_value(value)
|
@@ -88,10 +92,8 @@ class Proc
|
|
88
92
|
@resets_at = Time.at(response.headers["x-rate-limit-reset"].to_s.to_i)
|
89
93
|
|
90
94
|
payload = Oj.load(response.read, mode: :compat)
|
91
|
-
rescue
|
92
|
-
|
93
|
-
#
|
94
|
-
raise Proc::Unavailable, error.message
|
95
|
+
rescue
|
96
|
+
raise Proc::Unavailable
|
95
97
|
ensure
|
96
98
|
response&.close
|
97
99
|
end
|
@@ -121,8 +123,12 @@ class Proc
|
|
121
123
|
}.wait
|
122
124
|
end
|
123
125
|
|
124
|
-
def method_missing(name, input =
|
125
|
-
|
126
|
+
def method_missing(name, input = input_omitted = true, **arguments)
|
127
|
+
if input_omitted
|
128
|
+
Callable.new(name, client: self, arguments: arguments)
|
129
|
+
else
|
130
|
+
Callable.new(name, client: self, input: input, arguments: arguments)
|
131
|
+
end
|
126
132
|
end
|
127
133
|
|
128
134
|
def respond_to_missing?(name, *)
|
data/lib/proc/composition.rb
CHANGED
@@ -37,33 +37,38 @@ class Proc
|
|
37
37
|
|
38
38
|
def >>(other)
|
39
39
|
composed = dup
|
40
|
-
|
41
|
-
case other
|
42
|
-
when Composition
|
43
|
-
composed.merge(other)
|
44
|
-
when Callable
|
45
|
-
composed << other
|
46
|
-
end
|
47
|
-
|
40
|
+
composed << other
|
48
41
|
composed
|
49
42
|
end
|
50
43
|
|
51
44
|
def <<(callable)
|
52
|
-
|
45
|
+
case callable
|
46
|
+
when Composition
|
47
|
+
merge(callable)
|
48
|
+
when Callable
|
49
|
+
@callables << callable
|
50
|
+
end
|
53
51
|
end
|
54
52
|
|
55
53
|
def serialize
|
56
|
-
{
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
54
|
+
wrapped = {"[]" => serialized_calls}
|
55
|
+
|
56
|
+
unless Proc.undefined?(@input)
|
57
|
+
wrapped["<<"] = serialized_input
|
58
|
+
end
|
59
|
+
|
60
|
+
{"{}" => wrapped.merge(serialized_arguments)}
|
62
61
|
end
|
63
62
|
|
64
63
|
def serialized_calls
|
65
64
|
@callables.map { |callable|
|
66
|
-
|
65
|
+
arguments = callable.serialized_arguments
|
66
|
+
|
67
|
+
unless Proc.undefined?(callable.input)
|
68
|
+
arguments["<<"] = callable.serialized_input
|
69
|
+
end
|
70
|
+
|
71
|
+
[callable.proc, arguments]
|
67
72
|
}
|
68
73
|
end
|
69
74
|
|
data/lib/proc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-http
|