2018-09-17 11:41:14 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-21 02:01:33 -03:00
|
|
|
require 'yaml'
|
|
|
|
|
2016-02-06 19:00:29 -08:00
|
|
|
module Puma
|
|
|
|
class StateFile
|
|
|
|
def initialize
|
|
|
|
@options = {}
|
|
|
|
end
|
|
|
|
|
2020-05-06 23:13:35 -04:00
|
|
|
def save(path, permission = nil)
|
2020-11-27 09:47:33 -06:00
|
|
|
contents =YAML.dump @options
|
|
|
|
if permission
|
|
|
|
File.write path, contents, mode: 'wb:UTF-8'
|
|
|
|
else
|
|
|
|
File.write path, contents, mode: 'wb:UTF-8', perm: permission
|
2020-05-06 23:13:35 -04:00
|
|
|
end
|
2016-02-06 19:00:29 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def load(path)
|
|
|
|
@options = YAML.load File.read(path)
|
|
|
|
end
|
|
|
|
|
2020-05-23 19:27:51 +02:00
|
|
|
FIELDS = %w!control_url control_auth_token pid running_from!
|
2016-02-06 19:00:29 -08:00
|
|
|
|
|
|
|
FIELDS.each do |f|
|
|
|
|
define_method f do
|
|
|
|
@options[f]
|
|
|
|
end
|
|
|
|
|
|
|
|
define_method "#{f}=" do |v|
|
|
|
|
@options[f] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|