Module: RHosts::ConsoleMethods

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

Instance Method Summary collapse

Instance Method Details

#activesObject



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

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

#display(title, mappings) ⇒ Object

print mappings



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

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

#inactivesObject



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

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

#map(target) ⇒ Object



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

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



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

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