Class: Bow::Targets

Inherits:
Object
  • Object
show all
Defined in:
lib/bow/targets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, user = 'root') ⇒ Targets

Returns a new instance of Targets.



13
14
15
16
17
18
# File 'lib/bow/targets.rb', line 13

def initialize(file, user = 'root')
  @file = file
  @hosts = { all: Set.new }
  @user = user
  @groups = []
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



11
12
13
# File 'lib/bow/targets.rb', line 11

def file
  @file
end

#groupObject

Returns the value of attribute group.



11
12
13
# File 'lib/bow/targets.rb', line 11

def group
  @group
end

#groupsObject (readonly)

Returns the value of attribute groups.



10
11
12
# File 'lib/bow/targets.rb', line 10

def groups
  @groups
end

#userObject

Returns the value of attribute user.



11
12
13
# File 'lib/bow/targets.rb', line 11

def user
  @user
end

Instance Method Details

#hosts(group = :all) ⇒ Object



20
21
22
23
24
25
# 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

#parseObject



27
28
29
30
31
32
33
34
# 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