Class: WatchList::DSL::Context

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

Defined Under Namespace

Classes: AlertContact, Monitor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}, &block) ⇒ Context

Returns a new instance of Context.



12
13
14
15
16
17
# File 'lib/watch_list/dsl/context.rb', line 12

def initialize(path, options = {}, &block)
  @path = path
  @options = options
  @result = {:monitors => {}, :alert_contacts => []}
  instance_eval(&block)
end

Instance Attribute Details

#resultObject (readonly)

of class methods



10
11
12
# File 'lib/watch_list/dsl/context.rb', line 10

def result
  @result
end

Class Method Details

.eval(dsl, path, opts = {}) ⇒ Object



3
4
5
6
7
# File 'lib/watch_list/dsl/context.rb', line 3

def eval(dsl, path, opts = {})
  self.new(path, opts) {
    Kernel.eval(dsl, binding, path)
  }
end

Instance Method Details

#alert_contact(&block) ⇒ Object



37
38
39
# File 'lib/watch_list/dsl/context.rb', line 37

def alert_contact(&block)
  @result[:alert_contacts] << WatchList::DSL::Context::AlertContact.new(&block).result
end

#monitor(name, &block) ⇒ Object



31
32
33
34
35
# File 'lib/watch_list/dsl/context.rb', line 31

def monitor(name, &block)
  raise 'Monitor: "friendlyname" is required' unless name
  raise "Monitor `#{name}` is already defined" if @result[:monitors][name]
  @result[:monitors][name] = WatchList::DSL::Context::Monitor.new(name, &block).result
end

#require(file) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/watch_list/dsl/context.rb', line 19

def require(file)
 robotfile = File.expand_path(File.join(File.dirname(@path), file))

  if File.exist?(robotfile)
    instance_eval(File.read(robotfile), robotfile)
  elsif File.exist?(robotfile + '.rb')
    instance_eval(File.read(robotfile + '.rb'), robotfile + '.rb')
  else
    Kernel.require(file)
  end
end