Class: PgBundle::Dsl
- Inherits:
-
Object
- Object
- PgBundle::Dsl
- 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
- #database(*args) ⇒ Object
- #eval_pgfile(pgfile, contents = nil) ⇒ Object
-
#initialize ⇒ Dsl
constructor
A new instance of Dsl.
- #pgx(*args) ⇒ Object
Constructor Details
#initialize ⇒ Dsl
Returns a new instance of Dsl.
5 6 7 8 9 |
# File 'lib/pgbundle/dsl.rb', line 5 def initialize @definition = Definition.new @extensions = [] @databases = [] end |
Instance Method Details
#database(*args) ⇒ Object
26 27 28 29 |
# File 'lib/pgbundle/dsl.rb', line 26 def database(*args) opts = (args) @databases << Database.new(args.first, opts) end |
#eval_pgfile(pgfile, contents = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pgbundle/dsl.rb', line 11 def eval_pgfile(pgfile, contents=nil) contents ||= File.read(pgfile.to_s) instance_eval(contents) @databases.map{|d| df = @definition.clone; df.database = d; df} rescue SyntaxError => e syntax_msg = e..gsub("#{pgfile}:", 'on line ') raise PgfileError, "Pgfile syntax error #{syntax_msg}" rescue ScriptError, RegexpError, NameError, ArgumentError => e e.backtrace[0] = "#{e.backtrace[0]}: #{e.} (#{e.class})" puts e.backtrace.join("\n ") raise PgfileError, "There was an error in your Pgfile," \ " and pgbundle cannot continue. " \ + e. end |