gretl 1.0.2 → 1.0.4
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/gretl.rb +40 -2
- 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: 1656965332fced86693ad3f2c07fdd3ddf9a7456ee6985109813e5d92226523f
|
|
4
|
+
data.tar.gz: d5c7cc8aac92b0d20d7da86f7b0e258e336445fa38cbf78e4560b3a54d5fe4d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa39a4f95613e614c4ea3ba13eed47d9a5ce770fba0416f3ed8b2718bebcdab2b72f7acd24d715eead4a112a8d70609ad78a797169b55f5ca2fa969126609db4
|
|
7
|
+
data.tar.gz: 664e92a0787ac6c3b81421372475234f904346c71862b862f09653ac173383de5d403382552add34518c9d76cbb023696c99a9b9403c8330c37195e110029097
|
data/lib/gretl.rb
CHANGED
|
@@ -5,6 +5,27 @@ require "uri"
|
|
|
5
5
|
module Gretl
|
|
6
6
|
BASE = "http://127.0.0.1:27892"
|
|
7
7
|
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def _daemon_running?
|
|
11
|
+
uri = URI("#{BASE}/health")
|
|
12
|
+
Net::HTTP.get_response(uri).is_a?(Net::HTTPSuccess)
|
|
13
|
+
rescue
|
|
14
|
+
false
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def _ensure_daemon
|
|
18
|
+
return if _daemon_running?
|
|
19
|
+
gr = `which gr 2>/dev/null`.strip
|
|
20
|
+
raise "Gretl daemon is not running and `gr` was not found on PATH.\nInstall with: npm install -g @gretl/cli then run: gr daemon start" if gr.empty?
|
|
21
|
+
spawn(gr, "daemon", "start", out: File::NULL, err: File::NULL)
|
|
22
|
+
25.times do
|
|
23
|
+
sleep 0.2
|
|
24
|
+
return if _daemon_running?
|
|
25
|
+
end
|
|
26
|
+
raise "Gretl daemon did not start in time. Run: gr daemon start"
|
|
27
|
+
end
|
|
28
|
+
|
|
8
29
|
PortInfo = Struct.new(
|
|
9
30
|
:port, :name, :active, :pid, :process,
|
|
10
31
|
:has_command, :group, :is_docker, :links,
|
|
@@ -18,6 +39,7 @@ module Gretl
|
|
|
18
39
|
module_function
|
|
19
40
|
|
|
20
41
|
def _request(method, path)
|
|
42
|
+
_ensure_daemon
|
|
21
43
|
uri = URI("#{BASE}#{path}")
|
|
22
44
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
23
45
|
http.open_timeout = 5
|
|
@@ -29,8 +51,8 @@ module Gretl
|
|
|
29
51
|
end
|
|
30
52
|
res = http.request(req)
|
|
31
53
|
JSON.parse(res.body, symbolize_names: true)
|
|
32
|
-
rescue Errno::ECONNREFUSED
|
|
33
|
-
raise "Cannot connect to Gretl
|
|
54
|
+
rescue Errno::ECONNREFUSED => e
|
|
55
|
+
raise "Cannot connect to Gretl daemon: #{e}"
|
|
34
56
|
end
|
|
35
57
|
|
|
36
58
|
def _fetch_ports
|
|
@@ -107,6 +129,22 @@ module Gretl
|
|
|
107
129
|
raise "Port matching #{query.inspect} did not become active within #{timeout}s"
|
|
108
130
|
end
|
|
109
131
|
|
|
132
|
+
def add(port, name: nil, cmd: nil, group: nil, cwd: nil)
|
|
133
|
+
Gretl._ensure_daemon
|
|
134
|
+
uri = URI("#{Gretl::BASE}/ports")
|
|
135
|
+
body = { port: port }
|
|
136
|
+
body[:name] = name if name
|
|
137
|
+
body[:cmd] = cmd if cmd
|
|
138
|
+
body[:group] = group if group
|
|
139
|
+
body[:cwd] = cwd if cwd
|
|
140
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
141
|
+
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
|
|
142
|
+
req.body = body.to_json
|
|
143
|
+
res = http.request(req)
|
|
144
|
+
data = JSON.parse(res.body, symbolize_names: true)
|
|
145
|
+
Gretl::PortInfo.new(**data.slice(*Gretl::PortInfo.members))
|
|
146
|
+
end
|
|
147
|
+
|
|
110
148
|
def wait_for_inactive(query, timeout: 30, interval: 0.5)
|
|
111
149
|
deadline = Time.now + timeout
|
|
112
150
|
while Time.now < deadline
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gretl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gretl
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email:
|