class DbCompile::Construct
Anything that can be expressed in SQL
Attributes
dependencies[RW]
name[RW]
path[RW]
root_path[RW]
Public Class Methods
new(name, root_path)
click to toggle source
# File lib/dbcompile/construct.rb, line 9 def initialize(name, root_path) @name = name @root_path = root_path build_path end
Public Instance Methods
build_path()
click to toggle source
Override this to set path the SQL source
# File lib/dbcompile/construct.rb, line 16 def build_path end
does_one_exist?(sql)
click to toggle source
checks to see if one object exists based on the sql string generated by an individual construct
# File lib/dbcompile/construct.rb, line 43 def does_one_exist?(sql) result = ActiveRecord::Base.connection.execute(sql) case ActiveRecord::Base.connection.class.to_s when "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter" return result.num_tuples == 1 when "ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter" row_count= 0 while f = result.fetch row_count += 1 end return row_count == 1 else return result.length == 1 end end
execute()
click to toggle source
Execute the source to create contruct in database
# File lib/dbcompile/construct.rb, line 20 def execute ActiveRecord::Base.connection.execute(source) end
source()
click to toggle source
Return the SQL source. Do any magic wrapping here.
# File lib/dbcompile/construct.rb, line 25 def source f = File.open(File.join(root_path, path)) data = f.read f.close data end
verify()
click to toggle source
Override to verify the existence of the construct Return true for verified successs Return false for verified failure Return nil otherwise
# File lib/dbcompile/construct.rb, line 36 def verify end