class Bow::Targets

Attributes

file[RW]
group[RW]
groups[R]
user[RW]

Public Class Methods

new(file, user = 'root') click to toggle source
# File lib/bow/targets.rb, line 13
def initialize(file, user = 'root')
  @file = file
  @hosts = { all: Set.new }
  @user = user
  @groups = []
end

Public Instance Methods

hosts(group = :all) { |h| ... } click to toggle source
# File lib/bow/targets.rb, line 20
def hosts(group = :all)
  parse
  group = group.to_sym
  return @hosts[group] unless block_given?
  @hosts[group.to_sym].each { |h| yield(h) }
end
parse() click to toggle source
# File lib/bow/targets.rb, line 27
def parse
  return if @parsed
  raw_data.each do |group, hosts|
    parse_group(group, hosts)
  end
  @hosts[:all] = @hosts[:all].uniq
  @parsed = true
end

Private Instance Methods

build_host(group, host) click to toggle source
# File lib/bow/targets.rb, line 46
def build_host(group, host)
  Host.new(host, group, "#{@user}@#{host}")
end
parse_group(group, hosts) click to toggle source
# File lib/bow/targets.rb, line 38
def parse_group(group, hosts)
  group = group.to_sym
  hosts = hosts.uniq.map { |h| build_host(group, h) }
  @hosts[group] = Set.new hosts
  @hosts[:all] += hosts
  groups << group
end
raw_data() click to toggle source
# File lib/bow/targets.rb, line 50
def raw_data
  @raw_data ||= JSON.parse(File.read(@file))
end