-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add monkey patch for joining with
ONLY
keyword (#35)
* monkey patch for join on only * update comment
- Loading branch information
Showing
9 changed files
with
163 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'lib/hoardable/version' | ||
require_relative "lib/hoardable/version" | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'hoardable' | ||
spec.name = "hoardable" | ||
spec.version = Hoardable::VERSION | ||
spec.authors = ['justin talbott'] | ||
spec.email = ['[email protected]'] | ||
spec.authors = ["justin talbott"] | ||
spec.email = ["[email protected]"] | ||
|
||
spec.summary = 'An ActiveRecord extension for versioning and soft-deletion of records in Postgres' | ||
spec.description = 'Rails model versioning with the power of uni-temporal inherited tables' | ||
spec.homepage = 'https://github.com/waymondo/hoardable' | ||
spec.license = 'MIT' | ||
spec.required_ruby_version = '>= 2.7.0' | ||
spec.summary = "An ActiveRecord extension for versioning and soft-deletion of records in Postgres" | ||
spec.description = "Rails model versioning with the power of uni-temporal inherited tables" | ||
spec.homepage = "https://github.com/waymondo/hoardable" | ||
spec.license = "MIT" | ||
spec.required_ruby_version = ">= 3.0" | ||
|
||
spec.metadata['homepage_uri'] = spec.homepage | ||
spec.metadata['source_code_uri'] = spec.homepage | ||
spec.metadata['rubygems_mfa_required'] = 'true' | ||
spec.metadata["homepage_uri"] = spec.homepage | ||
spec.metadata["source_code_uri"] = spec.homepage | ||
spec.metadata["rubygems_mfa_required"] = "true" | ||
|
||
spec.files = Dir.chdir(File.expand_path(__dir__)) do | ||
`git ls-files -z`.split("\x0").reject do |f| | ||
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) | ||
spec.files = | ||
Dir.chdir(File.expand_path(__dir__)) do | ||
`git ls-files -z`.split("\x0") | ||
.reject do |f| | ||
(f == __FILE__) || | ||
f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) | ||
end | ||
end | ||
end | ||
spec.bindir = 'exe' | ||
spec.bindir = "exe" | ||
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } | ||
spec.require_paths = ['lib'] | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_dependency 'activerecord', '>= 6.1', '< 8' | ||
spec.add_dependency 'activesupport', '>= 6.1', '< 8' | ||
spec.add_dependency 'railties', '>= 6.1', '< 8' | ||
spec.add_dependency "activerecord", ">= 7", "< 8" | ||
spec.add_dependency "activesupport", ">= 7", "< 8" | ||
spec.add_dependency "railties", ">= 7", "< 8" | ||
|
||
spec.add_dependency 'fx', '>= 0.8', '< 1' | ||
spec.add_dependency 'pg', '>= 1', '< 2' | ||
spec.add_dependency "fx", ">= 0.8", "< 1" | ||
spec.add_dependency "pg", ">= 1", "< 2" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Hoardable | ||
# This is a monkey patch of JOIN related {Arel::Visitors} for PostgreSQL so that they can append | ||
# the ONLY clause when known to be operating on a {Hoardable::Model}. Ideally, {Arel} itself would | ||
# provide a mechanism to support this keyword. | ||
module ArelVisitors | ||
def visit_Arel_Nodes_FullOuterJoin(o, collector) | ||
collector << "FULL OUTER JOIN " | ||
hoardable_maybe_add_only(o, collector) | ||
collector = visit o.left, collector | ||
collector << " " | ||
visit o.right, collector | ||
end | ||
|
||
def visit_Arel_Nodes_OuterJoin(o, collector) | ||
collector << "LEFT OUTER JOIN " | ||
hoardable_maybe_add_only(o, collector) | ||
collector = visit o.left, collector | ||
collector << " " | ||
visit o.right, collector | ||
end | ||
|
||
def visit_Arel_Nodes_RightOuterJoin(o, collector) | ||
collector << "RIGHT OUTER JOIN " | ||
hoardable_maybe_add_only(o, collector) | ||
collector = visit o.left, collector | ||
collector << " " | ||
visit o.right, collector | ||
end | ||
|
||
def visit_Arel_Nodes_InnerJoin(o, collector) | ||
collector << "INNER JOIN " | ||
hoardable_maybe_add_only(o, collector) | ||
collector = visit o.left, collector | ||
if o.right | ||
collector << " " | ||
visit(o.right, collector) | ||
else | ||
collector | ||
end | ||
end | ||
|
||
private def hoardable_maybe_add_only(o, collector) | ||
return unless o.left.instance_variable_get("@klass").in?(Hoardable::REGISTRY) | ||
return if Hoardable.instance_variable_get("@at") | ||
|
||
collector << "ONLY " | ||
end | ||
end | ||
end | ||
|
||
Arel::Visitors::PostgreSQL.prepend Hoardable::ArelVisitors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.