This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work on 4.0.0 compatibility. Specs pass.
This work will not be backwards compatible with 3.x at the moment. References #239
- Loading branch information
Showing
34 changed files
with
216 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
squeel |
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 @@ | ||
ruby-1.9.3-p374 |
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,13 +1,5 @@ | ||
rvm: | ||
- 1.8.7 | ||
- 1.9.3 | ||
# TODO: Re-enable when updates to Rubinius on | ||
# Travis stop randomly breaking specs that | ||
# pass on MRI. :( | ||
# - rbx-18mode | ||
# - rbx-19mode | ||
|
||
env: | ||
- RAILS=3-2-stable | ||
- RAILS=3-1-stable AREL=2-2-stable | ||
- RAILS=3-0-stable AREL=2-0-stable | ||
- RAILS=4-0-stable AREL=master |
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
13 changes: 13 additions & 0 deletions
13
lib/squeel/adapters/active_record/4.0/association_scope_extensions.rb
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,13 @@ | ||
module ActiveRecord | ||
module Associations | ||
class AssociationScope | ||
def eval_scope(klass, scope) | ||
if scope.is_a?(Relation) | ||
scope | ||
else | ||
klass.unscoped.instance_exec(owner, &scope).visited | ||
end | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'squeel/adapters/active_record/compat' |
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 @@ | ||
require 'squeel/adapters/active_record/context' |
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 @@ | ||
require 'squeel/adapters/active_record/preloader_extensions' |
75 changes: 75 additions & 0 deletions
75
lib/squeel/adapters/active_record/4.0/relation_extensions.rb
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,75 @@ | ||
require 'squeel/adapters/active_record/relation_extensions' | ||
|
||
module Squeel | ||
module Adapters | ||
module ActiveRecord | ||
module RelationExtensions | ||
|
||
def where(opts = :chain, *rest) | ||
if block_given? | ||
super(DSL.eval &Proc.new) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def build_arel | ||
arel = Arel::SelectManager.new(table.engine, table) | ||
|
||
build_joins(arel, joins_values) unless joins_values.empty? | ||
|
||
collapse_wheres(arel, where_visit((where_values - ['']).uniq)) | ||
|
||
arel.having(*having_visit(having_values.uniq.reject{|h| h.blank?})) unless having_values.empty? | ||
|
||
arel.take(connection.sanitize_limit(limit_value)) if limit_value | ||
arel.skip(offset_value.to_i) if offset_value | ||
|
||
arel.group(*group_visit(group_values.uniq.reject{|g| g.blank?})) unless group_values.empty? | ||
|
||
build_order(arel) | ||
|
||
build_select(arel, select_visit(select_values.uniq)) | ||
|
||
arel.distinct(distinct_value) | ||
arel.from(from_visit(from_value)) if from_value | ||
arel.lock(lock_value) if lock_value | ||
|
||
arel | ||
end | ||
|
||
def build_order(arel) | ||
orders = order_visit(order_values) | ||
orders = reverse_sql_order(attrs_to_orderings(orders)) if reverse_order_value | ||
|
||
orders = orders.uniq.reject(&:blank?).flat_map do |order| | ||
case order | ||
when Symbol | ||
table[order].asc | ||
when Hash | ||
order.map { |field, dir| table[field].send(dir) } | ||
else | ||
order | ||
end | ||
end | ||
|
||
arel.order(*orders) unless orders.empty? | ||
end | ||
|
||
def build_from | ||
opts, name = from_value | ||
case opts | ||
when Relation | ||
name ||= 'subquery' | ||
opts.arel.as(name.to_s) | ||
else | ||
opts | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Relation.send :include, Squeel::Adapters::ActiveRecord::RelationExtensions |
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
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
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,6 @@ | ||
module Squeel | ||
module Nodes | ||
class Node | ||
end | ||
end | ||
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
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.