Class: Patch::Hub

Inherits:
Object
  • Object
show all
Defined in:
lib/patch/hub.rb

Overview

The main application object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Hub

Returns a new instance of Hub.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :log (IO)
  • :patches (Array<Patch>)


11
12
13
14
# File 'lib/patch/hub.rb', line 11

def initialize(options = {})
  @log = Log.new(options[:log]) unless options[:log].nil?
  populate_patches(options[:patches] || options[:patch])
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



6
7
8
# File 'lib/patch/hub.rb', line 6

def log
  @log
end

#patchesObject (readonly)

Returns the value of attribute patches.



6
7
8
# File 'lib/patch/hub.rb', line 6

def patches
  @patches
end

Instance Method Details

#ipsArray<String>

Collected IP addresses for the nodes

Returns:

  • (Array<String>)


18
19
20
21
22
# File 'lib/patch/hub.rb', line 18

def ips
  regex = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/
  all_ips = Socket.ip_address_list.map(&:inspect_sockaddr)
  all_ips.select { |ip| !!ip.match(regex) }
end

#listen(options = {}) ⇒ Hub

Start the hub

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :background (Boolean)

    Run in a background thread (default: false)

Returns:

  • (Hub)

    self



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

def listen(options = {})
  begin
    enable_nodes
    @thread.join unless !!options[:background]
    self
  rescue SystemExit, Interrupt => exception
    exit 0
  end
end

#nodesNode::Container

All of the nodes used by the patches

Returns:



40
41
42
43
# File 'lib/patch/hub.rb', line 40

def nodes
  nodes = @patches.map { |patch| patch.maps.map(&:nodes) }.flatten.compact.uniq
  Node::Container.new(nodes)
end