activerecord-setops 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 825c886304c118ae19d8993c4dc9529ee2bbd39af385054a2f28c26cae6b210a
4
+ data.tar.gz: b652c44096b150959940b71b6c45de9e70e21ce4d10efe29ab69c78ffbebc1c4
5
+ SHA512:
6
+ metadata.gz: 2f3bbb031e2bdeeb92a88b913b930494c8e5e7abf65fe78686c0061af1a6175ba683aa03f86ee6cc6782b2e0408563fce1b41810379c4415109655687e4ce809
7
+ data.tar.gz: 324d14a9905f256045f07e6bb9730ea165b669bb8f1f95031c52478fe9a58f4531c94ff9fd93bad8721f91d27c6de1baffb57ff4b8535541f97aeb4538a8058d
@@ -0,0 +1,20 @@
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
+ gem install bundler
19
+ bundle install --jobs 4 --retry 3
20
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,12 @@
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
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
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ activerecord-setops (0.1.0)
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.2.4)
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
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # ActiveRecord::Setops
2
+
3
+ Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll).
4
+ Has only been tested with Rails 5.
5
+
6
+ # Why?
7
+
8
+ Joins can be difficult to reason about in Arel (an SQL for that matter). Many joins can be replaced
9
+ with set operations which are much simplers beasts and have consistent mathetical properties.
10
+
11
+ # Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'activerecord-setops'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install activerecord-setops
26
+
27
+ # Synopsis
28
+
29
+ ```ruby
30
+ class Student < ActiveRecord::Base; end
31
+ class Employee < ActiveRecord::Base; end
32
+
33
+ (Student.select(:name, :birth_date) | Employee.select(:name, :birth_date)).where("name like John%")
34
+ ```
35
+
36
+ # See Also
37
+
38
+ - [Sequel](http://sequel.jeremyevans.net)
39
+ - [SQL Set Operations](https://en.wikipedia.org/wiki/Set_operations_(SQL))
data/Rakefile ADDED
@@ -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,45 @@
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, Intesection, 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
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.17"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "gen-test", "~> 0.1.1"
42
+ spec.add_development_dependency "contracts-gen", "~> 0.1.1"
43
+ spec.add_development_dependency "activerecord", "~> 5.2.4"
44
+ spec.add_development_dependency "sqlite3", "~> 1.4.2"
45
+ 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.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-setops
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Delon Newman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-30 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.2.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 5.2.4
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, Intesection, 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
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubygems_version: 3.0.6
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Set operations for ActiveRecord
156
+ test_files: []