Class: Cql::Protocol::QueryRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/cql/protocol/requests/query_request.rb

Instance Attribute Summary collapse

Attributes inherited from Request

#opcode

Instance Method Summary collapse

Methods inherited from Request

#encode_frame

Methods included from Encoding

#write_bytes, #write_consistency, #write_decimal, #write_double, #write_float, #write_int, #write_long, #write_long_string, #write_short, #write_short_bytes, #write_string, #write_string_list, #write_string_map, #write_uuid, #write_varint

Constructor Details

#initialize(cql, consistency) ⇒ QueryRequest

Returns a new instance of QueryRequest.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
# File 'lib/cql/protocol/requests/query_request.rb', line 8

def initialize(cql, consistency)
  raise ArgumentError, %(No CQL given!) unless cql
  raise ArgumentError, %(No such consistency: #{consistency.inspect}) unless CONSISTENCIES.include?(consistency)
  super(7)
  @cql = cql
  @consistency = consistency
end

Instance Attribute Details

#consistencyObject (readonly)

Returns the value of attribute consistency.



6
7
8
# File 'lib/cql/protocol/requests/query_request.rb', line 6

def consistency
  @consistency
end

#cqlObject (readonly)

Returns the value of attribute cql.



6
7
8
# File 'lib/cql/protocol/requests/query_request.rb', line 6

def cql
  @cql
end

Instance Method Details

#eql?(rq) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


25
26
27
# File 'lib/cql/protocol/requests/query_request.rb', line 25

def eql?(rq)
  self.class === rq && rq.cql.eql?(self.cql) && rq.consistency.eql?(self.consistency)
end

#hashObject



30
31
32
# File 'lib/cql/protocol/requests/query_request.rb', line 30

def hash
  @h ||= (@cql.hash * 31) ^ consistency.hash
end

#to_sObject



21
22
23
# File 'lib/cql/protocol/requests/query_request.rb', line 21

def to_s
  %(QUERY "#@cql" #{@consistency.to_s.upcase})
end

#write(io) ⇒ Object



16
17
18
19
# File 'lib/cql/protocol/requests/query_request.rb', line 16

def write(io)
  write_long_string(io, @cql)
  write_consistency(io, @consistency)
end