Class: DataSet
Overview
A collection of data that can be inserted together into a database
Defined Under Namespace
Classes: DataPiece
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#downs ⇒ Object
Returns the value of attribute downs.
-
#ups ⇒ Object
Returns the value of attribute ups.
Instance Method Summary collapse
-
#delete ⇒ Object
Executes the SQL scripts marked as reset scripts.
-
#initialize(directory, user_config = {}) ⇒ DataSet
constructor
Creates a dataset using the SQL and the configuration contained in directory.
-
#load ⇒ Object
Executes the SQL scripts associated with the dataset.
-
#reset ⇒ Object
If there are reset scripts available, executes them before executing once again the regular scripts.
- #to_s ⇒ Object
Methods included from DBConfig
#get_config_path, #load_config
Methods included from DB
Constructor Details
#initialize(directory, user_config = {}) ⇒ DataSet
Creates a dataset using the SQL and the configuration contained in directory. The supplied user configuration overrides the configuration contained in the directory
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sqlloader.rb', line 27 def initialize(directory, user_config = {}) @ups = [] @downs = [] @directory = directory populate() @config = load_config(directory).merge(user_config) if insufficient(config) raise ArgumentError, 'No database name' end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
21 22 23 |
# File 'lib/sqlloader.rb', line 21 def config @config end |
#directory ⇒ Object
Returns the value of attribute directory.
21 22 23 |
# File 'lib/sqlloader.rb', line 21 def directory @directory end |
#downs ⇒ Object
Returns the value of attribute downs.
21 22 23 |
# File 'lib/sqlloader.rb', line 21 def downs @downs end |
#ups ⇒ Object
Returns the value of attribute ups.
21 22 23 |
# File 'lib/sqlloader.rb', line 21 def ups @ups end |
Instance Method Details
#delete ⇒ Object
Executes the SQL scripts marked as reset scripts
62 63 64 65 66 67 68 69 |
# File 'lib/sqlloader.rb', line 62 def delete get_db_connection(@config) do |db_connection| @downs.each do |s| result = db_connection.exec(s.statement) puts "#{s.filename}: #{result.cmd_status}" end end end |
#load ⇒ Object
Executes the SQL scripts associated with the dataset.
51 52 53 54 55 56 57 58 |
# File 'lib/sqlloader.rb', line 51 def load get_db_connection(@config) do |db_connection| @ups.each do |s| result = db_connection.exec(s.statement) puts "#{s.filename}: #{result.cmd_status}" end end end |
#reset ⇒ Object
If there are reset scripts available, executes them before executing once again the regular scripts
41 42 43 44 45 46 47 |
# File 'lib/sqlloader.rb', line 41 def reset if @downs.empty? raise ArgumentError, 'There are no reset scripts to run' end delete load end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/sqlloader.rb', line 71 def to_s File.basename(@directory) end |