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



19
20
21
22
23
24
# File 'lib/octoauth/configfile.rb', line 19

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.



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

def file
  @file
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Instance Method Details

#writeObject



26
27
28
29
30
# File 'lib/octoauth/configfile.rb', line 26

def write
  new = get
  new[@note] = @token
  File.open(@file, 'w', 0o0600) { |fh| fh.write new.to_yaml }
end