proc 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2950f8e2178a95a40c29372c902203d883bda75ac84785a3579134b9394d7a52
4
- data.tar.gz: 6c8433c3f49bbc0a6a62187c9b992fd7c39e6eac2894f7d71a2056205bdc7900
3
+ metadata.gz: 75ef8a4c8d8b8f07682996ca70c0263f5e0b6d123493137a07f92717c9c16eab
4
+ data.tar.gz: 48d2b0b5a4e453366ec4fc99536f98d875f804cb705ff5fde9a8b4b2d46e74c0
5
5
  SHA512:
6
- metadata.gz: 36828988724d7e3cad08a3a741f576bfa50f8d53a459062892bb270e01da1d8a1ddf4977255976a314a15b4e79e8266da4089c9cdbb8f723c30d681099654c7f
7
- data.tar.gz: e224df7dcabcf284d5cf72f410be3ccf713dfbb0ff386ae5a50597e5c9a6b07634c87759f30d5e4b4a95fc0091d0c2f0aa490146a02b8806a3784033025fd123
6
+ metadata.gz: 1fca54bd564be4fa0ac560ee4c81c9f6d81421b6fe26a6a7038ac97c4b2a17da34359949ba9d1d02191370022d916727793bda08e3d5a3c6d50d577acfaea17b
7
+ data.tar.gz: 7a7bba01f304f8866ff2cd69b779c4a4995b966d0ec835d78da29f577704c89d848d79b83b516c5b53df59c0352fb7a038f4f28e2a2d02fab5337048cbfb6fff
@@ -6,4 +6,12 @@ class Proc
6
6
  def self.connect(authorization, **options)
7
7
  Client.new(authorization, **options)
8
8
  end
9
+
10
+ def self.undefined
11
+ @_undefined ||= Object.new
12
+ end
13
+
14
+ def self.undefined?(value)
15
+ value == undefined
16
+ end
9
17
  end
@@ -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: nil, arguments: {})
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
- "<<" => serialized_input,
50
- "[]" => [[@proc, serialized_arguments]]
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
@@ -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 = { "<<" => serialize_value(input) }
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 => error
92
- # TODO: This should wrap `error`.
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 = nil, **arguments)
125
- Callable.new(name, client: self, input: input, arguments: arguments)
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, *)
@@ -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
- @callables << callable
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
- "<<" => serialized_input,
59
- "[]" => serialized_calls
60
- }.merge(serialized_arguments)
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
- [callable.proc, callable.serialized_arguments]
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
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Proc
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
 
6
6
  def self.version
7
7
  VERSION
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.1.2
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-10-31 00:00:00.000000000 Z
11
+ date: 2020-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http