Class: Change

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

Direct Known Subclasses

Alteration, Definition

Defined Under Namespace

Classes: DatabaseError

Constant Summary collapse

SPLIT_MARKER =
'---- CREATE above / DROP below ----'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#create_sqlObject (readonly)

Returns the value of attribute create_sql.



36
37
38
# File 'lib/tern.rb', line 36

def create_sql
  @create_sql
end

#drop_sqlObject (readonly)

Returns the value of attribute drop_sql.



37
38
39
# File 'lib/tern.rb', line 37

def drop_sql
  @drop_sql
end

#nameObject (readonly)

Returns the value of attribute name.



38
39
40
# File 'lib/tern.rb', line 38

def name
  @name
end

Class Method Details

.parse(string) ⇒ Object



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

def self.parse(string)
  create_sql, drop_sql = Parser.new.render_text(string).split(SPLIT_MARKER)
  [create_sql, drop_sql]
end

Instance Method Details

#run(sql, context) ⇒ Object



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

def run(sql, context)
  DB.run sql
rescue Sequel::DatabaseError
  raise DatabaseError, "Error in #{context}\n#{$!.to_s}"
end