Class: Cassie::Support::StatementParser

Inherits:
Object
  • Object
show all
Defined in:
lib/cassie/support/statement_parser.rb

Constant Summary collapse

QUOTED_TYPES =
[:date, :time, :text, :timestamp, :inet, :ascii].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statement) ⇒ StatementParser

Returns a new instance of StatementParser.



7
8
9
# File 'lib/cassie/support/statement_parser.rb', line 7

def initialize(statement)
  @statement = statement
end

Instance Attribute Details

#statementObject (readonly)

Returns the value of attribute statement.



5
6
7
# File 'lib/cassie/support/statement_parser.rb', line 5

def statement
  @statement
end

Instance Method Details

#bound_cqlObject



11
12
13
# File 'lib/cassie/support/statement_parser.rb', line 11

def bound_cql
  statement.cql
end

#paramsObject



15
16
17
# File 'lib/cassie/support/statement_parser.rb', line 15

def params
  statement.params
end

#params_typesObject



19
20
21
# File 'lib/cassie/support/statement_parser.rb', line 19

def params_types
  statement.params_types
end

#to_cqlObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cassie/support/statement_parser.rb', line 23

def to_cql
  cql = bound_cql.dup

  params_types.map.with_index do |type, i|
    cassandra_param = type.new(params[i])
    quoted_val = if QUOTED_TYPES.include? type.kind
      "'#{cassandra_param}'"
    else
      cassandra_param.to_s
    end

    cql.sub!("?", quoted_val)
  end
  cql
end