Class: HostList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/host_list.rb

Class Method Summary collapse

Class Method Details

.add(host, ip) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/host_list.rb', line 28

def add(host, ip)
  begin
    Host.add(host, ip)
    set_entry(host,ip)
  rescue => e
    puts "Error adding entry: #{e}"
  end
end

.applyObject



52
53
54
55
56
57
58
59
# File 'lib/host_list.rb', line 52

def apply
  each do |host, ip|
    if Host.find_by_host(host)
      Host.delete(host)
    end
    Host.add(host, ip)
  end
end

.config_file=(path) ⇒ Object



8
9
10
# File 'lib/host_list.rb', line 8

def config_file=(path)
  @@config_file = path
end

.eachObject



12
13
14
15
16
17
# File 'lib/host_list.rb', line 12

def each
  read_entries
  @@entries.each do |host|
    yield host
  end
end

.has_entries?Boolean

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/host_list.rb', line 67

def has_entries?
  read_entries
  @@entries.size > 0
end

.remove(host) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/host_list.rb', line 43

def remove(host)
  begin
    Host.delete(host)
    set_entry(host)
  rescue => e
    puts "Error removing entry: #{e}"
  end
end

.set_entry(host, ip = nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/host_list.rb', line 19

def set_entry(host, ip = nil)
  if ip
    @@entries[host.strip] = ip.strip
  else
    @@entries.delete(host.strip)
  end
  save_entries
end

.unapplyObject



61
62
63
64
65
# File 'lib/host_list.rb', line 61

def unapply
  each do |host, ip|
    Host.delete(host) if Host.find_by_host(host)
  end
end

.update(host, ip) ⇒ Object



37
38
39
40
41
# File 'lib/host_list.rb', line 37

def update(host, ip)
  Host.delete(host)
  Host.add(host,ip)
  set_entry(host,ip)
end