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