Class: DbCompile::View
Instance Attribute Summary
Attributes inherited from Construct
#dependencies, #name, #path, #root_path
Instance Method Summary collapse
Methods inherited from Construct
#does_one_exist?, #execute, #initialize
Constructor Details
This class inherits a constructor from DbCompile::Construct
Instance Method Details
#build_path ⇒ Object
3 4 5 |
# File 'lib/dbcompile/view.rb', line 3 def build_path @path = File.join('views', "#{name}.sql") end |
#source ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/dbcompile/view.rb', line 7 def source case ActiveRecord::Base.connection.class.to_s when "ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter" "CREATE OR REPLACE VIEW #{name} AS #{super}" else "DROP VIEW IF EXISTS #{name} CASCADE; CREATE VIEW #{name} AS #{super}" end end |
#verify ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dbcompile/view.rb', line 16 def verify sql = nil case ActiveRecord::Base.connection.class.to_s when 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' sql = "SELECT viewname FROM pg_catalog.pg_views WHERE viewname = '#{name}'" when "ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter" sql = "SELECT lower(view_name) FROM user_views WHERE lower(view_name) = lower('#{name}')" else raise "data dictionary query for adapter #{ActiveRecord::Base.connection.class.to_s} not defined" end require 'ckuru-tools' ckebug 0, sql return does_one_exist?(sql) end |