Class: STConfig
- Inherits:
-
Object
- Object
- STConfig
- Defined in:
- lib/vapor/config.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add_server(handle, ip, port) ⇒ Object
-
#initialize ⇒ STConfig
constructor
A new instance of STConfig.
- #load ⇒ Object
- #lookup_server_by_handle(handle) ⇒ Object
- #rm_server(handle) ⇒ Object
- #set_user(me) ⇒ Object
Constructor Details
#initialize ⇒ STConfig
Returns a new instance of STConfig.
8 9 10 11 12 |
# File 'lib/vapor/config.rb', line 8 def initialize @dir = '.config/steamthing' @file = 'conf.yaml' @data = self.load end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/vapor/config.rb', line 4 def data @data end |
Instance Method Details
#add_server(handle, ip, port) ⇒ Object
38 39 40 41 42 |
# File 'lib/vapor/config.rb', line 38 def add_server(handle, ip, port) server = { 'handle' => handle, 'ip' => ip, 'port' => port } @data['servers'].push(server) @data.save end |
#load ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vapor/config.rb', line 16 def load conf = UserConfig.new(@dir) yaml = conf[@file] if yaml.empty? UserConfig.default(@file, { 'servers' => [ { 'handle' => 'rb1', 'ip' => '70.42.74.139', 'port' => 27015 }, { 'handle' => '2forttex', 'ip' => '216.144.255.162', 'port' => 27015 } ] }) conf.create(@file) yaml = conf[@file] end return yaml end |
#lookup_server_by_handle(handle) ⇒ Object
54 55 56 57 |
# File 'lib/vapor/config.rb', line 54 def lookup_server_by_handle(handle) server = @data['servers'].select { |s| handle == s['handle'] } return server[0] end |
#rm_server(handle) ⇒ Object
46 47 48 49 50 |
# File 'lib/vapor/config.rb', line 46 def rm_server(handle) @data['servers'] = @data['servers'].reject { |s| handle == s['handle'] } puts @data['servers'] @data.save end |
#set_user(me) ⇒ Object
61 62 63 64 |
# File 'lib/vapor/config.rb', line 61 def set_user(me) @data['me'] = me @data.save end |