proc 0.11.1 → 0.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 165ffe3b7cd5976e7091d46261724665b2ba65b8b40144d5b5a12bcfde0dcf21
4
- data.tar.gz: c79d592b4e21d9109268cc50929ae1f8f0e4daff8297fc3755da99bff05d47b5
3
+ metadata.gz: b102aa8b4a6c4f99758cab2f6aefff1800948b60197d920f6279cb76f26decbb
4
+ data.tar.gz: 37b8a0aa99c4089a584b2b7197ab7e9e9ec7bc555a59bdaf1bbce76f4ab466ac
5
5
  SHA512:
6
- metadata.gz: 02ce5abfc9089157d26a2430a3d6af2b74510d726698a5326a00c6f5cfa433f5a03d44e143cd8efb08d8b5ff6145cfde6a96746b4160cc584779c0be6f42005e
7
- data.tar.gz: 3e37e7b6d53001aec939303c7c7371f9fe63e78c874b5e00d14b652fcd0ca9aa2531d2e75e7083ee9cb1df56d9ebf53816c266c2fe17078cf7d76382b00bc7b3
6
+ metadata.gz: 33e2381e9f9d5ff7a6ff10c7ad4a75cc2d0687a4e6890916d4443563ddcaf883d7205b971e7dee63637f81731cea2c5caf80df1a980718db65c78b94db19c0ca
7
+ data.tar.gz: fc7497fce516a9b003ed4dbf617d26c9c7ca5e6b2696f324cba275f765f85f6f878baaea2e7006d3e2e023a61de73b506aff743d1d3ae1451fa9226c2c9040d4
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- **This is the official Ruby client for Proc: Serverless web functions with superpowers.**
1
+ **Superpowers to help you ship web endpoints faster.**
2
+
3
+ Proc is an all-in-one toolchain for building, deploying, and calling custom behavior from any website or app.
2
4
 
3
5
  * [Learn more about Proc](https://proc.dev)
4
- * [Browse available packages](https://proc.dev/packages)
6
+ * [Browse packages](https://proc.dev/packages)
5
7
  * [Read the docs](https://proc.dev/docs)
6
- * [Join chat](https://discord.gg/aRu8qvkCmy)
8
+ * [Chat with us](https://discord.gg/aRu8qvkCmy)
7
9
 
8
10
  ## Install
9
11
 
@@ -31,7 +33,7 @@ client.type.number.add.call(1, {value: 1});
31
33
  => 2
32
34
  ```
33
35
 
34
- Build more complex behaviors by composing procs together:
36
+ Build more complex behavior by composing procs together:
35
37
 
36
38
  ```ruby
37
39
  time = client.time
@@ -43,7 +45,7 @@ composition.call
43
45
  => "Tuesday"
44
46
  ````
45
47
 
46
- Deploy custom endpoints instantly and call them from anywhere:
48
+ Instantly deploy your behavior to a private endpoint and call it from anywhere:
47
49
 
48
50
  ```ruby
49
51
  client.proc.create.call(name: "day_of_week", proc: composition)
data/lib/proc/callable.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Proc
4
- class Callable
4
+ class Callable < BasicObject
5
5
  attr_reader :proc, :input, :arguments
6
6
 
7
- def initialize(proc, client:, input: Proc.undefined, arguments: {})
7
+ def initialize(proc, client:, input: ::Proc.undefined, arguments: {})
8
8
  @proc = proc.to_s
9
9
  @client = client
10
10
  @input = input
@@ -21,11 +21,11 @@ class Proc
21
21
  # If a block is passed, it will be called to prior to dispatch and its result passed as a nested context.
22
22
  #
23
23
  def call(input = input_omitted = true, **arguments)
24
- if block_given?
24
+ if ::Kernel.block_given?
25
25
  arguments[:proc] = yield
26
26
  end
27
27
 
28
- callable = self.class.new(
28
+ callable = ::Proc::Callable.new(
29
29
  @proc,
30
30
  client: @client,
31
31
  input: input_omitted ? @input : input,
@@ -38,7 +38,7 @@ class Proc
38
38
  # [public] Dispatches this callable context to proc using the client, calling the given block once for each value.
39
39
  #
40
40
  def each(input = input_omitted = true, **arguments, &block)
41
- callable = self.class.new(
41
+ callable = ::Proc::Callable.new(
42
42
  @proc,
43
43
  client: @client,
44
44
  input: input_omitted ? @input : input,
@@ -51,11 +51,11 @@ class Proc
51
51
  # [public] Creates a new callable context based on this one, with a new input and/or arguments.
52
52
  #
53
53
  def with(input = input_omitted = true, **arguments)
54
- if block_given?
54
+ if ::Kernel.block_given?
55
55
  arguments[:proc] = yield
56
56
  end
57
57
 
58
- self.class.new(
58
+ ::Proc::Callable.new(
59
59
  @proc,
60
60
  client: @client,
61
61
  input: input_omitted ? @input : input,
@@ -66,7 +66,7 @@ class Proc
66
66
  # [public] Returns a composition built from this callable context and one or more other callables.
67
67
  #
68
68
  def compose(*others)
69
- composed = Composition.new(client: @client, input: @input)
69
+ composed = ::Proc::Composition.new(client: @client, input: @input)
70
70
  composed << self
71
71
  others.each { |other| composed << other }
72
72
  composed
@@ -75,7 +75,7 @@ class Proc
75
75
  # [public] Returns a composition built from this callable context and another callable.
76
76
  #
77
77
  def >>(other)
78
- composed = Composition.new(client: @client, input: @input)
78
+ composed = ::Proc::Composition.new(client: @client, input: @input)
79
79
  composed << self
80
80
  composed << other
81
81
  composed
@@ -84,7 +84,7 @@ class Proc
84
84
  def serialize(unwrapped: false)
85
85
  serialized = ["()", @proc]
86
86
 
87
- unless Proc.undefined?(@input)
87
+ unless ::Proc.undefined?(@input)
88
88
  serialized << [">>", serialized_input]
89
89
  end
90
90
 
@@ -110,7 +110,7 @@ class Proc
110
110
  # [public] Returns a callable context for `proc`, nested within this callable context.
111
111
  #
112
112
  def [](proc)
113
- arguments = if block_given?
113
+ arguments = if ::Kernel.block_given?
114
114
  duped = @arguments.dup
115
115
  duped[:proc] = yield
116
116
  duped
@@ -118,7 +118,7 @@ class Proc
118
118
  @arguments
119
119
  end
120
120
 
121
- Callable.new(
121
+ ::Proc::Callable.new(
122
122
  [@proc, proc].join("."),
123
123
  client: @client,
124
124
  input: @input,
@@ -134,11 +134,11 @@ class Proc
134
134
  if IGNORE_MISSING.include?(name)
135
135
  super
136
136
  else
137
- if block_given?
137
+ if ::Kernel.block_given?
138
138
  arguments[:proc] = yield
139
139
  end
140
140
 
141
- Callable.new(
141
+ ::Proc::Callable.new(
142
142
  [@proc, name].join("."),
143
143
  client: @client,
144
144
  input: input_omitted ? @input : input,
@@ -156,9 +156,10 @@ class Proc
156
156
  end
157
157
 
158
158
  private def serialize_value(value)
159
- if value.is_a?(Symbol)
159
+ case value
160
+ when ::Symbol
160
161
  ["@@", value.to_s, {}]
161
- elsif value.respond_to?(:serialize)
162
+ when ::Proc::Argument, ::Proc::Callable, ::Proc::Composition
162
163
  value.serialize
163
164
  else
164
165
  ["%%", value]
data/lib/proc/client.rb CHANGED
@@ -56,8 +56,8 @@ class Proc
56
56
 
57
57
  # [public] Connection to proc, configured with an authorization.
58
58
  #
59
- class Client
60
- include Is::Async
59
+ class Client < BasicObject
60
+ include ::Is::Async
61
61
 
62
62
  # [public] The configured authorization.
63
63
  #
@@ -97,10 +97,10 @@ class Proc
97
97
  # [public] Returns a callable context for `proc`.
98
98
  #
99
99
  def [](proc)
100
- if block_given?
101
- Callable.new(proc, client: self, arguments: {proc: yield})
100
+ if ::Kernel.block_given?
101
+ ::Proc::Callable.new(proc, client: self, arguments: {proc: yield})
102
102
  else
103
- Callable.new(proc, client: self)
103
+ ::Proc::Callable.new(proc, client: self)
104
104
  end
105
105
  end
106
106
 
@@ -135,10 +135,10 @@ class Proc
135
135
  #
136
136
  # If a block is passed and the proc returns an enumerable, the block will be called with each value.
137
137
  #
138
- def call(proc = nil, input = Proc.undefined, **arguments, &block)
138
+ def call(proc = nil, input = ::Proc.undefined, **arguments, &block)
139
139
  body = []
140
140
 
141
- unless Proc.undefined?(input)
141
+ unless ::Proc.undefined?(input)
142
142
  body << [">>", serialize_value(input)]
143
143
  end
144
144
 
@@ -154,9 +154,9 @@ class Proc
154
154
 
155
155
  if (cursor = headers["x-cursor"])
156
156
  enumerator = if cursor.empty?
157
- Enumerator.new(result)
157
+ ::Proc::Enumerator.new(result)
158
158
  else
159
- Enumerator.new(result) {
159
+ ::Proc::Enumerator.new(result) {
160
160
  arguments[:cursor] = cursor.to_s
161
161
  call(proc, input, **arguments)
162
162
  }
@@ -171,25 +171,25 @@ class Proc
171
171
  result
172
172
  end
173
173
  when 400
174
- raise Proc::Invalid, extract_error_message(payload)
174
+ ::Kernel.raise ::Proc::Invalid, extract_error_message(payload)
175
175
  when 401
176
- raise Proc::Unauthorized, extract_error_message(payload)
176
+ ::Kernel.raise ::Proc::Unauthorized, extract_error_message(payload)
177
177
  when 403
178
- raise Proc::Forbidden, extract_error_message(payload)
178
+ ::Kernel.raise ::Proc::Forbidden, extract_error_message(payload)
179
179
  when 404
180
- raise Proc::Undefined, extract_error_message(payload)
180
+ ::Kernel.raise ::Proc::Undefined, extract_error_message(payload)
181
181
  when 408
182
- raise Proc::Timeout, extract_error_message(payload)
182
+ ::Kernel.raise ::Proc::Timeout, extract_error_message(payload)
183
183
  when 413
184
- raise Proc::Invalid, extract_error_message(payload)
184
+ ::Kernel.raise ::Proc::Invalid, extract_error_message(payload)
185
185
  when 429
186
- raise Proc::Limited, extract_error_message(payload)
186
+ ::Kernel.raise ::Proc::Limited, extract_error_message(payload)
187
187
  when 500
188
- raise Proc::Error, extract_error_message(payload)
188
+ ::Kernel.raise ::Proc::Error, extract_error_message(payload)
189
189
  when 508
190
- raise Proc::Error, extract_error_message(payload)
190
+ ::Kernel.raise ::Proc::Error, extract_error_message(payload)
191
191
  else
192
- raise Proc::Error, "unhandled"
192
+ ::Kernel.raise ::Proc::Error, "unhandled"
193
193
  end
194
194
  end
195
195
 
@@ -197,9 +197,9 @@ class Proc
197
197
  #
198
198
  def method_missing(name, input = input_omitted = true, *, **arguments)
199
199
  if input_omitted
200
- Callable.new(name, client: self, arguments: arguments)
200
+ ::Proc::Callable.new(name, client: self, arguments: arguments)
201
201
  else
202
- Callable.new(name, client: self, input: input, arguments: arguments)
202
+ ::Proc::Callable.new(name, client: self, input: input, arguments: arguments)
203
203
  end
204
204
  end
205
205
 
@@ -210,18 +210,19 @@ class Proc
210
210
  # [public] Builds a named argument with options.
211
211
  #
212
212
  def argument(name, **options)
213
- Argument.new(name, **options)
213
+ ::Proc::Argument.new(name, **options)
214
214
  end
215
215
  alias_method :arg, :argument
216
216
 
217
217
  private def build_uri(proc)
218
- File.join(@__base_url, proc.to_s.split(".").join("/"))
218
+ ::File.join(@__base_url, proc.to_s.split(".").join("/"))
219
219
  end
220
220
 
221
221
  private def serialize_value(value)
222
- if value.is_a?(Symbol)
222
+ case value
223
+ when ::Symbol
223
224
  ["@@", value.to_s, {}]
224
- elsif value.respond_to?(:serialize)
225
+ when ::Proc::Argument, ::Proc::Callable, ::Proc::Composition
225
226
  value.serialize
226
227
  else
227
228
  ["%%", value]
@@ -232,15 +233,15 @@ class Proc
232
233
  await {
233
234
  @request_count += 1
234
235
 
235
- response = HTTP.headers(@__headers).post(build_uri(proc), body: MessagePack.pack(body))
236
+ response = ::HTTP.headers(@__headers).post(build_uri(proc), body: ::MessagePack.pack(body))
236
237
 
237
238
  update_rate_limit(response)
238
239
  @response = response
239
240
 
240
- [response.status, response.headers, MessagePack.unpack(response.to_s)]
241
+ [response.status, response.headers, ::MessagePack.unpack(response.to_s)]
241
242
  }
242
243
  rescue
243
- raise Proc::Unavailable
244
+ ::Kernel.raise ::Proc::Unavailable
244
245
  end
245
246
 
246
247
  private def update_rate_limit(response)
@@ -256,7 +257,7 @@ class Proc
256
257
  end
257
258
 
258
259
  @rate_limit_reset = if (reset = response.headers["x-rate-limit-reset"])
259
- Time.at(reset.to_s.to_i)
260
+ ::Time.at(reset.to_s.to_i)
260
261
  end
261
262
  end
262
263
 
@@ -113,9 +113,10 @@ class Proc
113
113
  end
114
114
 
115
115
  private def serialize_value(value)
116
- if value.is_a?(Symbol)
116
+ case value
117
+ when Symbol
117
118
  ["@@", value.to_s, {}]
118
- elsif value.respond_to?(:serialize)
119
+ when Argument, Callable, Composition
119
120
  value.serialize
120
121
  else
121
122
  ["%%", value]
data/lib/proc/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Proc
4
- VERSION = "0.11.1"
4
+ VERSION = "0.12.0"
5
5
 
6
6
  # [public]
7
7
  #
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.11.1
4
+ version: 0.12.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: 2021-04-19 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-async
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.4'
55
- description: Proc Ruby client.
55
+ description: Proc client library.
56
56
  email: bryan@metabahn.com
57
57
  executables: []
58
58
  extensions: []
@@ -68,7 +68,7 @@ files:
68
68
  - lib/proc/enumerator.rb
69
69
  - lib/proc/msgpack/types/decimal.rb
70
70
  - lib/proc/version.rb
71
- homepage: https://github.com/metabahn/proc-rb/
71
+ homepage: https://proc.dev
72
72
  licenses:
73
73
  - MPL-2.0
74
74
  metadata: {}
@@ -90,5 +90,5 @@ requirements: []
90
90
  rubygems_version: 3.2.15
91
91
  signing_key:
92
92
  specification_version: 4
93
- summary: Proc Ruby client.
93
+ summary: Proc client library.
94
94
  test_files: []