Class: Albacore::Sql::SqlTask
- Inherits:
-
Object
- Object
- Albacore::Sql::SqlTask
- Includes:
- Logging
- Defined in:
- lib/albacore/task_types/sql_cmd.rb
Overview
a task that handles the execution of sql scripts.
Instance Method Summary collapse
- #execute ⇒ Object
-
#execute_inner!(work_dir, script) ⇒ Object
execute, for each sql script.
-
#initialize(work_dir, opts) ⇒ SqlTask
constructor
A new instance of SqlTask.
- #path_to(path, work_dir) ⇒ Object
Methods included from Logging
#debug, #err, #error, #fatal, #info, #puts, #trace, #warn
Constructor Details
#initialize(work_dir, opts) ⇒ SqlTask
Returns a new instance of SqlTask.
95 96 97 98 99 100 101 102 |
# File 'lib/albacore/task_types/sql_cmd.rb', line 95 def initialize work_dir, opts raise ArgumentError, 'opts is not a map' unless opts.is_a? Map raise ArgumentError, 'no scripts given' unless opts.get(:scripts).length > 0 raise ArgumentError, 'no parameters given' unless opts.get(:parameters).length > 0 @opts = opts.apply :work_dir => work_dir @scripts = opts.get :scripts end |
Instance Method Details
#execute ⇒ Object
104 105 106 107 108 |
# File 'lib/albacore/task_types/sql_cmd.rb', line 104 def execute @scripts.each do |s| execute_inner! @opts.get(:work_dir), s end end |
#execute_inner!(work_dir, script) ⇒ Object
execute, for each sql script
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/albacore/task_types/sql_cmd.rb', line 111 def execute_inner! work_dir, script exe = path_to(@opts.get(:exe), work_dir) parameters = @opts.get(:parameters) parameters.add("-i#{script.gsub('/','\\')}") cmd = Albacore::Sql::Cmd.new(work_dir, exe, parameters) cmd.execute fail "SqlCmd.exe is not installed.\nPlease download and install Microsoft SQL Server 2012 Command Line Utilities: https://www.microsoft.com/en-gb/download/confirmation.aspx?id=29065\nAnd add the location of SqlCmd.exe to the PATH system varible." unless exe end |
#path_to(path, work_dir) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/albacore/task_types/sql_cmd.rb', line 125 def path_to path, work_dir if (Pathname.new path).absolute? return path else return File.( File.join(@opts.get(:original_path), path), work_dir ) end end |