wise_gopher 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +11 -11
- data/lib/wise_gopher/base.rb +7 -4
- data/lib/wise_gopher/column.rb +11 -5
- data/lib/wise_gopher/param.rb +9 -3
- data/lib/wise_gopher/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 509914f52ec8f5902d4ef0dc1de802f8c80bba0d77477617259e2d143ab30637
|
4
|
+
data.tar.gz: 9b68edf080df0f2e74a9f8eab87fe620644ab5faee65e91170ccd8b9f6bcaf81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66ddaa1559ccc3c33654016de9e46bbbe6f4d7efce4bcfc42dc519218abc3b51d027ab982179868c3af8896be3e6365806f10167b4bbf2164bfbb7422ecc4894
|
7
|
+
data.tar.gz: 1c00e325744b986a070486540bf60ce42557256d39db27e588ffa31740cb9ae23115cb73f626ebef37803e01578e72bab900a1735b712f960dc056baa75d190a
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wise_gopher (0.2.
|
4
|
+
wise_gopher (0.2.2)
|
5
5
|
activerecord (>= 5, < 7)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (6.1.4.
|
11
|
-
activesupport (= 6.1.4.
|
12
|
-
activerecord (6.1.4.
|
13
|
-
activemodel (= 6.1.4.
|
14
|
-
activesupport (= 6.1.4.
|
15
|
-
activesupport (6.1.4.
|
10
|
+
activemodel (6.1.4.4)
|
11
|
+
activesupport (= 6.1.4.4)
|
12
|
+
activerecord (6.1.4.4)
|
13
|
+
activemodel (= 6.1.4.4)
|
14
|
+
activesupport (= 6.1.4.4)
|
15
|
+
activesupport (6.1.4.4)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
@@ -24,10 +24,10 @@ GEM
|
|
24
24
|
concurrent-ruby (1.1.9)
|
25
25
|
database_cleaner (1.99.0)
|
26
26
|
diff-lcs (1.4.4)
|
27
|
-
i18n (1.
|
27
|
+
i18n (1.9.1)
|
28
28
|
concurrent-ruby (~> 1.0)
|
29
29
|
method_source (1.0.0)
|
30
|
-
minitest (5.
|
30
|
+
minitest (5.15.0)
|
31
31
|
parallel (1.20.1)
|
32
32
|
parser (3.0.1.1)
|
33
33
|
ast (~> 2.4.1)
|
@@ -79,7 +79,7 @@ GEM
|
|
79
79
|
concurrent-ruby (~> 1.0)
|
80
80
|
unicode-display_width (2.0.0)
|
81
81
|
yard (0.9.26)
|
82
|
-
zeitwerk (2.5.
|
82
|
+
zeitwerk (2.5.4)
|
83
83
|
|
84
84
|
PLATFORMS
|
85
85
|
x86_64-darwin-21
|
@@ -99,4 +99,4 @@ DEPENDENCIES
|
|
99
99
|
wise_gopher!
|
100
100
|
|
101
101
|
BUNDLED WITH
|
102
|
-
2.
|
102
|
+
2.3.6
|
data/lib/wise_gopher/base.rb
CHANGED
@@ -101,7 +101,6 @@ module WiseGopher
|
|
101
101
|
def initialize(inputs = {})
|
102
102
|
@inputs = inputs
|
103
103
|
@binds = []
|
104
|
-
@bind_symbol = WiseGopher.postgresql? ? +"$1" : "?"
|
105
104
|
@query_prepared = false
|
106
105
|
|
107
106
|
self.class.ensure_all_params_are_given(inputs)
|
@@ -180,16 +179,20 @@ module WiseGopher
|
|
180
179
|
|
181
180
|
def use_bind_symbol
|
182
181
|
if WiseGopher.postgresql?
|
183
|
-
symbol =
|
182
|
+
symbol = bind_symbol.dup
|
184
183
|
|
185
|
-
|
184
|
+
bind_symbol.next!
|
186
185
|
|
187
186
|
symbol
|
188
187
|
else
|
189
|
-
|
188
|
+
bind_symbol
|
190
189
|
end
|
191
190
|
end
|
192
191
|
|
192
|
+
def bind_symbol
|
193
|
+
@bind_symbol ||= WiseGopher.postgresql? ? +"$1" : "?"
|
194
|
+
end
|
195
|
+
|
193
196
|
def ensure_row_class_is_declared
|
194
197
|
raise RowClassIsMissing unless row_class
|
195
198
|
end
|
data/lib/wise_gopher/column.rb
CHANGED
@@ -3,21 +3,25 @@
|
|
3
3
|
module WiseGopher
|
4
4
|
# Cast query columns and transform value
|
5
5
|
class Column
|
6
|
-
attr_reader :name, :
|
6
|
+
attr_reader :name, :alias
|
7
7
|
|
8
8
|
def initialize(name, type_symbol, transform: nil, as: nil)
|
9
|
-
@alias
|
10
|
-
@name
|
11
|
-
@
|
9
|
+
@alias = as&.to_s.freeze || name.to_s.freeze
|
10
|
+
@name = name.to_s.freeze
|
11
|
+
@type_symbol = type_symbol
|
12
12
|
@transform = transform&.to_proc
|
13
13
|
end
|
14
14
|
|
15
15
|
def cast(value)
|
16
|
-
casted_value =
|
16
|
+
casted_value = type.deserialize(value)
|
17
17
|
|
18
18
|
@transform ? transform_value(casted_value) : casted_value
|
19
19
|
end
|
20
20
|
|
21
|
+
def type
|
22
|
+
@type ||= ActiveRecord::Type.lookup type_symbol
|
23
|
+
end
|
24
|
+
|
21
25
|
def define_getter(row_class)
|
22
26
|
column = self
|
23
27
|
|
@@ -32,6 +36,8 @@ module WiseGopher
|
|
32
36
|
|
33
37
|
private
|
34
38
|
|
39
|
+
attr_reader :type_symbol
|
40
|
+
|
35
41
|
def transform_value(value)
|
36
42
|
case @transform.arity
|
37
43
|
when 0 then value.instance_exec(&@transform)
|
data/lib/wise_gopher/param.rb
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
module WiseGopher
|
4
4
|
# Register query's params and build query's bind variables
|
5
5
|
class Param
|
6
|
-
attr_reader :name
|
6
|
+
attr_reader :name
|
7
7
|
|
8
8
|
def initialize(name, type_symbol, transform = nil)
|
9
|
-
@name
|
10
|
-
@
|
9
|
+
@name = name.to_s.freeze
|
10
|
+
@type_symbol = type_symbol
|
11
11
|
@transform = transform&.to_proc
|
12
12
|
end
|
13
13
|
|
@@ -17,8 +17,14 @@ module WiseGopher
|
|
17
17
|
ActiveRecord::Relation::QueryAttribute.new(name, prepared_value, type)
|
18
18
|
end
|
19
19
|
|
20
|
+
def type
|
21
|
+
@type ||= ActiveRecord::Type.lookup type_symbol
|
22
|
+
end
|
23
|
+
|
20
24
|
private
|
21
25
|
|
26
|
+
attr_reader :type_symbol
|
27
|
+
|
22
28
|
def transform_value(value)
|
23
29
|
case @transform.arity
|
24
30
|
when 0 then value.instance_exec(&@transform)
|
data/lib/wise_gopher/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wise_gopher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PageHey
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -210,7 +210,7 @@ metadata:
|
|
210
210
|
homepage_uri: https://github.com/Pagehey/wise_gopher
|
211
211
|
source_code_uri: https://github.com/Pagehey/wise_gopher
|
212
212
|
changelog_uri: https://github.com/Pagehey/wise_gopher/blob/main/CHANGELOG.md
|
213
|
-
post_install_message:
|
213
|
+
post_install_message:
|
214
214
|
rdoc_options: []
|
215
215
|
require_paths:
|
216
216
|
- lib
|
@@ -225,8 +225,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
225
|
- !ruby/object:Gem::Version
|
226
226
|
version: '0'
|
227
227
|
requirements: []
|
228
|
-
rubygems_version: 3.
|
229
|
-
signing_key:
|
228
|
+
rubygems_version: 3.1.6
|
229
|
+
signing_key:
|
230
230
|
specification_version: 4
|
231
231
|
summary: Encapsulate raw SQL queries and return result as plain Ruby objects, using
|
232
232
|
ActiveRecord.
|