record-collection 0.0.1424540975 → 0.1.1424542204

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/record_collection.rb +14 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42aa79dc18bda909e4edfbb3f15e97991a73a4fb
4
- data.tar.gz: 5c7ad353ffb0b63cf4e5736f49da2dc3128a5f42
3
+ metadata.gz: e32711e7065692238d331a260412a7fcfe983422
4
+ data.tar.gz: 6833e8207a03b42d9c9bedff75f3d900ca35944d
5
5
  SHA512:
6
- metadata.gz: e4cd1840f6547d4d91937bf6bef8156137f8f4a4d19b9e0085b102f3126c96100cae5248c7971866e37fa62b1aaad7d1e019d000d99e5dd33b8babc62fc8ec30
7
- data.tar.gz: 9dbd97e2bc1154000a0ce37cbd0f7d65aaa5d3667e23a2ef67b44589a5e5ba830380c928e9b58d0f0869df5a36ac4a58d4c34f52f460d1aeeec163b9a0f1a907
6
+ metadata.gz: 82824a2a1ab8a44c0483ccd9c071775fe2d6ff3401a35522292aeca7646b3137f790175f472f1b6498ec7833bd0d3c78d88beb7cd83452b33025e4bba68f285e
7
+ data.tar.gz: 2cd606a71c2bf37da7a9a52d9ab273b9b3eac798317aad0e6afbf57d49c238a84829c38baae3cf4eaf96beb56a232829d73ff5bbb6a7416bff7849efdb78b5f4
@@ -3,20 +3,33 @@ class RecordCollection
3
3
  require 'set'
4
4
 
5
5
  def initialize(base_scope)
6
- self.base_scope = base_scope
6
+ self.base_scope = coerce_to_relation(base_scope)
7
7
  self.scopes = Set.new
8
8
  end
9
9
 
10
+ def coerce_to_relation(base_scope)
11
+ if base_scope.respond_to?(:all)
12
+ base_scope.all
13
+ else
14
+ # rails 3
15
+ base_scope.scoped
16
+ end
17
+ end
18
+
10
19
  def limit_by(scope)
11
20
  scopes.add(scope)
12
21
  self
13
22
  end
14
23
 
24
+ alias and limit_by
25
+
15
26
  def is_limited_by?(scope)
16
27
  # because ActiveRecord::Relations do not implement hashing correctly, we must do case by case equality
17
28
  scopes.any? { |s| s == scope }
18
29
  end
19
30
 
31
+ alias limited_by? is_limited_by?
32
+
20
33
  def each(&block)
21
34
  scopes.reduce(base_scope) { |scope, base| base.merge(scope) }.each(&block)
22
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record-collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1424540975
4
+ version: 0.1.1424542204
5
5
  platform: ruby
6
6
  authors:
7
7
  - Courtney de Lautour