Class: Gretl::Client
- Inherits:
-
Object
- Object
- Gretl::Client
- Defined in:
- lib/gretl.rb
Instance Method Summary collapse
- #active ⇒ Object
- #inactive ⇒ Object
- #port(query) ⇒ Object
- #ports ⇒ Object
- #remove(query) ⇒ Object
- #start(query) ⇒ Object
- #start_group(group) ⇒ Object
- #status_group(group) ⇒ Object
- #stop(query) ⇒ Object
- #stop_group(group) ⇒ Object
- #wait_for_active(query, timeout: 30, interval: 0.5) ⇒ Object
- #wait_for_inactive(query, timeout: 30, interval: 0.5) ⇒ Object
Instance Method Details
#active ⇒ Object
53 |
# File 'lib/gretl.rb', line 53 def active = _fetch_ports.select(&:active) |
#inactive ⇒ Object
54 |
# File 'lib/gretl.rb', line 54 def inactive = _fetch_ports.reject(&:active) |
#ports ⇒ Object
51 |
# File 'lib/gretl.rb', line 51 def ports = Gretl._fetch_ports |
#remove(query) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/gretl.rb', line 94 def remove(query) matches = Gretl._resolve(query) raise ArgumentError, "No port found matching #{query.inspect}" if matches.empty? matches.each { |p| Gretl._request(:delete, "/ports/#{p.port}") } matches end |
#start(query) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/gretl.rb', line 56 def start(query) matches = Gretl._resolve(query) raise ArgumentError, "No port found matching #{query.inspect}" if matches.empty? matches.each do |p| Gretl._request(:post, "/ports/#{p.port}/start") if !p.active && p.has_command end matches end |
#start_group(group) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/gretl.rb', line 74 def start_group(group) matches = Gretl._fetch_ports.select { |p| p.group&.downcase == group.downcase } raise ArgumentError, "No ports found in group #{group.inspect}" if matches.empty? matches.each { |p| Gretl._request(:post, "/ports/#{p.port}/start") if !p.active && p.has_command } matches end |
#status_group(group) ⇒ Object
88 89 90 91 92 |
# File 'lib/gretl.rb', line 88 def status_group(group) matches = Gretl._fetch_ports.select { |p| p.group&.downcase == group.downcase } raise ArgumentError, "No ports found in group #{group.inspect}" if matches.empty? matches end |
#stop(query) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/gretl.rb', line 65 def stop(query) matches = Gretl._resolve(query) raise ArgumentError, "No port found matching #{query.inspect}" if matches.empty? matches.each do |p| Gretl._request(:post, "/ports/#{p.port}/stop") if p.active end matches end |
#stop_group(group) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/gretl.rb', line 81 def stop_group(group) matches = Gretl._fetch_ports.select { |p| p.group&.downcase == group.downcase } raise ArgumentError, "No ports found in group #{group.inspect}" if matches.empty? matches.each { |p| Gretl._request(:post, "/ports/#{p.port}/stop") if p.active } matches end |
#wait_for_active(query, timeout: 30, interval: 0.5) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/gretl.rb', line 101 def wait_for_active(query, timeout: 30, interval: 0.5) deadline = Time.now + timeout while Time.now < deadline Gretl._resolve(query).each { |p| return p if p.active } sleep interval end raise "Port matching #{query.inspect} did not become active within #{timeout}s" end |
#wait_for_inactive(query, timeout: 30, interval: 0.5) ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/gretl.rb', line 110 def wait_for_inactive(query, timeout: 30, interval: 0.5) deadline = Time.now + timeout while Time.now < deadline Gretl._resolve(query).each { |p| return p if p.stopped? } sleep interval end raise "Port matching #{query.inspect} did not become inactive within #{timeout}s" end |