Class: SrvManager::Context
- Inherits:
-
Object
- Object
- SrvManager::Context
- Defined in:
- lib/srv_manager/context.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.scoped(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/srv_manager/context.rb', line 22 def self.scoped(={}) context = load monitor_running = [:safe] && context.monitor.alive? context.monitor.stop if monitor_running begin yield context ensure save context if monitor_running context.monitor.start save context end end end |
Instance Method Details
#clean ⇒ Object
12 13 14 15 |
# File 'lib/srv_manager/context.rb', line 12 def clean services.each(&:stop) services.clear end |
#load(json) ⇒ Object
17 18 19 20 |
# File 'lib/srv_manager/context.rb', line 17 def load(json) clean @services = json['services'].map { |js| Service.parse js } end |
#monitor ⇒ Object
4 5 6 |
# File 'lib/srv_manager/context.rb', line 4 def monitor @monitor ||= Monitor.new end |
#services ⇒ Object
8 9 10 |
# File 'lib/srv_manager/context.rb', line 8 def services @services ||= [] end |
#to_hash ⇒ Object
37 38 39 |
# File 'lib/srv_manager/context.rb', line 37 def to_hash {services: services.map(&:to_hash)} end |