Class: TplinkCli::Configuration

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostname_lengthObject

Returns the value of attribute hostname_length.



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

def hostname_length
  @hostname_length
end

#hostsObject

Returns the value of attribute hosts.



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

def hosts
  @hosts
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.instanceObject



18
19
20
# File 'lib/tplink-cli/configuration.rb', line 18

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

.load_ymlObject



22
23
24
# File 'lib/tplink-cli/configuration.rb', line 22

def self.load_yml
  YAML.load_file(CONFIG_FILE)
end

.saveObject



26
27
28
# File 'lib/tplink-cli/configuration.rb', line 26

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

Instance Method Details

#defaultsObject



11
12
13
14
15
16
# File 'lib/tplink-cli/configuration.rb', line 11

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