Class: Praegustator::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/praegustator/dsl.rb

Instance Method Summary collapse

Constructor Details

#initializeDsl

Returns a new instance of Dsl.



4
5
6
# File 'lib/praegustator/dsl.rb', line 4

def initialize
  @suits = []
end

Instance Method Details

#environment(name, &block) ⇒ Object



8
9
10
# File 'lib/praegustator/dsl.rb', line 8

def environment(name, &block)
  @environment = name
end

#ip(address, &block) ⇒ Object



21
22
23
# File 'lib/praegustator/dsl.rb', line 21

def ip(address, &block)
  search("ipaddress:#{address}",&block)
end

#parse_file(filename) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/praegustator/dsl.rb', line 33

def parse_file(filename)
  if File.exists?(filename) && File.readable?(filename)
    self.instance_eval(IO.read(filename), filename, 1)
  else
    raise IOError, "Cannot open or read #{filename}!"
  end
  @suits
end

#recipe(name, &block) ⇒ Object



16
17
18
19
# File 'lib/praegustator/dsl.rb', line 16

def recipe(name, &block)
  name = name.gsub(":","\\:")
  search("run_list:recipe\\[#{name}\\]",&block)
end

#role(name, &block) ⇒ Object



12
13
14
# File 'lib/praegustator/dsl.rb', line 12

def role(name, &block)
  search("role:#{name}",&block)
end

#search(query, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/praegustator/dsl.rb', line 25

def search(query, &block)
  query = "#{query} AND chef_environment:#{@environment}" if @environment
  suite = TestSuite.new(query)
  suite.instance_eval(&block)
  @suits << suite
  suite.nodes
end