Class: WORMY::DBConnection
- Inherits:
-
Object
- Object
- WORMY::DBConnection
- Defined in:
- lib/wormy/db_connection.rb
Instance Attribute Summary collapse
-
#db_file ⇒ Object
Returns the value of attribute db_file.
-
#seed_file ⇒ Object
Returns the value of attribute seed_file.
Class Method Summary collapse
- .execute(*args) ⇒ Object
- .execute2(*args) ⇒ Object
- .instance ⇒ Object
- .last_insert_row_id ⇒ Object
- .open(db_file_name) ⇒ Object
- .reset ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#db_file ⇒ Object
Returns the value of attribute db_file.
8 9 10 |
# File 'lib/wormy/db_connection.rb', line 8 def db_file @db_file end |
#seed_file ⇒ Object
Returns the value of attribute seed_file.
8 9 10 |
# File 'lib/wormy/db_connection.rb', line 8 def seed_file @seed_file end |
Class Method Details
.execute(*args) ⇒ Object
34 35 36 37 |
# File 'lib/wormy/db_connection.rb', line 34 def self.execute(*args) print_query(*args) instance.execute(*args) end |
.execute2(*args) ⇒ Object
39 40 41 42 |
# File 'lib/wormy/db_connection.rb', line 39 def self.execute2(*args) print_query(*args) instance.execute2(*args) end |
.instance ⇒ Object
28 29 30 31 32 |
# File 'lib/wormy/db_connection.rb', line 28 def self.instance reset if @db.nil? @db end |
.last_insert_row_id ⇒ Object
44 45 46 |
# File 'lib/wormy/db_connection.rb', line 44 def self.last_insert_row_id instance.last_insert_row_id end |
.open(db_file_name) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/wormy/db_connection.rb', line 10 def self.open(db_file_name) @db = SQLite3::Database.new(db_file_name) @db.results_as_hash = true @db.type_translation = true @db end |
.reset ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/wormy/db_connection.rb', line 18 def self.reset commands = [ "rm '#{DB_FILE}'", "cat '#{SQL_FILE}' | sqlite3 '#{DB_FILE}'" ] commands.each { |command| `#{command}` } DBConnection.open(DB_FILE) end |
Instance Method Details
#configure(seed_file, db_file) ⇒ Object
49 50 51 52 |
# File 'lib/wormy/db_connection.rb', line 49 def configure(seed_file, db_file) @seed_file = seed_file @db_file = db_file end |