Class: Tunnel::Configfile
- Inherits:
-
Object
- Object
- Tunnel::Configfile
- Defined in:
- lib/tunnel/configfile.rb
Class Method Summary collapse
- .add(config) ⇒ Object
- .config_exists? ⇒ Boolean
- .configfile ⇒ Object
- .configs ⇒ Object
- .load_from_file ⇒ Object
- .save ⇒ Object
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
30 31 32 |
# File 'lib/tunnel/configfile.rb', line 30 def config_exists? File.exist?(configfile) end |
.configfile ⇒ Object
34 35 36 |
# File 'lib/tunnel/configfile.rb', line 34 def configfile File.("~/.tunnel") end |
.configs ⇒ Object
5 6 7 |
# File 'lib/tunnel/configfile.rb', line 5 def configs @configs ||= ( load_from_file || [] ) end |
.load_from_file ⇒ Object
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 |
.save ⇒ Object
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 |