class Cronicle::DSL::Context

Attributes

result[R]

Public Class Methods

eval(dsl, path, opts = {}) click to toggle source
# File lib/cronicle/dsl/context.rb, line 3
def eval(dsl, path, opts = {})
  self.new(path, opts) {
    Kernel.eval(dsl, binding, path)
  }
end
new(path, options = {}, &block) click to toggle source
# File lib/cronicle/dsl/context.rb, line 12
def initialize(path, options = {}, &block)
  @path = path
  @options = options
  @result = []
  instance_eval(&block)
end

Public Instance Methods

on(target, &block) click to toggle source
# File lib/cronicle/dsl/context.rb, line 31
def on(target, &block)
  unless block
    raise ArgumentError, "Block is required for `on` method"
  end

  unless target.kind_of?(Hash)
    raise TypeError, "wrong argument type #{target.class} (expected Hash)"
  end

  if target.empty?
    raise ArgumentError, ':servers or :roles is not passed to `on` method'
  end

  target.assert_valid_keys(:servers, :roles)
  values = Cronicle::DSL::Context::Job.new(target, &block).result.values

  @result.concat(values.empty? ? [{
    :servers => Array(target[:servers]),
    :roles => Array(target[:roles]),
    :job => {}
  }] : values)
end
require(file) click to toggle source
# File lib/cronicle/dsl/context.rb, line 19
def require(file)
  cronfile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@path), file))

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