record-collection 0.0.0 → 0.0.1
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.rb +27 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed87bf6f98fad0fd07766f936581ebcbc1490af4
|
4
|
+
data.tar.gz: 95648439a51e13afdbf86640d7ff9a46be797464
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0d10ea57cf79ae17bcd14fda6e49ca09cb4fb2078714a36981ead5a13a7c278adfcfb6dfcbbe5c7caead26780cc02165760b133e8ab5d38c5bae806843e3c2e
|
7
|
+
data.tar.gz: 320ddb3dee49cbaa8a366623767107404a9a9517988c1e6ccdc6d8e31731114b46356ebe1ca30b712a5ab1f167ae0e2496ce17f7272c9ca5b11b61f1580c9395
|
data/lib/record_collection.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
class RecordCollection
|
2
|
+
include Enumerable
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
def initialize(base_scope)
|
6
|
+
self.base_scope = base_scope
|
7
|
+
self.scopes = Set.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def limit_by(scope)
|
11
|
+
scopes.add(scope)
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def is_limited_by?(scope)
|
16
|
+
# because ActiveRecord::Relations do not implement hashing correctly, we must do case by case equality
|
17
|
+
scopes.any? { |s| s == scope }
|
18
|
+
end
|
19
|
+
|
20
|
+
def each(&block)
|
21
|
+
scopes.reduce(base_scope) { |scope, base| base.merge(scope) }.each(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_accessor :base_scope, :scopes
|
27
|
+
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.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Courtney de Lautour
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
41
55
|
description: |2
|
42
56
|
Exposing ActiveRecord::Relations from your controllers to views is bad for business. As much as it is convenient to
|
43
57
|
do so, does it really make sense that your view can use an `unscoped` version of it? More importantly, testing what is
|