Class: TplinkAdmin::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/tplink-admin/configuration.rb

Constant Summary collapse

CONFIG_FILE =
"#{ENV['HOME']}/.tplinkadmin"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostname_lengthObject

Returns the value of attribute hostname_length.



7
8
9
# File 'lib/tplink-admin/configuration.rb', line 7

def hostname_length
  @hostname_length
end

#hostsObject

Returns the value of attribute hosts.



8
9
10
# File 'lib/tplink-admin/configuration.rb', line 8

def hosts
  @hosts
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/tplink-admin/configuration.rb', line 6

def password
  @password
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/tplink-admin/configuration.rb', line 4

def url
  @url
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/tplink-admin/configuration.rb', line 5

def username
  @username
end

Class Method Details

.instanceObject



20
21
22
# File 'lib/tplink-admin/configuration.rb', line 20

def self.instance
  @instance ||= File.exists?(CONFIG_FILE) ? load_yml() : new.tap(&:defaults)
end

.load_ymlObject



24
25
26
# File 'lib/tplink-admin/configuration.rb', line 24

def self.load_yml
  YAML.load_file(CONFIG_FILE)
end

.saveObject



28
29
30
# File 'lib/tplink-admin/configuration.rb', line 28

def self.save
  File.open(CONFIG_FILE, 'w+') { |f| f.write(instance.to_yaml) }
end

Instance Method Details

#defaultsObject



12
13
14
15
16
17
18
# File 'lib/tplink-admin/configuration.rb', line 12

def defaults
  self.hosts ||= {}
  self.hostname_length ||= 16
  self.username ||= 'admin'
  self.password ||= 'admin'
  self.url ||= '192.168.0.1'
end