Class: Net::Openvpn::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/net/openvpn/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Server

Returns a new instance of Server.



5
6
7
8
# File 'lib/net/openvpn/server.rb', line 5

def initialize(name)
  @name = name
  load if exists?
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/net/openvpn/server.rb', line 26

def exists?
  File.exists? path
end

#get(key) ⇒ Object



14
15
16
# File 'lib/net/openvpn/server.rb', line 14

def get(key)
  @config[key]
end

#loadObject



10
11
12
# File 'lib/net/openvpn/server.rb', line 10

def load
  @config = Net::Openvpn::Parser::ServerConfig.parse(File.read(path))
end

#pathObject



22
23
24
# File 'lib/net/openvpn/server.rb', line 22

def path
  Net::Openvpn.basepath "#{@name}.conf"
end

#saveObject



30
31
32
33
34
35
# File 'lib/net/openvpn/server.rb', line 30

def save
  text = Net::Openvpn::Parser::ServerConfig.generate(@config)
  File.open(path, "w") do |f|
    f.puts text
  end
end

#set(key, value) ⇒ Object



18
19
20
# File 'lib/net/openvpn/server.rb', line 18

def set(key, value)
  @config[key] = value
end