Class: Handle::Command::Batch
- Inherits:
-
Object
- Object
- Handle::Command::Batch
- Defined in:
- lib/handle/command/connection.rb
Instance Method Summary collapse
- #add_handle_values(handle, record) ⇒ Object
- #cleanup ⇒ Object
- #create_handle(handle, record) ⇒ Object
- #delete_handle(handle) ⇒ Object
- #delete_handle_values(handle, record) ⇒ Object
-
#execute! ⇒ Object
Raises an error if any part of the output is a “FAILURE” message.
-
#initialize(handle, index, auth) ⇒ Batch
constructor
A new instance of Batch.
- #update_handle_values(handle, record) ⇒ Object
Constructor Details
#initialize(handle, index, auth) ⇒ Batch
Returns a new instance of Batch.
6 7 8 9 10 11 |
# File 'lib/handle/command/connection.rb', line 6 def initialize(handle, index, auth) @batch_file = Tempfile.new('hdl') auth_type = auth.length == 2 ? "PUBKEY" : "SECKEY" @batch_file.puts "AUTHENTICATE #{auth_type}:#{index}:#{handle}" @batch_file.puts auth.select { |p| not (p.nil? or p.empty?) }.join('|') end |
Instance Method Details
#add_handle_values(handle, record) ⇒ Object
34 35 36 37 |
# File 'lib/handle/command/connection.rb', line 34 def add_handle_values(handle, record) @batch_file.puts "\nADD #{handle}" @batch_file.puts record.to_batch end |
#cleanup ⇒ Object
13 14 15 16 |
# File 'lib/handle/command/connection.rb', line 13 def cleanup @batch_file.close unless @batch_file.closed? @batch_file.unlink end |
#create_handle(handle, record) ⇒ Object
39 40 41 42 |
# File 'lib/handle/command/connection.rb', line 39 def create_handle(handle, record) @batch_file.puts "\nCREATE #{handle}" @batch_file.puts record.to_batch end |
#delete_handle(handle) ⇒ Object
44 45 46 |
# File 'lib/handle/command/connection.rb', line 44 def delete_handle(handle) @batch_file.puts "\nDELETE #{handle}" end |
#delete_handle_values(handle, record) ⇒ Object
48 49 50 51 |
# File 'lib/handle/command/connection.rb', line 48 def delete_handle_values(handle, record) indexes = record.collect(&:index).join(',') @batch_file.puts "\nREMOVE #{indexes}:#{handle}" end |
#execute! ⇒ Object
Raises an error if any part of the output is a “FAILURE” message
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/handle/command/connection.rb', line 19 def execute! @batch_file.close cmd = File.join(Handle::HOME, 'bin', 'hdl-genericbatch') output = `#{cmd} #{@batch_file.path} 2>/dev/null` results = output.lines.select { |line| line =~ /^=+>/ } results.each do |rs| if = ErrorParser.(rs) raise Handle::HandleError.new().tap { |exception| exception.set_backtrace(caller[3..-1]) } end end return true end |
#update_handle_values(handle, record) ⇒ Object
53 54 55 56 |
# File 'lib/handle/command/connection.rb', line 53 def update_handle_values(handle, record) @batch_file.puts "\nMODIFY #{handle}" @batch_file.puts record.to_batch end |