record_collection 0.8.1 → 0.8.2

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: 1c445bd0e2e9f8299f807585a29a41710e568714
4
- data.tar.gz: 1545d0887d9a46ca4d263143195c21dc7168e045
3
+ metadata.gz: 8105f9981da0c30ff4cea3a5de92bf724b6a53d2
4
+ data.tar.gz: 74efbf9e4cfbe05de9745eaae179f69317b91b0a
5
5
  SHA512:
6
- metadata.gz: 507893a2c300a9010b35f37e6068976cc5a49d4080ed4b7185f40b8aec08f5d921bb6297c3981902d5b5424138cea274f44c016fe46cddd5e510598bc6a7fdc0
7
- data.tar.gz: 04fc98678723024797e6cb10e9932d05d26e3cae59ab9914da957df93465d7e4e47dd880d5bd627f2ae760a4b7f31a9325c74056e66bd562e25b65e8def173e0
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
- new(ids.present? ? record_class.find(ids) : [])
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
@@ -1,3 +1,3 @@
1
1
  module RecordCollection
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
@@ -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.1
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-10-26 00:00:00.000000000 Z
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler