Class: Shadowsocks::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/shadowsocks/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_args) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
12
# File 'lib/shadowsocks/config.rb', line 7

def initialize(_args)
  @args = _args || []

  parse_args
  read_config
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/shadowsocks/config.rb', line 5

def args
  @args
end

#chnroutesObject (readonly)

Returns the value of attribute chnroutes.



5
6
7
# File 'lib/shadowsocks/config.rb', line 5

def chnroutes
  @chnroutes
end

#config_pathObject (readonly)

Returns the value of attribute config_path.



5
6
7
# File 'lib/shadowsocks/config.rb', line 5

def config_path
  @config_path
end

#local_portObject (readonly)

Returns the value of attribute local_port.



5
6
7
# File 'lib/shadowsocks/config.rb', line 5

def local_port
  @local_port
end

#methodObject (readonly)

Returns the value of attribute method.



5
6
7
# File 'lib/shadowsocks/config.rb', line 5

def method
  @method
end

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'lib/shadowsocks/config.rb', line 5

def password
  @password
end

#serverObject (readonly)

Returns the value of attribute server.



5
6
7
# File 'lib/shadowsocks/config.rb', line 5

def server
  @server
end

#server_portObject (readonly)

Returns the value of attribute server_port.



5
6
7
# File 'lib/shadowsocks/config.rb', line 5

def server_port
  @server_port
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



5
6
7
# File 'lib/shadowsocks/config.rb', line 5

def timeout
  @timeout
end

Instance Method Details

#read_configObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/shadowsocks/config.rb', line 14

def read_config
  @config_path = File.expand_path('../..', File.dirname(__FILE__)) + '/config.json' unless @config_path
  cfg_file = File.open @config_path
  json = JSON.parse cfg_file.read
  cfg_file.close

  @server       = json["server"]           if @server.nil?
  @password     = json["password"]         if @password.nil?
  @server_port  = json["server_port"].to_i if @server_port.nil?
  @local_port   = json["local_port"].to_i  if @local_port.nil?
  @timeout      = json["timeout"].to_i     if @timeout.nil?
  @method       = json["method"]           if @method.nil?
  @chnroutes    = json["chnroutes"]        if @chnroutes.nil?
end