nodo 1.5.4 → 1.5.5
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/README.md +30 -4
- data/lib/nodo/core.rb +2 -1
- data/lib/nodo/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: 3cef66bc4b1d53b20500110ac7acbc226ec361b6aaed569874ce8568a6718242
|
4
|
+
data.tar.gz: ab2cae6eef01d53ebc1c471a5e08edfd37a263178adc49aa459c98dfcea4e92f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bf90e8b56366f2e42039026575db43a0c5a9808a677a533c3e211c9ae211a8f06b2ea0890550e22fca259f9fa416c0e96017a676538a3eb673f2a66caa0996a
|
7
|
+
data.tar.gz: 2573e2dfd199bb9f8e25dc11c5dcb49e0ba6f29796aaa523656fa1020e0d8ce325ab411cf2d60413ac0557407fec4a132ba51d75075585a0e7b56d76bfc42811
|
data/README.md
CHANGED
@@ -39,13 +39,13 @@ In Nodo, you define JS functions as you would define Ruby methods:
|
|
39
39
|
|
40
40
|
```ruby
|
41
41
|
class Foo < Nodo::Core
|
42
|
-
|
42
|
+
|
43
43
|
function :say_hi, <<~JS
|
44
44
|
(name) => {
|
45
45
|
return `Hello ${name}!`;
|
46
46
|
}
|
47
47
|
JS
|
48
|
-
|
48
|
+
|
49
49
|
end
|
50
50
|
|
51
51
|
foo = Foo.new
|
@@ -90,6 +90,14 @@ class FooBar < Nodo::Core
|
|
90
90
|
end
|
91
91
|
```
|
92
92
|
|
93
|
+
### Alternate function definition syntax
|
94
|
+
|
95
|
+
JS code can also be supplied using the `code:` keyword argument:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
function :hello, code: "() => 'world'"
|
99
|
+
```
|
100
|
+
|
93
101
|
### Setting NODE_PATH
|
94
102
|
|
95
103
|
By default, `./node_modules` is used as the `NODE_PATH`.
|
@@ -130,7 +138,8 @@ end
|
|
130
138
|
|
131
139
|
### Inheritance
|
132
140
|
|
133
|
-
Subclasses will inherit functions, constants, dependencies and scripts from
|
141
|
+
Subclasses will inherit functions, constants, dependencies and scripts from
|
142
|
+
their superclasses, while only functions can be overwritten.
|
134
143
|
|
135
144
|
```ruby
|
136
145
|
class Foo < Nodo::Core
|
@@ -153,7 +162,8 @@ SubSubFoo.new.bar => "callingsubsubclass"
|
|
153
162
|
### Async functions
|
154
163
|
|
155
164
|
`Nodo` supports calling `async` functions from Ruby.
|
156
|
-
The Ruby call will happen synchronously, i.e. it will block until the JS
|
165
|
+
The Ruby call will happen synchronously, i.e. it will block until the JS
|
166
|
+
function resolves:
|
157
167
|
|
158
168
|
```ruby
|
159
169
|
class SyncFoo < Nodo::Core
|
@@ -162,3 +172,19 @@ class SyncFoo < Nodo::Core
|
|
162
172
|
JS
|
163
173
|
end
|
164
174
|
```
|
175
|
+
|
176
|
+
### Limiting function execution time
|
177
|
+
|
178
|
+
The default timeout for a single JS function call is 60 seconds due to the
|
179
|
+
`Net::HTTP` default. It can be overridden on a per-function basis:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
class Foo < Nodo::Core
|
183
|
+
function :sleep, timeout: 1, code: <<~'JS'
|
184
|
+
async (sec) => await new Promise(resolve => setTimeout(resolve, sec * 1000))
|
185
|
+
JS
|
186
|
+
end
|
187
|
+
|
188
|
+
foo.new.sleep(2)
|
189
|
+
=> Nodo::TimeoutError raised
|
190
|
+
```
|
data/lib/nodo/core.rb
CHANGED
@@ -63,6 +63,7 @@ module Nodo
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def function(name, _code = nil, timeout: 60, code: nil)
|
66
|
+
raise ArgumentError, "reserved method name #{name.inspect}" if Nodo::Core.method_defined?(name)
|
66
67
|
code = (code ||= _code).strip
|
67
68
|
raise ArgumentError, 'function code is required' if '' == code
|
68
69
|
self.functions = functions.merge(name => Function.new(name, _code || code, caller.first, timeout))
|
@@ -174,7 +175,7 @@ module Nodo
|
|
174
175
|
begin
|
175
176
|
break if socket = UNIXSocket.new(socket_path)
|
176
177
|
rescue Errno::ENOENT, Errno::ECONNREFUSED, Errno::ENOTDIR
|
177
|
-
sleep
|
178
|
+
Kernel.sleep(0.2)
|
178
179
|
end
|
179
180
|
end
|
180
181
|
socket.close if socket
|
data/lib/nodo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nodo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|