Class: SqlQueryExecutor::Query::Normalizers::QueryNormalizer

Inherits:
BaseNormalizer
  • Object
show all
Defined in:
lib/sql_query_executor/query/normalizers/query_normalizer.rb

Constant Summary collapse

CONVERT_METHODS =
{"String" => "get_query", "Array" => "interpolate_query", "Hash" => "convert_hash"}

Class Method Summary collapse

Class Method Details

.attributes_from_query(query) ⇒ Object



23
24
25
26
27
# File 'lib/sql_query_executor/query/normalizers/query_normalizer.rb', line 23

def self.attributes_from_query(query)
  return {} if query.empty?
  selector = query.class == Hash ? query : Base.new(query).selector
  super(selector)
end

.clean_query(query) ⇒ Object



19
20
21
# File 'lib/sql_query_executor/query/normalizers/query_normalizer.rb', line 19

def self.clean_query(query)
  remove_placeholders execute(query).gsub('!=', '<>')
end

.execute(query) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/sql_query_executor/query/normalizers/query_normalizer.rb', line 11

def self.execute(query)
  query = clean_query_attribute(query)
  method = CONVERT_METHODS[query.class.name]


  query = sanitize(send(method, query))
end