Module: Agent::Lock::Store::BackendName
- Defined in:
- lib/agent/lock/store/backend_name.rb
Overview
A backend's name as somebody spelled it, read in one place so that nothing but "file" or "redis" can reach claim.
AGENT_LOCK_BACKEND used to reach the marker as typed, only
downcased, and was checked after: bogus, filesystem or a
variable exported empty bound the tree to a store that does not
exist, and every later command read the name back and refused it.
Constant Summary collapse
- VARIABLE =
The variable that names the backend when no caller does.
"AGENT_LOCK_BACKEND"
Class Method Summary collapse
-
.canonical(name, from = nil) ⇒ String?
A blank name is no name at all.
-
.from_environment ⇒ String?
What VARIABLE asks for; nil when it is unset or blank.
-
.marked(name, path, offer: nil) ⇒ String?
What a tree's marker holds, as long as that is a backend.
Class Method Details
.canonical(name, from = nil) ⇒ String?
A blank name is no name at all. filesystem is file, as it is
for --locking-strategy.
28 29 30 31 32 33 34 35 |
# File 'lib/agent/lock/store/backend_name.rb', line 28 def canonical(name, from = nil) spelled = name.to_s.strip return if spelled.empty? Facade::Strategies.canonical(spelled.downcase) rescue ArgumentError raise Mismatch, "unknown backend #{spelled.inspect}#{" in #{from}" if from}, expected file or redis" end |
.from_environment ⇒ String?
Returns what VARIABLE asks for; nil when it is unset or blank.
39 |
# File 'lib/agent/lock/store/backend_name.rb', line 39 def from_environment = canonical(ENV.fetch(VARIABLE, nil), VARIABLE) |
.marked(name, path, offer: nil) ⇒ String?
What a tree's marker holds, as long as that is a backend. A marker
an older alock wrote from a mistyped VARIABLE was refused by
every command with the name and nothing more, though
switch-backend rebinds such a tree: so that command is offered,
with the file store unless the caller asked for redis, since file
needs nothing to answer.
53 54 55 56 57 58 |
# File 'lib/agent/lock/store/backend_name.rb', line 53 def marked(name, path, offer: nil) return name if name.nil? || BACKENDS.include?(name) raise Mismatch.new("unknown backend #{name.inspect} in #{path}, expected file or redis", command: "switch-backend #{offer || "file"}") end |