Class: Octoauth::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/octoauth/configfile.rb

Overview

Configuration object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ ConfigFile

Create new Config object, either ephemerally or from a file



20
21
22
23
24
25
# 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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



15
16
17
# File 'lib/octoauth/configfile.rb', line 15

def file
  @file
end

#tokenObject

Returns the value of attribute token.



16
17
18
# File 'lib/octoauth/configfile.rb', line 16

def token
  @token
end

Instance Method Details

#writeObject



27
28
29
30
31
# 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