Module: Localhost::State
- Defined in:
- lib/localhost/state.rb
Overview
Represents a single public/private key pair for a given hostname.
Class Method Summary collapse
-
.path(env = ENV) ⇒ Object
Where to store the key pair on the filesystem.
-
.purge(env = ENV) ⇒ Object
Delete the directory where the key pair is stored.
Class Method Details
.path(env = ENV) ⇒ Object
Where to store the key pair on the filesystem. This is a subdirectory of $XDG_STATE_HOME, or ~/.local/state/ when that’s not defined.
Ensures that the directory to store the certificate exists. If the legacy directory (~/.localhost/) exists, it is moved into the new XDG Basedir compliant directory.
19 20 21 22 23 24 25 26 27 |
# File 'lib/localhost/state.rb', line 19 def self.path(env = ENV) path = File.("localhost.rb", env.fetch("XDG_STATE_HOME", "~/.local/state")) unless File.directory?(path) FileUtils.mkdir_p(path, mode: 0700) end return path end |
.purge(env = ENV) ⇒ Object
Delete the directory where the key pair is stored.
32 33 34 35 36 |
# File 'lib/localhost/state.rb', line 32 def self.purge(env = ENV) path = self.path(env) return FileUtils.rm_rf(path) end |