Class: SSHTunnel::UI::Models::Config
- Inherits:
-
Object
- Object
- SSHTunnel::UI::Models::Config
- Defined in:
- lib/ssh-hull/ui/models/config.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
Instance Method Summary collapse
- #add_host(host) ⇒ Object
-
#initialize(file) ⇒ Config
constructor
A new instance of Config.
- #load! ⇒ Object
- #remove_host(host) ⇒ Object
- #save! ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(file) ⇒ Config
Returns a new instance of Config.
11 12 13 14 |
# File 'lib/ssh-hull/ui/models/config.rb', line 11 def initialize(file) @file = file load! end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/ssh-hull/ui/models/config.rb', line 8 def data @data end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/ssh-hull/ui/models/config.rb', line 8 def file @file end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
8 9 10 |
# File 'lib/ssh-hull/ui/models/config.rb', line 8 def hosts @hosts end |
Instance Method Details
#add_host(host) ⇒ Object
23 24 25 |
# File 'lib/ssh-hull/ui/models/config.rb', line 23 def add_host(host) @hosts << host end |
#load! ⇒ Object
17 18 19 20 |
# File 'lib/ssh-hull/ui/models/config.rb', line 17 def load! @data = load_json_file(file) @hosts = load_hosts end |
#remove_host(host) ⇒ Object
28 29 30 |
# File 'lib/ssh-hull/ui/models/config.rb', line 28 def remove_host(host) @hosts.delete(host) end |
#save! ⇒ Object
33 34 35 |
# File 'lib/ssh-hull/ui/models/config.rb', line 33 def save! write_yaml_file(file, to_hash) end |
#to_hash ⇒ Object
38 39 40 |
# File 'lib/ssh-hull/ui/models/config.rb', line 38 def to_hash marshal_dump(hosts: hosts.sort_by(&:name).map(&:to_hash)) end |