Module: RHosts::ConsoleMethods

Included in:
Console
Defined in:
lib/rhosts/console/app.rb

Instance Method Summary collapse

Instance Method Details

#activesObject



5
6
7
# File 'lib/rhosts/console/app.rb', line 5

def actives
  @actives ||= Hash.new{ |h, k| h[k] = Set.new }
end

#display(title, mappings) ⇒ Object

print mappings



38
39
40
41
42
43
44
45
# File 'lib/rhosts/console/app.rb', line 38

def display(title, mappings)
  puts "### #{title}"
  mappings.each do |ip, hosts|
    puts ip
    hosts.each{ |host| puts "  #{host}" }
    puts ''
  end
end

#inactivesObject



9
10
11
# File 'lib/rhosts/console/app.rb', line 9

def inactives
  @inactives ||= Hash.new{ |h, k| h[k] = Set.new }
end

#map(target) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rhosts/console/app.rb', line 13

def map(target)
  process(target) do |host, ip|
    unless inactives[ip].empty?
      inactives[ip].delete_if{ |h| h == host }
      inactives.delete(ip) if inactives[ip].empty?
    end

    actives[ip] << host
    puts "map #{host} to #{ip}"
  end
end

#unmap(target) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rhosts/console/app.rb', line 25

def unmap(target)
  process(target) do |host, ip|
    unless actives[ip].empty?
      actives[ip].delete_if{ |h| h == host }
      actives.delete(ip) if actives[ip].empty?
    end

    inactives[ip] << host
    puts "unmap #{host} from #{ip}"
  end
end