Module: Config

Defined in:
lib/nehm/config.rb

Overview

Config module manipulate with nehm’s config file (~/.nehmconfig)

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



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

def self.[](key)
  config_hash = load_config
  config_hash[key.to_s]
end

.[]=(key, value) ⇒ Object



10
11
12
13
14
# File 'lib/nehm/config.rb', line 10

def self.[]=(key, value)
  config_hash = load_config
  config_hash[key.to_s] = value
  save_config(config_hash)
end

.createObject



16
17
18
# File 'lib/nehm/config.rb', line 16

def self.create
  File.open(file_path, 'w+') { |f| f.write("---\napp: nehm") }
end

.exist?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/nehm/config.rb', line 20

def self.exist?
  File.exist?(file_path)
end

.file_pathObject



30
31
32
# File 'lib/nehm/config.rb', line 30

def file_path
  File.join(ENV['HOME'], '.nehmconfig')
end

.key?(key) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/nehm/config.rb', line 24

def self.key?(key)
  load_config.key?(key.to_s)
end

.load_configObject



34
35
36
# File 'lib/nehm/config.rb', line 34

def load_config
  YAML.load_file(file_path)
end

.save_config(config_hash) ⇒ Object



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

def save_config(config_hash)
  IO.write(file_path, config_hash.to_yaml)
end