Class: Nerdinator::Config
- Inherits:
-
Object
- Object
- Nerdinator::Config
- Includes:
- Singleton
- Defined in:
- lib/nerdinator/config.rb
Constant Summary collapse
- SETTINGS_KEY =
'nerdinator'.freeze
Instance Method Summary collapse
- #link(name) ⇒ Object
- #local ⇒ Object
- #parse_settings(data) ⇒ Object
- #read(path = root) ⇒ Object
- #root ⇒ Object
- #setup(path) ⇒ Object
- #start(sessions) ⇒ Object
- #tmuxinator_command(session, settings) ⇒ Object
- #tmuxinator_root ⇒ Object
- #write(data) ⇒ Object
Instance Method Details
#link(name) ⇒ Object
54 55 56 57 |
# File 'lib/nerdinator/config.rb', line 54 def link(name) path = "#{tmuxinator_root}/#{name}.yml" File.symlink(local, path) unless File.symlink?(path) end |
#local ⇒ Object
15 16 17 |
# File 'lib/nerdinator/config.rb', line 15 def local File.("#{ENV['PWD']}/tmuxinator.yml") end |
#parse_settings(data) ⇒ Object
35 36 37 38 39 |
# File 'lib/nerdinator/config.rb', line 35 def parse_settings(data) if settings = data[SETTINGS_KEY] settings.map { |k, v| "#{k}=#{v}" }.join(' ') end end |
#read(path = root) ⇒ Object
24 25 26 27 |
# File 'lib/nerdinator/config.rb', line 24 def read(path = root) setup(path) unless File.exists?(path) YAML.load_file(path) end |
#root ⇒ Object
11 12 13 |
# File 'lib/nerdinator/config.rb', line 11 def root File.("#{ENV['HOME']}/.nerdinator/nerdinator.yml") end |
#setup(path) ⇒ Object
19 20 21 22 |
# File 'lib/nerdinator/config.rb', line 19 def setup(path) Dir.mkdir(path.split('/')[0...-1].join('/')) File.write(path, '') end |
#start(sessions) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/nerdinator/config.rb', line 45 def start(sessions) puts 'Nerdinator Sessions started:' sessions.each do |session| puts "#{session}" settings = parse_settings(read("#{tmuxinator_root}/#{session}.yml")) tmuxinator_command(session, settings) end end |
#tmuxinator_command(session, settings) ⇒ Object
41 42 43 |
# File 'lib/nerdinator/config.rb', line 41 def tmuxinator_command(session, settings) %x[tmuxinator start #{session} #{settings}] end |
#tmuxinator_root ⇒ Object
7 8 9 |
# File 'lib/nerdinator/config.rb', line 7 def tmuxinator_root File.("#{ENV['HOME']}/.tmuxinator") end |
#write(data) ⇒ Object
29 30 31 32 33 |
# File 'lib/nerdinator/config.rb', line 29 def write(data) File.open(root, 'w+') do |f| YAML.dump(data, f) end end |