activerecord-setops 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '09d2b63cfae3f2bba4e0b0801647560862d92f7cbedbe737bf77d293c87fbea2'
4
+ data.tar.gz: fe50366524aaa0f02b13aa1c2510006f452367aee839b43f3a001b577ae5c250
5
+ SHA512:
6
+ metadata.gz: af9917f129aab8114aacb667968a7f8689adaa3bf796d55d686a3baa40da31dd677103c6b9af8eced33a01994c6eddf65263e7b62305e793d38ff135fa8ec78c
7
+ data.tar.gz: 0a45adae43ef6106c430adfcde79fa1200c6929d3b54daf0855a0352591e511d265885ad0347b4248a0079f0345916cf2ef123c4d73918409ea760b11f888bf3
@@ -0,0 +1,21 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby 2.6
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6.x
16
+ - name: Build and test with Rake
17
+ run: |
18
+ sudo apt-get install libsqlite3-dev
19
+ gem install bundler
20
+ bundle install --jobs 4 --retry 3
21
+ bundle exec rake
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ spec/spec.db
13
+ tags
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in activerecord-setoperations.gemspec
6
+ gemspec
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ activerecord-setops (0.1.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activemodel (5.2.4.1)
10
+ activesupport (= 5.2.4.1)
11
+ activerecord (5.2.4.1)
12
+ activemodel (= 5.2.4.1)
13
+ activesupport (= 5.2.4.1)
14
+ arel (>= 9.0)
15
+ activesupport (5.2.4.1)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ arel (9.0.0)
21
+ concurrent-ruby (1.1.5)
22
+ contracts (0.16.0)
23
+ contracts-gen (0.1.1)
24
+ contracts (~> 0.16.0)
25
+ faker (~> 1.9.6)
26
+ gen-test (~> 0.1.0)
27
+ diff-lcs (1.3)
28
+ faker (1.9.6)
29
+ i18n (>= 0.7)
30
+ gen-test (0.1.1)
31
+ faker (~> 1.9.6)
32
+ regexp-examples (~> 1.5.0)
33
+ i18n (1.8.2)
34
+ concurrent-ruby (~> 1.0)
35
+ minitest (5.14.0)
36
+ rake (10.5.0)
37
+ regexp-examples (1.5.1)
38
+ rspec (3.9.0)
39
+ rspec-core (~> 3.9.0)
40
+ rspec-expectations (~> 3.9.0)
41
+ rspec-mocks (~> 3.9.0)
42
+ rspec-core (3.9.1)
43
+ rspec-support (~> 3.9.1)
44
+ rspec-expectations (3.9.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.9.0)
47
+ rspec-mocks (3.9.1)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.9.0)
50
+ rspec-support (3.9.2)
51
+ sqlite3 (1.4.2)
52
+ thread_safe (0.3.6)
53
+ tzinfo (1.2.6)
54
+ thread_safe (~> 0.1)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ activerecord (~> 5.0)
61
+ activerecord-setops!
62
+ bundler (~> 1.17)
63
+ contracts-gen (~> 0.1.1)
64
+ gen-test (~> 0.1.1)
65
+ rake (~> 10.0)
66
+ rspec (~> 3.0)
67
+ sqlite3 (~> 1.4.2)
68
+
69
+ BUNDLED WITH
70
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Delon Newman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ ![Ruby](https://github.com/delonnewman/activerecord-setops/workflows/Ruby/badge.svg)
2
+
3
+ # ActiveRecord::Setops
4
+
5
+ Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll).
6
+ Has only been tested with Rails 5.
7
+
8
+ # Synopsis
9
+
10
+ ```ruby
11
+ class Student < ActiveRecord::Base; end
12
+ class Employee < ActiveRecord::Base; end
13
+
14
+ (Student.select(:name, :birth_date) | Employee.select(:name, :birth_date)).where("name like John%")
15
+ ```
16
+
17
+ # Why?
18
+
19
+ Joins can be difficult to reason about in Arel (an SQL for that matter). Many joins can be replaced
20
+ with set operations which are much simpler beasts, may offer performance gains, and have consistent
21
+ mathematical properties. But these operations while present in Arel are missing in ActiveRecord. This
22
+ module attempts to correct this lack.
23
+
24
+ # Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'activerecord-setops'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install activerecord-setops
39
+
40
+ # See Also
41
+
42
+ - [Sequel](http://sequel.jeremyevans.net)
43
+ - [SQL Set Operations](https://en.wikipedia.org/wiki/Set_operations_(SQL))
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,46 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "active_record/setops/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "activerecord-setops"
7
+ spec.version = ActiveRecord::Setops::VERSION
8
+ spec.authors = ["Delon Newman"]
9
+ spec.email = ["contact@delonnewman.name"]
10
+
11
+ spec.summary = %q{Set operations for ActiveRecord}
12
+ spec.description = %q{Union, Intersection, and Difference operations for ActiveRecord}
13
+ spec.homepage = "https://github.com/delonnewman/activerecord-setops#readme"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/delonnewman/activerecord-setops"
23
+ spec.metadata["changelog_uri"] = "https://github.com/delonnewman/activerecord-setops#changelog"
24
+ spec.metadata["documentation_uri"] = 'https://www.rubydoc.info/gems/activerecord-setops'
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "gen-test", "~> 0.1.1"
43
+ spec.add_development_dependency "contracts-gen", "~> 0.1.1"
44
+ spec.add_development_dependency "activerecord", "~> 5.0"
45
+ spec.add_development_dependency "sqlite3", "~> 1.4.2"
46
+ end
@@ -0,0 +1,34 @@
1
+ require "active_record/setops/version"
2
+
3
+ module ActiveRecord
4
+ class Relation
5
+ # Performs a set theoretic union works like `Array#+` but puts the load on the database
6
+ # and allows you to chain more relation operations.
7
+ def union(other)
8
+ binary_operation(Arel::Nodes::Union, other)
9
+ end
10
+ alias | union
11
+ alias + union
12
+
13
+ def union_all(other)
14
+ binary_operation(Arel::Nodes::UnionAll, other)
15
+ end
16
+
17
+ def intersect(other)
18
+ binary_operation(Arel::Nodes::Intersect, other)
19
+ end
20
+ alias & intersect
21
+
22
+ def except(other)
23
+ binary_operation(Arel::Nodes::Except, other)
24
+ end
25
+ alias difference except
26
+ alias - except
27
+
28
+ private
29
+
30
+ def binary_operation(op_class, other)
31
+ @klass.unscoped.from(Arel::Nodes::TableAlias.new(op_class.new(self.arel.ast, other.arel.ast), @klass.arel_table.name))
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module Setops
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-setops
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Delon Newman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gen-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: contracts-gen
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.4.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.4.2
111
+ description: Union, Intersection, and Difference operations for ActiveRecord
112
+ email:
113
+ - contact@delonnewman.name
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".github/workflows/ruby.yml"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - activerecord-setops.gemspec
127
+ - lib/active_record/setops.rb
128
+ - lib/active_record/setops/version.rb
129
+ homepage: https://github.com/delonnewman/activerecord-setops#readme
130
+ licenses:
131
+ - MIT
132
+ metadata:
133
+ allowed_push_host: https://rubygems.org
134
+ homepage_uri: https://github.com/delonnewman/activerecord-setops#readme
135
+ source_code_uri: https://github.com/delonnewman/activerecord-setops
136
+ changelog_uri: https://github.com/delonnewman/activerecord-setops#changelog
137
+ documentation_uri: https://www.rubydoc.info/gems/activerecord-setops
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubygems_version: 3.0.6
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Set operations for ActiveRecord
157
+ test_files: []