Class: PgBundle::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/pgbundle/dsl.rb

Overview

The Dsl class defines the Domain Specific Language for the PgFile it’s mainly user to parse a PgFile and return a Definition Object

Instance Method Summary collapse

Constructor Details

#initializeDsl

Returns a new instance of Dsl.



5
6
7
8
# File 'lib/pgbundle/dsl.rb', line 5

def initialize
  @definition = Definition.new
  @extensions = []
end

Instance Method Details

#database(*args) ⇒ Object



25
26
27
28
# File 'lib/pgbundle/dsl.rb', line 25

def database(*args)
  opts = extract_options!(args)
  @definition.database = Database.new(args.first, opts)
end

#eval_pgfile(pgfile, contents = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pgbundle/dsl.rb', line 10

def eval_pgfile(pgfile, contents=nil)
  contents ||= File.read(pgfile.to_s)
  instance_eval(contents)
  @definition
rescue SyntaxError => e
  syntax_msg = e.message.gsub("#{pgfile}:", 'on line ')
  raise PgfileError, "Pgfile syntax error #{syntax_msg}"
rescue ScriptError, RegexpError, NameError, ArgumentError => e
  e.backtrace[0] = "#{e.backtrace[0]}: #{e.message} (#{e.class})"
  puts e.backtrace.join("\n       ")
  raise PgfileError, "There was an error in your Pgfile," \
    " and pgbundle cannot continue. " \
    + e.message
end

#pgx(*args) ⇒ Object



30
31
32
33
34
# File 'lib/pgbundle/dsl.rb', line 30

def pgx(*args)
  opts = extract_options!(args)
  ext = Extension.new(*args, opts)
  @definition.extensions[ext.name] = ext
end