Class: ChidConfig
- Inherits:
-
Object
- Object
- ChidConfig
- Defined in:
- lib/chid/chid_config.rb
Instance Attribute Summary collapse
-
#chid_config_path ⇒ Object
readonly
Returns the value of attribute chid_config_path.
-
#chid_path ⇒ Object
readonly
Returns the value of attribute chid_path.
-
#home_path ⇒ Object
readonly
Returns the value of attribute home_path.
Class Method Summary collapse
Instance Method Summary collapse
- #all_tmux_templates ⇒ Object
- #all_workstations ⇒ Object
- #create_workstation(name, apps = []) ⇒ Object
- #destroy_workstations(workstations = []) ⇒ Object
-
#initialize ⇒ ChidConfig
constructor
A new instance of ChidConfig.
Constructor Details
#initialize ⇒ ChidConfig
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.("~/") @chid_config_path = File.join(home_path, '.chid.config') end |
Instance Attribute Details
#chid_config_path ⇒ Object (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_path ⇒ Object (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_path ⇒ Object (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_linux ⇒ Object
16 17 18 19 20 |
# File 'lib/chid/chid_config.rb', line 16 def self.on_linux if platform =~ /Linux/ yield end end |
.on_osx ⇒ Object
22 23 24 25 26 |
# File 'lib/chid/chid_config.rb', line 22 def self.on_osx if platform =~ /Darwin/ yield end end |
.platform ⇒ Object
28 29 30 |
# File 'lib/chid/chid_config.rb', line 28 def self.platform %x{echo $(uname -s)}.strip end |
.username ⇒ Object
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_templates ⇒ Object
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_workstations ⇒ Object
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 |