record_collection 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/record_collection/base.rb +7 -1
- data/lib/record_collection/version.rb +1 -1
- data/spec/base/finding_records_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8105f9981da0c30ff4cea3a5de92bf724b6a53d2
|
4
|
+
data.tar.gz: 74efbf9e4cfbe05de9745eaae179f69317b91b0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5129d5f5f6104a49305680d9093a4b33f5efc322397d63fc2935a0eafea2900ecf29d489939a2f55d2c73cff035ed76c24eaccf9512a0acce08b8aeed58356cc
|
7
|
+
data.tar.gz: 897479481ce00c0e9b20305bac81b69d2433b83aee09f4798b1afe3c0a3c5ddb244a0a0fbab49f30618108dde7eabb8f25283766a2efa21c39fefbe2674dbdb9
|
@@ -2,6 +2,7 @@ module RecordCollection
|
|
2
2
|
class Base
|
3
3
|
include Enumerable
|
4
4
|
include ActiveAttr::Model
|
5
|
+
STRING_IDS_SEPARATOR = '~'
|
5
6
|
|
6
7
|
attr_reader :collection
|
7
8
|
delegate :first, :last, :size, :length, :count, :empty?, :any?, to: :collection
|
@@ -47,7 +48,12 @@ module RecordCollection
|
|
47
48
|
#FINDERS
|
48
49
|
def find(ids)
|
49
50
|
raise "Cannot call find on a collection object if there is no record_class defined" unless respond_to?(:record_class) && record_class
|
50
|
-
|
51
|
+
collection = case ids.presence
|
52
|
+
when String then record_class.find(ids.split(STRING_IDS_SEPARATOR))
|
53
|
+
when nil then []
|
54
|
+
else record_class.find(Array.wrap(ids))
|
55
|
+
end
|
56
|
+
self.new(collection)
|
51
57
|
end
|
52
58
|
|
53
59
|
# Create a new collection with the scope set to the result of the query on the record_class
|
@@ -24,6 +24,17 @@ RSpec.describe Employee::Collection do
|
|
24
24
|
described_class.find([employee1.id, employee2.id]).collection.should match_array [employee1, employee2]
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
it "finds single id as string as collection" do
|
29
|
+
employee = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
30
|
+
described_class.find(employee.id).collection.should eq [employee]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'finds multiple records from a tilde separated string' do
|
34
|
+
employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
35
|
+
employee2 = Employee.create name: 'E2', section: 'QNP', admin: false, vegan: false
|
36
|
+
described_class.find("#{employee1.id}~#{employee2.id}").collection.should match_array [employee1, employee2]
|
37
|
+
end
|
27
38
|
end
|
28
39
|
|
29
40
|
describe '.where' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: record_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin ter Kuile
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|