Class: SSHTunnel::UI::Models::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh-hull/ui/models/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/ssh-hull/ui/models/config.rb', line 8

def data
  @data
end

#fileObject (readonly)

Returns the value of attribute file.



8
9
10
# File 'lib/ssh-hull/ui/models/config.rb', line 8

def file
  @file
end

#hostsObject (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_hashObject



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