querier 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/querier.rb +11 -8
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b2d11506c653fd02680d9410d0e0bbb7b75f24b
4
- data.tar.gz: 6c5dd58c5c86529e66e4d8974ac2ebb0db6b69eb
3
+ metadata.gz: fb7c5d8fc4b623ae3b146c0bce71b98aa7738d9f
4
+ data.tar.gz: 1b369a793dfb45726ad8807a4dee7adae275ee0d
5
5
  SHA512:
6
- metadata.gz: 688be4a3c50af9a55923f8d33b3e7440c7f09db8b1dccfc9db1a04835304dbdf91e7848a234e2484cc15f6fb4ee89ee81446c2a2e371fb82d30130d9d4cdbe90
7
- data.tar.gz: c556a3a85323b67e81c729bf622016fdc637bfd7e7c1661067f18a70b07d855846f9dc35214c139c55560bb18d045cfcc2833520913f785a74e0c9960d764a1d
6
+ metadata.gz: 9b3722f19bd382dcb49dd28a289f2e8e7d66ca1546ff7e48da04f3bee3700012575afcde3ccc74a7a9f995b908525d7a2584b34240cd57e5b90649f4919e253b
7
+ data.tar.gz: 87421d0e984be779a1afcd7ed78766ffcfcba35d8f67da43bddf972a03ff8c374ebfbb2a8f2edc841a6f08957ef1d37724d7282ad700eec0125ad889c7045d0e
data/README.md CHANGED
@@ -19,4 +19,4 @@ WHERE
19
19
  end
20
20
  end
21
21
 
22
- # UserQuerier.new(user_name: foo, active: true).execute
22
+ # UserQuerier.new(user_name: 'foo', active: true).execute
data/lib/querier.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  class Querier
2
+
2
3
  PARAM_NAME_INDEX = 0
3
4
  PARAM_VALUE_INDEX = 1
5
+
4
6
  attr_reader :query_template, :query_params
5
7
 
6
8
  def initialize **template_query_params
@@ -8,7 +10,7 @@ class Querier
8
10
  end
9
11
 
10
12
  def execute
11
- ActiveRecord::Base.connection.select_all build_query(query_template: @query_template, query_params: @query_params)
13
+ ActiveRecord::Base.connection.select_all fill_query_params(query_template: @query_template, query_params: @query_params)
12
14
  end
13
15
 
14
16
  def structured_results
@@ -18,22 +20,23 @@ class Querier
18
20
  structured_results
19
21
  end
20
22
 
21
- def to_sanitized_sql
22
- to_sql.gsub(/\n/, ' ').gsub(/\t/, ' ')
23
- end
24
-
25
23
  def to_sql
26
- build_query(query_template: @query_template, query_params: @query_params)
24
+ fill_query_params(query_template: @query_template, query_params: @query_params)
27
25
  end
28
26
 
29
27
  private
30
28
 
31
- def build_query query_template:, query_params:
29
+ def get_param_value raw_query_param
30
+ # where's String#quote when we need it?
31
+ raw_query_param.class.eql?(String) ? "'#{raw_query_param.to_s}'" : raw_query_param.to_s
32
+ end
33
+
34
+ def fill_query_params query_template:, query_params:
32
35
  query = query_template.dup
33
36
 
34
37
  query_params.each do |query_param|
35
38
  query_param_name = query_param[PARAM_NAME_INDEX].to_s
36
- query_param_value = query_param[PARAM_VALUE_INDEX].class.eql?(String) ? "'#{query_param[PARAM_VALUE_INDEX].to_s}'" : query_param[PARAM_VALUE_INDEX].to_s
39
+ query_param_value = get_param_value(query_param[PARAM_VALUE_INDEX])
37
40
 
38
41
  query.gsub! /{\?#{query_param_name}}/, query_param_value
39
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: querier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias