proc 0.10.0 → 0.12.2

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: cc5ea46072b5407ec2b71822b8406163aeecd2aa6a57d10773e440bb08721ac5
4
- data.tar.gz: 4640295398b9266d57361f62aadf461b9d23e69f9fa0d21d60c5d1cd8b00715f
3
+ metadata.gz: '02639b241bf6aa890c69bebcf99739d987c6f47ea5a4eb5e122f74ff1f84abc4'
4
+ data.tar.gz: 400d2369a30233dfdeb510087b7ec20b28b7a8b9255d0e4b85ad18d2c57ab39c
5
5
  SHA512:
6
- metadata.gz: 45bb39ab2f194fe673f22a09d7d681c8514e639c71829a5673ac437991652212260fa6031c46fbdf92c48397865e1552ca7fdda72064a0ce6011c29dbee5e018
7
- data.tar.gz: 8d1ae22aa4ec5f39cd4c10e2fdf1fa24ad38355e511d5d12cd8935563cb7f6a835a166683922e56bf7db9cc30a5dda7dc649c4c39f3c47b060c5f528f4077331
6
+ metadata.gz: e6a9e623c4b14f9103d4df2c0338fc5656723902b2a56553dfeb8ddcb3c9c74001a5727ac06651351ce42cec801b0513c7988816647d5f9eb70cb89355fac805
7
+ data.tar.gz: bfa20fa9817dca6274b00e216e8853f93890b0b8ec10c6ca99070690c60c9acacb1c6260fec7f13e3734560c290257c0a1bee8aac5167e751bce735bdfd53f25
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## [v0.12.1](https://github.com/metabahn/proc/releases/tag/2021-05-13)
2
+
3
+ *released on 2021-05-13*
4
+
5
+ * `chg` [#2](https://github.com/metabahn/proc/pull/2) Update http.rb dependency ([bryanp](https://github.com/bryanp))
6
+
7
+
data/README.md CHANGED
@@ -1,80 +1,58 @@
1
- The `proc` gem lets you call codeless web functions through the proc.dev service.
1
+ **Superpowers to help you ship web endpoints faster.**
2
2
 
3
- ## Getting Started
3
+ Proc is an all-in-one toolchain for building, deploying, and calling custom behavior from any website or app.
4
4
 
5
- Install `proc` using the `gem` command from the command line:
5
+ * [Learn more about Proc](https://proc.dev)
6
+ * [Browse packages](https://proc.dev/packages)
7
+ * [Read the docs](https://proc.dev/docs)
8
+ * [Chat with us](https://discord.gg/aRu8qvkCmy)
6
9
 
7
- ```
8
- gem install proc
9
- ```
10
-
11
- You will also need a proc.dev account. Create a free account in seconds at [proc.dev](https://proc.dev/).
12
-
13
- ## Connecting
10
+ ## Install
14
11
 
15
- Sign in to your proc.dev account and locate your secret key. Use the secret to create a client connection:
12
+ Install with `gem install proc`:
16
13
 
17
- ```ruby
18
- client = Proc.connect("secret-key")
19
14
  ```
20
-
21
- ## Calling Procs
22
-
23
- You can call available procs through a connected client:
24
-
25
- ```ruby
26
- client.core.string.reverse.call("hello")
27
- => "olleh"
15
+ gem install proc
28
16
  ```
29
17
 
30
- Requests are sent to proc.dev anytime the `call` method is invoked.
18
+ ## Usage
31
19
 
32
- ## Callable Contexts
33
-
34
- Proc lookups create contexts that can be called later:
20
+ Connect to proc using an account secret or limited api key:
35
21
 
36
22
  ```ruby
37
- string = client.core.string
38
-
39
- string.reverse.call("hello")
40
- => "olleh"
23
+ require "proc"
41
24
 
42
- string.truncate.call("hello", length: 3)
43
- => "hel"
25
+ client = Proc.connect("{your-proc-authorization}")
44
26
  ```
45
27
 
46
- Contexts can be configured with default input and arguments using the `with` method:
28
+ Now you can call procs just like local code:
47
29
 
48
30
  ```ruby
49
- truncate = client.core.string.truncate.with("default", length: 1)
31
+ client.type.number.add.call(1, {value: 1});
50
32
 
51
- truncate.call
52
- => "d"
33
+ => 2
53
34
  ```
54
35
 
55
- Default input and/or arguments can be overidden for a specific call:
36
+ Build more complex behavior by composing procs together:
56
37
 
57
38
  ```ruby
58
- truncate.call(length: 3)
59
- => "def"
60
- ```
39
+ time = client.time
61
40
 
62
- Procs can also be looked up using the hash key syntax:
41
+ composition = time.now >> time.format(string: "%A")
63
42
 
64
- ```ruby
65
- client["core.string.truncate"].call("hello", length: 3)
66
- => "hel"
67
- ```
43
+ composition.call
68
44
 
69
- ## Compositions
45
+ => "Tuesday"
46
+ ````
70
47
 
71
- Procs can be composed together to build more complex behavior:
48
+ Instantly deploy your behavior to a private endpoint and call it from anywhere:
72
49
 
73
50
  ```ruby
74
- composition = client.core.string.reverse >> client.core.string.truncate(length: 3) >> client.core.string.capitalize
51
+ client.proc.create.call(name: "day_of_week", proc: composition)
52
+
53
+ client.self.day_of_week.call
75
54
 
76
- composition.call("hello")
77
- => "Oll"
55
+ => "Tuesday"
78
56
  ```
79
57
 
80
- Compositions are sent to proc.dev in a single request.
58
+ Learn more at [proc.dev](https://proc.dev). See you around!
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
  #
@@ -75,6 +75,8 @@ class Proc
75
75
  #
76
76
  attr_reader :request_count
77
77
 
78
+ attr_reader :response
79
+
78
80
  DEFAULT_HEADERS = {
79
81
  "accept" => "application/vnd.proc+msgpack",
80
82
  "content-type" => "application/vnd.proc+msgpack"
@@ -95,10 +97,10 @@ class Proc
95
97
  # [public] Returns a callable context for `proc`.
96
98
  #
97
99
  def [](proc)
98
- if block_given?
99
- Callable.new(proc, client: self, arguments: {proc: yield})
100
+ if ::Kernel.block_given?
101
+ ::Proc::Callable.new(proc, client: self, arguments: {proc: yield})
100
102
  else
101
- Callable.new(proc, client: self)
103
+ ::Proc::Callable.new(proc, client: self)
102
104
  end
103
105
  end
104
106
 
@@ -124,8 +126,8 @@ class Proc
124
126
  end
125
127
 
126
128
  private def refresh_rate_limit
127
- unless defined?(@rate_limit_reset)
128
- self["ping"].call
129
+ unless defined?(@rate_limit)
130
+ self["core.ping"].call
129
131
  end
130
132
  end
131
133
 
@@ -133,10 +135,10 @@ class Proc
133
135
  #
134
136
  # If a block is passed and the proc returns an enumerable, the block will be called with each value.
135
137
  #
136
- def call(proc = nil, input = Proc.undefined, **arguments, &block)
138
+ def call(proc = nil, input = ::Proc.undefined, **arguments, &block)
137
139
  body = []
138
140
 
139
- unless Proc.undefined?(input)
141
+ unless ::Proc.undefined?(input)
140
142
  body << [">>", serialize_value(input)]
141
143
  end
142
144
 
@@ -152,9 +154,9 @@ class Proc
152
154
 
153
155
  if (cursor = headers["x-cursor"])
154
156
  enumerator = if cursor.empty?
155
- Enumerator.new(result)
157
+ ::Proc::Enumerator.new(result)
156
158
  else
157
- Enumerator.new(result) {
159
+ ::Proc::Enumerator.new(result) {
158
160
  arguments[:cursor] = cursor.to_s
159
161
  call(proc, input, **arguments)
160
162
  }
@@ -169,25 +171,25 @@ class Proc
169
171
  result
170
172
  end
171
173
  when 400
172
- raise Proc::Invalid, extract_error_message(payload)
174
+ ::Kernel.raise ::Proc::Invalid, extract_error_message(payload)
173
175
  when 401
174
- raise Proc::Unauthorized, extract_error_message(payload)
176
+ ::Kernel.raise ::Proc::Unauthorized, extract_error_message(payload)
175
177
  when 403
176
- raise Proc::Forbidden, extract_error_message(payload)
178
+ ::Kernel.raise ::Proc::Forbidden, extract_error_message(payload)
177
179
  when 404
178
- raise Proc::Undefined, extract_error_message(payload)
180
+ ::Kernel.raise ::Proc::Undefined, extract_error_message(payload)
179
181
  when 408
180
- raise Proc::Timeout, extract_error_message(payload)
182
+ ::Kernel.raise ::Proc::Timeout, extract_error_message(payload)
181
183
  when 413
182
- raise Proc::Invalid, extract_error_message(payload)
184
+ ::Kernel.raise ::Proc::Invalid, extract_error_message(payload)
183
185
  when 429
184
- raise Proc::Limited, extract_error_message(payload)
186
+ ::Kernel.raise ::Proc::Limited, extract_error_message(payload)
185
187
  when 500
186
- raise Proc::Error, extract_error_message(payload)
188
+ ::Kernel.raise ::Proc::Error, extract_error_message(payload)
187
189
  when 508
188
- raise Proc::Error, extract_error_message(payload)
190
+ ::Kernel.raise ::Proc::Error, extract_error_message(payload)
189
191
  else
190
- raise Proc::Error, "unhandled"
192
+ ::Kernel.raise ::Proc::Error, "unhandled"
191
193
  end
192
194
  end
193
195
 
@@ -195,9 +197,9 @@ class Proc
195
197
  #
196
198
  def method_missing(name, input = input_omitted = true, *, **arguments)
197
199
  if input_omitted
198
- Callable.new(name, client: self, arguments: arguments)
200
+ ::Proc::Callable.new(name, client: self, arguments: arguments)
199
201
  else
200
- Callable.new(name, client: self, input: input, arguments: arguments)
202
+ ::Proc::Callable.new(name, client: self, input: input, arguments: arguments)
201
203
  end
202
204
  end
203
205
 
@@ -208,18 +210,19 @@ class Proc
208
210
  # [public] Builds a named argument with options.
209
211
  #
210
212
  def argument(name, **options)
211
- Argument.new(name, **options)
213
+ ::Proc::Argument.new(name, **options)
212
214
  end
213
215
  alias_method :arg, :argument
214
216
 
215
217
  private def build_uri(proc)
216
- File.join(@__base_url, proc.to_s.split(".").join("/"))
218
+ ::File.join(@__base_url, proc.to_s.split(".").join("/"))
217
219
  end
218
220
 
219
221
  private def serialize_value(value)
220
- if value.is_a?(Symbol)
222
+ case value
223
+ when ::Symbol
221
224
  ["@@", value.to_s, {}]
222
- elsif value.respond_to?(:serialize)
225
+ when ::Proc::Argument, ::Proc::Callable, ::Proc::Composition
223
226
  value.serialize
224
227
  else
225
228
  ["%%", value]
@@ -230,14 +233,15 @@ class Proc
230
233
  await {
231
234
  @request_count += 1
232
235
 
233
- 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))
234
237
 
235
238
  update_rate_limit(response)
239
+ @response = response
236
240
 
237
- [response.status, response.headers, MessagePack.unpack(response.to_s)]
241
+ [response.status, response.headers, ::MessagePack.unpack(response.to_s)]
238
242
  }
239
243
  rescue
240
- raise Proc::Unavailable
244
+ ::Kernel.raise ::Proc::Unavailable
241
245
  end
242
246
 
243
247
  private def update_rate_limit(response)
@@ -253,7 +257,7 @@ class Proc
253
257
  end
254
258
 
255
259
  @rate_limit_reset = if (reset = response.headers["x-rate-limit-reset"])
256
- Time.at(reset.to_s.to_i)
260
+ ::Time.at(reset.to_s.to_i)
257
261
  end
258
262
  end
259
263
 
@@ -29,7 +29,7 @@ class Proc
29
29
  arguments: @arguments.merge(arguments)
30
30
  )
31
31
 
32
- @client.call("exec", Proc.undefined, proc: callable)
32
+ @client.call("core.exec", Proc.undefined, proc: callable)
33
33
  end
34
34
 
35
35
  # [public] Dispatches this composition to proc using the client, calling the given block once for each value.
@@ -42,7 +42,7 @@ class Proc
42
42
  arguments: @arguments.merge(arguments)
43
43
  )
44
44
 
45
- @client.call("exec", Proc.undefined, proc: callable, &block)
45
+ @client.call("core.exec", Proc.undefined, proc: callable, &block)
46
46
  end
47
47
 
48
48
  # [public] Creates a new composition based on this one, with a new input and/or arguments.
@@ -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]
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bigdecimal"
4
+
3
5
  class BigDecimal
4
6
  def to_msgpack(packer)
5
7
  if precision > 16
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.10.0"
4
+ VERSION = "0.12.2"
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.10.0
4
+ version: 0.12.2
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-01 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-async
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.0
19
+ version: '0.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.0
26
+ version: '0.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: http
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.4'
33
+ version: '5.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.4'
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: msgpack
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +58,7 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
+ - CHANGELOG.md
61
62
  - LICENSE
62
63
  - README.md
63
64
  - lib/proc.rb
@@ -68,7 +69,7 @@ files:
68
69
  - lib/proc/enumerator.rb
69
70
  - lib/proc/msgpack/types/decimal.rb
70
71
  - lib/proc/version.rb
71
- homepage: https://proc.dev/
72
+ homepage: https://proc.dev
72
73
  licenses:
73
74
  - MPL-2.0
74
75
  metadata: {}
@@ -80,14 +81,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
81
  requirements:
81
82
  - - ">="
82
83
  - !ruby/object:Gem::Version
83
- version: 2.5.0
84
+ version: 3.0.0
84
85
  required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  requirements: []
90
- rubygems_version: 3.2.4
91
+ rubygems_version: 3.2.15
91
92
  signing_key:
92
93
  specification_version: 4
93
94
  summary: Proc client library.