querier 0.0.1 → 0.0.2

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 +22 -1
  3. data/lib/querier.rb +4 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a7b74a9aa118493034f4b2827e147680a0fbe6a
4
- data.tar.gz: d041de66c3934471ad8a5cf0a5af60d49e3c1330
3
+ metadata.gz: 8b2d11506c653fd02680d9410d0e0bbb7b75f24b
4
+ data.tar.gz: 6c5dd58c5c86529e66e4d8974ac2ebb0db6b69eb
5
5
  SHA512:
6
- metadata.gz: 4e2a1928fe86c5b0ec1b3b1b3593154f4b8f0e8f37914f2d26a1a99886a9e6b04c5efeaef43728388f26b8197cffe1a6c5dd4c348b1b7623bab3a764d5e598bc
7
- data.tar.gz: 14b81752ca651fed3364d9a4ed9d3cbbd87173552d30e8e4b2ff1d70e1999d5b5977c67ce53aa1ddf89b7173798110eabc1d8c3de84af7ad20d82d98bda6aada
6
+ metadata.gz: 688be4a3c50af9a55923f8d33b3e7440c7f09db8b1dccfc9db1a04835304dbdf91e7848a234e2484cc15f6fb4ee89ee81446c2a2e371fb82d30130d9d4cdbe90
7
+ data.tar.gz: c556a3a85323b67e81c729bf622016fdc637bfd7e7c1661067f18a70b07d855846f9dc35214c139c55560bb18d045cfcc2833520913f785a74e0c9960d764a1d
data/README.md CHANGED
@@ -1 +1,22 @@
1
- # querier
1
+ # querier
2
+
3
+ # class UserQuerier < Querier
4
+ QUERY_TEMPLATE = <<-END_OF_QUERY_TEMPLATE
5
+
6
+ SELECT
7
+ *
8
+ FROM
9
+ users
10
+ WHERE
11
+ name = {?user_name}
12
+ AND active = {?active}
13
+
14
+ END_OF_QUERY_TEMPLATE
15
+
16
+ def initialize user_name:, active:
17
+ @query_template = QUERY_TEMPLATE
18
+ super
19
+ end
20
+ end
21
+
22
+ # UserQuerier.new(user_name: foo, active: true).execute
data/lib/querier.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  class Querier
2
+ PARAM_NAME_INDEX = 0
3
+ PARAM_VALUE_INDEX = 1
2
4
  attr_reader :query_template, :query_params
3
5
 
4
6
  def initialize **template_query_params
@@ -30,8 +32,8 @@ class Querier
30
32
  query = query_template.dup
31
33
 
32
34
  query_params.each do |query_param|
33
- query_param_name = query_param[0].to_s
34
- query_param_value = query_param[1].to_s
35
+ 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
35
37
 
36
38
  query.gsub! /{\?#{query_param_name}}/, query_param_value
37
39
  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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias
@@ -30,7 +30,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.0.0
34
34
  required_rubygems_version: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - ">="