activerecord-setops 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +38 -0
- data/lib/active_record/setops.rb +1 -1
- data/lib/active_record/setops/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19f77a7a5a20214036dc0394e28556788dcbbf95a9c78f8b502fe52fb551ec66
|
4
|
+
data.tar.gz: 9393dd62ceb050cd2605b9b112b7d3cd442e677398fb3ca1d13e7ec8cb836fca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f52b0afedfca8afa3fe948c831fb0ab6db2e31d37618268ee0246e8248f903fa8e83f70ccc7d785603011d0a7bc836a55fa6badbd7aa29d6eb24834f3647f02
|
7
|
+
data.tar.gz: 8a8e060c36ab59c0f5b50dabe04d7071a8251fb0835ddecb8aa9682211767c5698000ccd76397f98525fa81217afbcabaa0edc7cad08645bc4a646407ccec420
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -38,6 +38,44 @@ Or install it yourself as:
|
|
38
38
|
|
39
39
|
$ gem install activerecord-setops
|
40
40
|
|
41
|
+
# Non-Installation
|
42
|
+
|
43
|
+
If you'd like the functionality, but would prefer to avoid yet another dependency, please fill free to paste the following code into your nearest lib directory, I'm certain it's not perfect but it has been [tested](spec/active_record/setops_spec.rb) with Rails 5, and is being used in production.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
module ActiveRecord
|
47
|
+
class Relation
|
48
|
+
# Performs a set theoretic union works like `Array#+` but puts the load on the database
|
49
|
+
# and allows you to chain more relation operations.
|
50
|
+
def union(other)
|
51
|
+
binary_operation(Arel::Nodes::Union, other)
|
52
|
+
end
|
53
|
+
alias | union
|
54
|
+
alias + union
|
55
|
+
|
56
|
+
def union_all(other)
|
57
|
+
binary_operation(Arel::Nodes::UnionAll, other)
|
58
|
+
end
|
59
|
+
|
60
|
+
def intersect(other)
|
61
|
+
binary_operation(Arel::Nodes::Intersect, other)
|
62
|
+
end
|
63
|
+
alias & intersect
|
64
|
+
|
65
|
+
def difference(other)
|
66
|
+
binary_operation(Arel::Nodes::Except, other)
|
67
|
+
end
|
68
|
+
alias - difference
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def binary_operation(op_class, other)
|
73
|
+
@klass.unscoped.from(Arel::Nodes::TableAlias.new(op_class.new(self.arel.ast, other.arel.ast), @klass.arel_table.name))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
41
79
|
# See Also
|
42
80
|
|
43
81
|
- [Sequel](http://sequel.jeremyevans.net)
|
data/lib/active_record/setops.rb
CHANGED
@@ -8,11 +8,11 @@ module ActiveRecord
|
|
8
8
|
binary_operation(Arel::Nodes::Union, other)
|
9
9
|
end
|
10
10
|
alias | union
|
11
|
-
alias + union
|
12
11
|
|
13
12
|
def union_all(other)
|
14
13
|
binary_operation(Arel::Nodes::UnionAll, other)
|
15
14
|
end
|
15
|
+
alias + union_all
|
16
16
|
|
17
17
|
def intersect(other)
|
18
18
|
binary_operation(Arel::Nodes::Intersect, other)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-setops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delon Newman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|