class Repol::DSL::Context

Public Class Methods

eval(dsl, path, options = {}) click to toggle source
# File lib/repol/dsl/context.rb, line 4
def self.eval(dsl, path, options = {})
  self.new(path, options) {
    eval(dsl, binding, path)
  }
end
new(path, options = {}, &block) click to toggle source
# File lib/repol/dsl/context.rb, line 14
def initialize(path, options = {}, &block)
  @path = path
  @options = options
  @result = {}

  @context = Hashie::Mash.new(
    :path => path,
    :options => options,
    :templates => {}
  )

  instance_eval(&block)
end

Public Instance Methods

result() click to toggle source
# File lib/repol/dsl/context.rb, line 10
def result
  @result.sort_array!
end
template(name, &block) click to toggle source
# File lib/repol/dsl/context.rb, line 28
def template(name, &block)
  @context.templates[name.to_s] = block
end

Private Instance Methods

repository(name) { || ... } click to toggle source
# File lib/repol/dsl/context.rb, line 46
def repository(name)
  name = name.to_s

  if @result[name]
    raise "Repository `#{name}` is already defined"
  end

  @result[name] = yield
end
require(file) click to toggle source
# File lib/repol/dsl/context.rb, line 34
def require(file)
  repolfile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@path), file))

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