Sha256: 275e9fa19ed865eac2428350469fd23a1e2af5c2fa7ea315cd209f29778d23ed
Contents?: true
Size: 1.3 KB
Versions: 11
Compression:
Stored size: 1.3 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) 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 end
Version data entries
11 entries across 11 versions & 1 rubygems