class SrvManager::Context
Public Class Methods
scoped(options={}) { |context| ... }
click to toggle source
# File lib/srv_manager/context.rb, line 22 def self.scoped(options={}) context = load monitor_running = options[: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
Private Class Methods
data_file()
click to toggle source
# File lib/srv_manager/context.rb, line 55 def self.data_file File.expand_path('.srv_manager/context.bin', Dir.home) end
load()
click to toggle source
# File lib/srv_manager/context.rb, line 43 def self.load LOGGER.debug "Reading context from #{data_file}" return new unless File.exists? data_file Marshal.load(File.read(data_file)) end
save(context)
click to toggle source
# File lib/srv_manager/context.rb, line 49 def self.save(context) LOGGER.debug "Saving context to #{data_file}" FileUtils.mkpath File.dirname(data_file) unless Dir.exists? File.dirname(data_file) File.write data_file, Marshal.dump(context) end
Public Instance Methods
clean()
click to toggle source
# File lib/srv_manager/context.rb, line 12 def clean services.each(&:stop) services.clear end
load(json)
click to toggle source
# File lib/srv_manager/context.rb, line 17 def load(json) clean @services = json['services'].map { |js| Service.parse js } end
monitor()
click to toggle source
# File lib/srv_manager/context.rb, line 4 def monitor @monitor ||= Monitor.new end
services()
click to toggle source
# File lib/srv_manager/context.rb, line 8 def services @services ||= [] end
to_hash()
click to toggle source
# File lib/srv_manager/context.rb, line 37 def to_hash {services: services.map(&:to_hash)} end