Module: Vnehm::Cfg

Defined in:
lib/vnehm/cfg.rb

Overview

Cfg module manipulates with nehm’s config file (~/.vnehmconfig)

Constant Summary collapse

FILE_PATH =
File.join(ENV['HOME'], '.vnehmconfig')

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



12
13
14
# File 'lib/vnehm/cfg.rb', line 12

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

.[]=(key, value) ⇒ Object



16
17
18
19
# File 'lib/vnehm/cfg.rb', line 16

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

.config_hashObject



35
36
37
38
39
40
# File 'lib/vnehm/cfg.rb', line 35

def config_hash
  @config_hash ||= YAML.load_file(FILE_PATH)
  @config_hash ||= {} unless @config_hash

  @config_hash
end

.createObject



21
22
23
# File 'lib/vnehm/cfg.rb', line 21

def self.create
  File.new(FILE_PATH, 'w+')
end

.exist?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/vnehm/cfg.rb', line 25

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

.key?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/vnehm/cfg.rb', line 29

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

.writeObject



42
43
44
# File 'lib/vnehm/cfg.rb', line 42

def write
  IO.write(FILE_PATH, config_hash.to_yaml)
end