class Octoauth::ConfigFile

Configuration object

Attributes

file[R]
token[RW]

Public Class Methods

new(params = {}) click to toggle source

Create new Config object, either ephemerally or from a file

# File lib/octoauth/configfile.rb, line 20
def initialize(params = {})
  @file = params[:file] == :default ? DEFAULT_FILE : params[:file]
  @file = File.expand_path(@file) if @file
  @note = params[:note] || raise(ArgumentError, 'A note must be provided')
  @token = parse
end

Public Instance Methods

write() click to toggle source
# File lib/octoauth/configfile.rb, line 27
def write
  new = get
  new[@note] = @token
  File.open(@file, 'w', 0o0600) { |fh| fh.write new.to_yaml }
end

Private Instance Methods

get() click to toggle source
# File lib/octoauth/configfile.rb, line 35
def get
  return {} unless @file && File.exist?(@file)
  YAML.safe_load File.read(File.expand_path(@file))
end
parse() click to toggle source
# File lib/octoauth/configfile.rb, line 40
def parse
  get[@note]
end