Class: DbCompile::Construct
- Inherits:
-
Object
- Object
- DbCompile::Construct
- Defined in:
- lib/dbcompile/construct.rb
Overview
Anything that can be expressed in SQL
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#root_path ⇒ Object
Returns the value of attribute root_path.
Instance Method Summary collapse
-
#build_path ⇒ Object
Override this to set path the SQL source.
-
#does_one_exist?(sql) ⇒ Boolean
checks to see if one object exists based on the sql string generated by an individual construct.
-
#execute ⇒ Object
Execute the source to create contruct in database.
-
#initialize(name, root_path) ⇒ Construct
constructor
A new instance of Construct.
-
#source ⇒ Object
Return the SQL source.
-
#verify ⇒ Object
Override to verify the existence of the construct Return true for verified successs Return false for verified failure Return nil otherwise.
Constructor Details
#initialize(name, root_path) ⇒ Construct
Returns a new instance of Construct.
9 10 11 12 13 |
# File 'lib/dbcompile/construct.rb', line 9 def initialize(name, root_path) @name = name @root_path = root_path build_path end |
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
7 8 9 |
# File 'lib/dbcompile/construct.rb', line 7 def dependencies @dependencies end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/dbcompile/construct.rb', line 4 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/dbcompile/construct.rb', line 5 def path @path end |
#root_path ⇒ Object
Returns the value of attribute root_path.
6 7 8 |
# File 'lib/dbcompile/construct.rb', line 6 def root_path @root_path end |
Instance Method Details
#build_path ⇒ Object
Override this to set path the SQL source
16 17 |
# File 'lib/dbcompile/construct.rb', line 16 def build_path end |
#does_one_exist?(sql) ⇒ Boolean
checks to see if one object exists based on the sql string generated by an individual construct
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 ⇒ Object
Execute the source to create contruct in database
20 21 22 |
# File 'lib/dbcompile/construct.rb', line 20 def execute ActiveRecord::Base.connection.execute(source) end |
#source ⇒ Object
Return the SQL source. Do any magic wrapping here.
25 26 27 28 29 30 |
# 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 ⇒ Object
Override to verify the existence of the construct Return true for verified successs Return false for verified failure Return nil otherwise
36 37 |
# File 'lib/dbcompile/construct.rb', line 36 def verify end |