Class: Handle::Command::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/handle/command/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(handle, index, *auth, &block) ⇒ Connection

Returns a new instance of Connection.



60
61
62
63
64
65
66
67
# File 'lib/handle/command/connection.rb', line 60

def initialize(handle, index, *auth, &block)
  @handle = handle
  @index  = index
  @auth_params = auth
  if block_given?
    batch &block
  end
end

Instance Method Details

#add_handle_values(*args) ⇒ Object



80
81
82
# File 'lib/handle/command/connection.rb', line 80

def add_handle_values(*args)
  batch { |b| b.add_handle_values(*args) }
end

#batchObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/handle/command/connection.rb', line 69

def batch
  context = Batch.new(@handle, @index, @auth_params)
  begin
    yield context
    result = context.execute!
  ensure
    context.cleanup
  end
  result
end

#create_handle(*args) ⇒ Object



84
85
86
# File 'lib/handle/command/connection.rb', line 84

def create_handle(*args)
  batch { |b| b.create_handle(*args) }
end

#create_record(handle) ⇒ Object



100
101
102
103
104
105
# File 'lib/handle/command/connection.rb', line 100

def create_record(handle)
  result = Handle::Record.new
  result.connection = self
  result.handle = handle
  result
end

#delete_handle(*args) ⇒ Object



88
89
90
# File 'lib/handle/command/connection.rb', line 88

def delete_handle(*args)
  batch { |b| b.delete_handle(*args) }
end

#delete_handle_values(*args) ⇒ Object



92
93
94
# File 'lib/handle/command/connection.rb', line 92

def delete_handle_values(*args)
  batch { |b| b.delete_handle_values(*args) }
end

#resolve_handle(handle, types = [], indexes = [], auth = true) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/handle/command/connection.rb', line 107

def resolve_handle(handle, types=[], indexes=[], auth=true)
  cmd = File.join(Handle::HOME, 'bin', 'hdl-qresolver')
  response = `#{cmd} #{handle} 2>&1`.strip
  if response =~ /^Got Response:/
    response = response.lines.select { |line| line =~ /^\s*index=/ }.join("")
    result = Handle::Record.from_data(response)
    result.connection = self
    result.handle = handle
    result
  else
    (code, message) = response.scan(/Error\(([0-9]+)\): (.+)$/).last
    exception_klass = case code.to_i
    when 100 then Handle::NotFound
    else          Handle::HandleError
    end
    exception = exception_klass.new message
    exception.set_backtrace(caller)
    raise exception
  end
end

#update_handle_values(*args) ⇒ Object



96
97
98
# File 'lib/handle/command/connection.rb', line 96

def update_handle_values(*args)
  batch { |b| b.update_handle_values(*args) }
end