Class: Mode::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mode/config.rb

Constant Summary collapse

FILENAME =
'.mode.yml'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, filename = nil) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
18
19
# File 'lib/mode/config.rb', line 11

def initialize(path, filename = nil)
  @path = self.class.full_path(path, filename)

  if File.exist?(@path)
    configure YAML.load_file(@path)
  else
    raise "Could not load configuration file from #{@path}"
  end
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



9
10
11
# File 'lib/mode/config.rb', line 9

def access_token
  @access_token
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/mode/config.rb', line 7

def path
  @path
end

#usernameObject

Returns the value of attribute username.



9
10
11
# File 'lib/mode/config.rb', line 9

def username
  @username
end

Class Method Details

.full_path(path, filename = nil) ⇒ Object



36
37
38
# File 'lib/mode/config.rb', line 36

def full_path(path, filename = nil)
  File.expand_path(File.join(path, filename || Mode::Config::FILENAME))
end

.init(path, filename = nil) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/mode/config.rb', line 28

def init(path, filename = nil)
  File.open(full_path(path, filename), 'w+') do |file|
    file.write({}.to_yaml)
  end

  new(path, filename)
end

Instance Method Details

#saveObject



21
22
23
24
25
# File 'lib/mode/config.rb', line 21

def save
  File.open(path, 'w+') do |file|
    file.write(to_yaml)
  end
end