Class: ChidConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/chid/chid_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChidConfig

Returns a new instance of ChidConfig.



5
6
7
8
9
# File 'lib/chid/chid_config.rb', line 5

def initialize
  @chid_path = Dir.pwd
  @home_path = File.expand_path("~/")
  @chid_config_path = File.join(home_path, '.chid.config')
end

Instance Attribute Details

#chid_config_pathObject (readonly)

Returns the value of attribute chid_config_path.



3
4
5
# File 'lib/chid/chid_config.rb', line 3

def chid_config_path
  @chid_config_path
end

#chid_pathObject (readonly)

Returns the value of attribute chid_path.



3
4
5
# File 'lib/chid/chid_config.rb', line 3

def chid_path
  @chid_path
end

#home_pathObject (readonly)

Returns the value of attribute home_path.



3
4
5
# File 'lib/chid/chid_config.rb', line 3

def home_path
  @home_path
end

Class Method Details

.on_linuxObject



16
17
18
19
20
# File 'lib/chid/chid_config.rb', line 16

def self.on_linux
  if  platform =~ /Linux/
    yield
  end
end

.on_osxObject



22
23
24
25
26
# File 'lib/chid/chid_config.rb', line 22

def self.on_osx
  if  platform =~ /Darwin/
    yield
  end
end

.platformObject



28
29
30
# File 'lib/chid/chid_config.rb', line 28

def self.platform
  %x{echo $(uname -s)}.strip
end

.usernameObject



11
12
13
14
# File 'lib/chid/chid_config.rb', line 11

def self.username
  on_linux { return  %x[echo $USER].strip }
  on_osx   { return  %x[echo $(logname)].strip }
end

Instance Method Details

#all_tmux_templatesObject



37
38
39
40
# File 'lib/chid/chid_config.rb', line 37

def all_tmux_templates
  data = YAML.load_file chid_config_path
  data[:chid][:tmux_templates]
end

#all_workstationsObject



32
33
34
35
# File 'lib/chid/chid_config.rb', line 32

def all_workstations
  data = YAML.load_file chid_config_path
  data[:chid][:workstations]
end

#create_workstation(name, apps = []) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/chid/chid_config.rb', line 54

def create_workstation(name, apps = [])
  data = YAML.load_file chid_config_path

  data[:chid][:workstations][:"#{name}"] = apps

  File.open(chid_config_path, 'w') do |file|
    YAML.dump(data, file)
  end
end

#destroy_workstations(workstations = []) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chid/chid_config.rb', line 42

def destroy_workstations(workstations = [])
  data = YAML.load_file chid_config_path

  workstations.each do |w|
    data[:chid][:workstations].delete_if { |key, value| key == w }
  end

  File.open(chid_config_path, 'w') do |file|
    YAML.dump(data, file)
  end
end