Class: Tunnel::Configfile

Inherits:
Object
  • Object
show all
Defined in:
lib/tunnel/configfile.rb

Class Method Summary collapse

Class Method Details

.add(config) ⇒ Object



19
20
21
22
# File 'lib/tunnel/configfile.rb', line 19

def add(config)
  configs.push(config)
  save
end

.config_exists?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/tunnel/configfile.rb', line 30

def config_exists?
  File.exist?(configfile)
end

.configfileObject



34
35
36
# File 'lib/tunnel/configfile.rb', line 34

def configfile
  File.expand_path("~/.tunnel")
end

.configsObject



5
6
7
# File 'lib/tunnel/configfile.rb', line 5

def configs
  @configs ||= ( load_from_file || [] )
end

.load_from_fileObject



9
10
11
12
13
14
15
16
17
# File 'lib/tunnel/configfile.rb', line 9

def load_from_file
  return false unless config_exists?

  if result = YAML.load_file(configfile)
    result.map { |c| Config.new(c) }
  else
    puts "Your tunnel config (~/.tunnel) is not valid yaml"
  end
end

.saveObject



24
25
26
27
28
# File 'lib/tunnel/configfile.rb', line 24

def save
  File.open(configfile, "w+") do |f|
    f.puts YAML.dump( configs.sort_by { |c| c.name } )
  end
end