Class: Ask::Auth::Providers::File

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/auth/providers/file.rb

Overview

Reads credentials from a YAML file (default: ~/.ask/credentials.yml).

Ask::Auth::Providers::File.new(path: "~/.ask/credentials.yml")

The file is automatically created (with 0600 permissions) when writing, but this provider is read-only by design.

Constant Summary collapse

DEFAULT_PATH =
"~/.ask/credentials.yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: DEFAULT_PATH) ⇒ File

Returns a new instance of File.



18
19
20
# File 'lib/ask/auth/providers/file.rb', line 18

def initialize(path: DEFAULT_PATH)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

The path this provider reads from.



32
33
34
# File 'lib/ask/auth/providers/file.rb', line 32

def path
  @path
end

Instance Method Details

#call(name, user: nil) ⇒ Object

Returns the credential value from the YAML file, or nil.



23
24
25
26
27
28
29
# File 'lib/ask/auth/providers/file.rb', line 23

def call(name, user: nil)
  data = load_file
  return nil unless data

  value = data[name.to_s] || data[name.to_sym]
  value
end