class Posgra::DSL::Database

Attributes

result[R]

Public Class Methods

eval(dsl, path, options = {}) click to toggle source
# File lib/posgra/dsl/database.rb, line 6
def self.eval(dsl, path, options = {})
  self.new(path, options) do
    eval(dsl, binding, path)
  end
end
new(path, options = {}, &block) click to toggle source
# File lib/posgra/dsl/database.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

Private Instance Methods

require(file) click to toggle source
# File lib/posgra/dsl/database.rb, line 34
def require(file)
  pgrantfile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@path), file))

  if File.exist?(pgrantfile)
    instance_eval(File.read(pgrantfile), pgrantfile)
  elsif File.exist?(pgrantfile + '.rb')
    instance_eval(File.read(pgrantfile + '.rb'), pgrantfile + '.rb')
  else
    Kernel.require(file)
  end
end
role(name, &block) click to toggle source
# File lib/posgra/dsl/database.rb, line 46
def role(name, &block)
  name = name.to_s

  if matched?(name, @options[:include_role], @options[:exclude_role])
    @result[name] = Posgra::DSL::Database::Role.new(@context, name, @options, &block).result
  end
end
template(name, &block) click to toggle source
# File lib/posgra/dsl/database.rb, line 30
def template(name, &block)
  @context.templates[name.to_s] = block
end