Sha256: f4edeaee8b931ea1fa3e59c8683b1d34212581d9763bcab76f3300e10a299a0c

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

class Cronicle::DSL::Context
  class << self
    def eval(dsl, path, opts = {})
      self.new(path, opts) {
        Kernel.eval(dsl, binding, path)
      }
    end
  end # of class methods

  attr_reader :result

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

  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

  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)

    @result.concat(Cronicle::DSL::Context::Job.new(target, &block).result.values)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cronicle-0.1.4 lib/cronicle/dsl/context.rb
cronicle-0.1.3 lib/cronicle/dsl/context.rb
cronicle-0.1.2 lib/cronicle/dsl/context.rb
cronicle-0.1.1 lib/cronicle/dsl/context.rb
cronicle-0.1.0 lib/cronicle/dsl/context.rb