forked from metaskills/grouped_scope
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test 1.2.6, 2.0.4 and 2.1.1 named scope usage. New named scope back p…
…ort method since mislav back port from will paginate was not complete for 1.2.6.
- Loading branch information
1 parent
9c438e9
commit 693b17e
Showing
8 changed files
with
187 additions
and
61 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
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,20 @@ | ||
|
||
unless Hash.instance_methods.include? 'except' | ||
|
||
Hash.class_eval do | ||
|
||
# Returns a new hash without the given keys. | ||
def except(*keys) | ||
rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) | ||
reject { |key,| rejected.include?(key) } | ||
end | ||
|
||
# Replaces the hash without only the given keys. | ||
def except!(*keys) | ||
replace(except(*keys)) | ||
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 was deleted.
Oops, something went wrong.
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,61 @@ | ||
|
||
ActiveRecord::Associations::AssociationProxy.class_eval do | ||
protected | ||
def with_scope(*args, &block) | ||
@reflection.klass.send :with_scope, *args, &block | ||
end | ||
end | ||
|
||
ActiveRecord::Associations::HasManyAssociation.class_eval do | ||
protected | ||
def method_missing(method, *args, &block) | ||
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) | ||
super | ||
elsif @reflection.klass.scopes.include?(method) | ||
@reflection.klass.scopes[method].call(self, *args) | ||
else | ||
create_scoping = {} | ||
set_belongs_to_association_for(create_scoping) | ||
|
||
@reflection.klass.with_scope( | ||
:create => create_scoping, | ||
:find => { | ||
:conditions => @finder_sql, | ||
:joins => @join_sql, | ||
:readonly => false | ||
} | ||
) do | ||
@reflection.klass.send(method, *args, &block) | ||
end | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Associations::HasManyThroughAssociation.class_eval do | ||
protected | ||
def method_missing(method, *args, &block) | ||
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) | ||
super | ||
elsif @reflection.klass.scopes.include?(method) | ||
@reflection.klass.scopes[method].call(self, *args) | ||
else | ||
@reflection.klass.with_scope(construct_scope) { @reflection.klass.send(method, *args, &block) } | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do | ||
protected | ||
def method_missing(method, *args, &block) | ||
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) | ||
super | ||
elsif @reflection.klass.scopes.include?(method) | ||
@reflection.klass.scopes[method].call(self, *args) | ||
else | ||
@reflection.klass.with_scope(:find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false }) do | ||
@reflection.klass.send(method, *args, &block) | ||
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,32 @@ | ||
|
||
ActiveRecord::Associations::AssociationProxy.class_eval do | ||
protected | ||
def with_scope(*args, &block) | ||
@reflection.klass.send :with_scope, *args, &block | ||
end | ||
end | ||
|
||
|
||
ActiveRecord::Associations::AssociationCollection.class_eval do | ||
protected | ||
def method_missing(method, *args) | ||
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) | ||
if block_given? | ||
super { |*block_args| yield(*block_args) } | ||
else | ||
super | ||
end | ||
elsif @reflection.klass.scopes.include?(method) | ||
@reflection.klass.scopes[method].call(self, *args) | ||
else | ||
with_scope(construct_scope) do | ||
if block_given? | ||
@reflection.klass.send(method, *args) { |*block_args| yield(*block_args) } | ||
else | ||
@reflection.klass.send(method, *args) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|