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: bcfb4894f1b5070e7d844c0e4c24e64d8616b6b2
4
- data.tar.gz: 09a982cfedfcb5fc0998296fed5c4143530abec2
3
+ metadata.gz: cb66e1d1f8009402327ad30ba1342e21ea80bc7a
4
+ data.tar.gz: f9bc8954b6b27db5ee99d2a81243dd51d28751ae
5
5
  SHA512:
6
- metadata.gz: 4385589c6b5e8904dfb4a38d0de81017d5d3c34cffb21e0ef36a8248616e76d1fe26a6ede7ef95b4b9b04a25301c1dd1ac053415c0da6a4a7adc22d251624fed
7
- data.tar.gz: 0a3b380939669676eb9a9a6bc5e5440b806379efc5363f36c86857743547d8c24884f5db8c68bbc0834f734e938b326c380cb701fc0c4ed3e76e9132df5da7a1
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} FROM #{@scope.klass.table_name}",
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.any?
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
- 'id'
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
 
@@ -22,6 +22,10 @@ module Superstore
22
22
  limit(1).to_a.first
23
23
  end
24
24
 
25
+ def to_ids
26
+ klass.adapter.to_ids self
27
+ end
28
+
25
29
  private
26
30
 
27
31
  def find_one(id)
@@ -67,7 +67,6 @@ module Superstore
67
67
  klass.adapter.select(self) do |key, attributes|
68
68
  results << klass.instantiate(key, attributes)
69
69
  end
70
- results.compact!
71
70
  results
72
71
  end
73
72
  end
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'superstore'
5
- s.version = '2.1.0'
5
+ s.version = '2.1.1'
6
6
  s.description = 'ActiveModel for many attributes'
7
7
  s.summary = 'JSONB ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "Infogroup"]
@@ -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.0
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-02-13 00:00:00.000000000 Z
12
+ date: 2016-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel