Class: Unbound::Query
- Inherits:
-
Object
- Object
- Unbound::Query
- 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
-
#async_id ⇒ Object
readonly
Returns the value of attribute async_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rrclass ⇒ Object
readonly
Returns the value of attribute rrclass.
-
#rrtype ⇒ Object
readonly
Returns the value of attribute rrtype.
Instance Method Summary collapse
-
#answer!(result) ⇒ Object
Called by the resolver when it has received an answer.
-
#cancel! ⇒ Object
Called by the resolver after a cancel has occurred.
-
#error!(error_code) ⇒ Object
Called by the resolver when it has encountered an internal unbound error.
-
#finished? ⇒ Boolean
Whether the query has finished or not.
-
#initialize(name, rrtype, rrclass) ⇒ Query
constructor
A new instance of Query.
-
#start!(async_id) ⇒ Object
Called by the resolver just after it has sent the query, and received an asynchronous ID.
-
#started? ⇒ Boolean
Whether the query has been started or not.
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.
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_id ⇒ Object (readonly)
Returns the value of attribute async_id.
7 8 9 |
# File 'lib/unbound/query.rb', line 7 def async_id @async_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/unbound/query.rb', line 7 def name @name end |
#rrclass ⇒ Object (readonly)
Returns the value of attribute rrclass.
7 8 9 |
# File 'lib/unbound/query.rb', line 7 def rrclass @rrclass end |
#rrtype ⇒ Object (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
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
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.
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.
32 33 34 |
# File 'lib/unbound/query.rb', line 32 def started? @state >= STATE_STARTED end |