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
75 |
# File 'lib/gretl.rb', line 75 def active = Gretl._fetch_ports.select(&:active) |
#inactive ⇒ Object
76 |
# File 'lib/gretl.rb', line 76 def inactive = Gretl._fetch_ports.reject(&:active) |
#ports ⇒ Object
73 |
# File 'lib/gretl.rb', line 73 def ports = Gretl._fetch_ports |
#remove(query) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/gretl.rb', line 116 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
78 79 80 81 82 83 84 85 |
# File 'lib/gretl.rb', line 78 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
96 97 98 99 100 101 |
# File 'lib/gretl.rb', line 96 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
110 111 112 113 114 |
# File 'lib/gretl.rb', line 110 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
87 88 89 90 91 92 93 94 |
# File 'lib/gretl.rb', line 87 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
103 104 105 106 107 108 |
# File 'lib/gretl.rb', line 103 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
123 124 125 126 127 128 129 130 |
# File 'lib/gretl.rb', line 123 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
132 133 134 135 136 137 138 139 |
# File 'lib/gretl.rb', line 132 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 |