Class: Unbound::Query

Inherits:
Object
  • Object
show all
Includes:
CallbacksMixin
Defined in:
lib/unbound/query.rb

Overview

A representation of a query, as used by Unbound::Resolver

Constant Summary collapse

STATE_INIT =
0
STATE_STARTED =
1
STATE_FINISHED =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CallbacksMixin

#on_answer, #on_cancel, #on_error, #on_finish, #on_start

Constructor Details

#initialize(name, rrtype, rrclass) ⇒ Query

Returns a new instance of Query.

Parameters:

  • name (String)
  • rrtype (Integer)
  • rrclass (Integer)


16
17
18
19
20
21
22
23
24
# File 'lib/unbound/query.rb', line 16

def initialize(name, rrtype, rrclass)
  @name = name
  @rrtype = rrtype
  @rrclass = rrclass
  @async_id = nil

  @state = STATE_INIT
  init_callbacks
end

Instance Attribute Details

#async_idObject (readonly)

Returns the value of attribute async_id.



7
8
9
# File 'lib/unbound/query.rb', line 7

def async_id
  @async_id
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/unbound/query.rb', line 7

def name
  @name
end

#rrclassObject (readonly)

Returns the value of attribute rrclass.



7
8
9
# File 'lib/unbound/query.rb', line 7

def rrclass
  @rrclass
end

#rrtypeObject (readonly)

Returns the value of attribute rrtype.



7
8
9
# File 'lib/unbound/query.rb', line 7

def rrtype
  @rrtype
end

Instance Method Details

#answer!(result) ⇒ Object

Called by the resolver when it has received an answer

Parameters:



47
48
49
50
# File 'lib/unbound/query.rb', line 47

def answer!(result)
  @callbacks_answer.call(self, result)
  finish!()
end

#cancel!Object

Called by the resolver after a cancel has occurred.



60
61
62
63
# File 'lib/unbound/query.rb', line 60

def cancel!()
  @callbacks_cancel.call(self)
  finish!()
end

#error!(error_code) ⇒ Object

Called by the resolver when it has encountered an internal unbound error

Parameters:

  • error_code (Unbound::Bindings::error_codes)


54
55
56
57
# File 'lib/unbound/query.rb', line 54

def error!(error_code)
  @callbacks_error.call(self, error_code)
  finish!()
end

#finished?Boolean

Returns whether the query has finished or not.

Returns:

  • (Boolean)

    whether the query has finished or not



27
28
29
# File 'lib/unbound/query.rb', line 27

def finished?
  @state >= STATE_FINISHED
end

#start!(async_id) ⇒ Object

Called by the resolver just after it has sent the query, and received an asynchronous ID.



38
39
40
41
42
43
# File 'lib/unbound/query.rb', line 38

def start!(async_id)
  @state = STATE_STARTED
  @async_id = async_id
  @callbacks_start.call(self)
  @callbacks_start.clear
end

#started?Boolean

Returns whether the query has been started or not.

Returns:

  • (Boolean)

    whether the query has been started or not



32
33
34
# File 'lib/unbound/query.rb', line 32

def started?
  @state >= STATE_STARTED
end