superstore 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb66e1d1f8009402327ad30ba1342e21ea80bc7a
|
4
|
+
data.tar.gz: f9bc8954b6b27db5ee99d2a81243dd51d28751ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57efc766e9cfd09a53827243b748f0121e5e829580372318fefecf3dfebca43befc44546f0fe2b5479e4a6b27a15c57391bdf4168bc9055ee966dc62f739c4de
|
7
|
+
data.tar.gz: 158b2901c8ea1208067d593eda2134a6cde16e8b1a19e3e1c43eb2898b2df20b50cd1df8fcaaeba99e1382e298cbb2aefa513fc2b1692886c05f8774f96604db
|
@@ -12,18 +12,25 @@ module Superstore
|
|
12
12
|
|
13
13
|
def to_query
|
14
14
|
[
|
15
|
-
"SELECT #{select_string}
|
15
|
+
"SELECT #{select_string}",
|
16
|
+
from_string,
|
16
17
|
where_string,
|
17
18
|
order_string,
|
18
19
|
limit_string
|
19
20
|
].delete_if(&:blank?) * ' '
|
20
21
|
end
|
21
22
|
|
23
|
+
def from_string
|
24
|
+
"FROM #{@scope.klass.table_name}"
|
25
|
+
end
|
26
|
+
|
22
27
|
def select_string
|
23
|
-
if @scope.select_values.
|
24
|
-
"id, jsonb_slice(document, #{@adapter.fields_to_postgres_array(@scope.select_values)}) as document"
|
25
|
-
else
|
28
|
+
if @scope.select_values.empty?
|
26
29
|
'*'
|
30
|
+
elsif @scope.select_values == [@adapter.primary_key_column]
|
31
|
+
@adapter.primary_key_column
|
32
|
+
else
|
33
|
+
"#{@adapter.primary_key_column}, jsonb_slice(document, #{@adapter.fields_to_postgres_array(@scope.select_values)}) as document"
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
@@ -76,8 +83,9 @@ module Superstore
|
|
76
83
|
end
|
77
84
|
end
|
78
85
|
|
86
|
+
PRIMARY_KEY_COLUMN = 'id'.freeze
|
79
87
|
def primary_key_column
|
80
|
-
|
88
|
+
PRIMARY_KEY_COLUMN
|
81
89
|
end
|
82
90
|
|
83
91
|
def connection
|
@@ -96,6 +104,11 @@ module Superstore
|
|
96
104
|
connection.execute statement
|
97
105
|
end
|
98
106
|
|
107
|
+
def to_ids(scope)
|
108
|
+
statement = QueryBuilder.new(self, scope.select('id')).to_query
|
109
|
+
connection.select_values(statement)
|
110
|
+
end
|
111
|
+
|
99
112
|
def select(scope)
|
100
113
|
statement = QueryBuilder.new(self, scope).to_query
|
101
114
|
|
data/lib/superstore/scope.rb
CHANGED
data/lib/superstore/scoping.rb
CHANGED
@@ -4,7 +4,7 @@ module Superstore
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
singleton_class.class_eval do
|
7
|
-
delegate :find, :find_by_id, :first, :all, to: :scope
|
7
|
+
delegate :find, :find_by_id, :first, :all, :to_ids, to: :scope
|
8
8
|
delegate :find_each, :find_in_batches, to: :scope
|
9
9
|
delegate :select, :where, :where_ids, to: :scope
|
10
10
|
end
|
data/superstore.gemspec
CHANGED
@@ -48,4 +48,10 @@ class Superstore::FinderMethodsTest < Superstore::TestCase
|
|
48
48
|
|
49
49
|
assert [first_issue, second_issue].include?(Issue.first)
|
50
50
|
end
|
51
|
+
|
52
|
+
test 'to_ids' do
|
53
|
+
first_issue = Issue.create title: 'Sup!'
|
54
|
+
|
55
|
+
assert_equal [first_issue.id], Issue.to_ids
|
56
|
+
end
|
51
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Koziarski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|