Class: TplinkCli::Configuration
- Inherits:
-
Object
- Object
- TplinkCli::Configuration
- Defined in:
- lib/tplink-cli/configuration.rb
Constant Summary collapse
- CONFIG_FILE =
"#{ENV['HOME']}/.tplinkcli"
Instance Attribute Summary collapse
-
#hostname_length ⇒ Object
Returns the value of attribute hostname_length.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#password ⇒ Object
Returns the value of attribute password.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#hostname_length ⇒ Object
Returns the value of attribute hostname_length.
6 7 8 |
# File 'lib/tplink-cli/configuration.rb', line 6 def hostname_length @hostname_length end |
#hosts ⇒ Object
Returns the value of attribute hosts.
7 8 9 |
# File 'lib/tplink-cli/configuration.rb', line 7 def hosts @hosts end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/tplink-cli/configuration.rb', line 5 def password @password end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/tplink-cli/configuration.rb', line 4 def url @url end |
Class Method Details
.instance ⇒ Object
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_yml ⇒ Object
22 23 24 |
# File 'lib/tplink-cli/configuration.rb', line 22 def self.load_yml YAML.load_file(CONFIG_FILE) end |
.save ⇒ Object
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
#defaults ⇒ Object
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 |