Class: WindClutter::Util::Config

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

Overview

Config handler

Class Method Summary collapse

Class Method Details

.exists?Boolean

Returns:

  • (Boolean)


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

def self.exists?
  File.file?('/tmp/windclutter/config.yml')
end

.read(key) ⇒ Object



58
59
60
61
62
63
# File 'lib/windclutter/util/config.rb', line 58

def self.read(key)
  return unless exists?

  config = YAML.load_file('/tmp/windclutter/config.yml')
  config[key]
end

.read_project(name, key) ⇒ Object



51
52
53
54
55
56
# File 'lib/windclutter/util/config.rb', line 51

def self.read_project(name, key)
  return unless exists?

  config = YAML.load_file('/tmp/windclutter/config.yml')
  config['projects'][name][key]
end

.setup_project(name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/windclutter/util/config.rb', line 20

def self.setup_project(name)
  return unless exists?

  config = YAML.load_file('/tmp/windclutter/config.yml')

  config['projects'][name] = {
    'project_path' => nil,
    'dump_path' => nil,
    'class_key' => 'class',
    'class_start' => '"',
    'class_end' => '"'
  }

  File.open('/tmp/windclutter/config.yml', 'w') { |f| YAML.dump(config, f) }
end

.update(key, value) ⇒ Object



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

def self.update(key, value)
  return unless exists?

  config = YAML.load_file('/tmp/windclutter/config.yml')
  config[key] = value

  File.open('/tmp/windclutter/config.yml', 'w') { |f| YAML.dump(config, f) }
end

.update_project(name, key, value) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/windclutter/util/config.rb', line 36

def self.update_project(name, key, value)
  return unless exists?

  config = YAML.load_file('/tmp/windclutter/config.yml')
  if config['projects'][name].nil?
    config['projects'][name] = {
      'project_path' => nil,
      'dump_path' => nil
    }
  end
  config['projects'][name][key] = value

  File.open('/tmp/windclutter/config.yml', 'w') { |f| YAML.dump(config, f) }
end

.wtf?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
# File 'lib/windclutter/util/config.rb', line 65

def self.wtf?
  return puts 'No config found.'.red unless exists?

  YAML.load_file('/tmp/windclutter/config.yml')
end