Class: Mode::Config

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

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.



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

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

#data_sourcesObject

Returns the value of attribute data_sources.



11
12
13
# File 'lib/mode/config.rb', line 11

def data_sources
  @data_sources
end

#environmentObject

Returns the value of attribute environment.



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

def environment
  @environment
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/mode/config.rb', line 5

def path
  @path
end

#usernameObject

Config Variables



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

def username
  @username
end

Class Method Details

.default_dirObject



59
60
61
# File 'lib/mode/config.rb', line 59

def default_dir
  File.expand_path("~/.mode")
end

.default_filenameObject



38
39
40
# File 'lib/mode/config.rb', line 38

def default_filename
  'config.yml'
end

.drivers_dirObject



67
68
69
# File 'lib/mode/config.rb', line 67

def drivers_dir
  File.join(default_dir, 'drivers')
end

.exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/mode/config.rb', line 42

def exists?(path)
  File.exist?(full_path(path))
end

.full_path(path, filename = nil) ⇒ Object



71
72
73
# File 'lib/mode/config.rb', line 71

def full_path(path, filename = nil)
  File.expand_path(File.join(path, filename || default_filename))
end

.init(path, filename = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mode/config.rb', line 46

def init(path, filename = nil)
  FileUtils.mkdir_p(default_dir)
  
  FileUtils.mkdir_p(log_dir)
  FileUtils.mkdir_p(drivers_dir)

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

  new(path, filename)
end

.log_dirObject



63
64
65
# File 'lib/mode/config.rb', line 63

def log_dir
  File.join(default_dir, 'log')
end

Instance Method Details

#access_token_keyObject



29
30
31
# File 'lib/mode/config.rb', line 29

def access_token_key
  access_token && access_token['token']
end

#access_token_passwordObject



33
34
35
# File 'lib/mode/config.rb', line 33

def access_token_password
  access_token && access_token['password']
end

#saveObject



23
24
25
26
27
# File 'lib/mode/config.rb', line 23

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