Skip to content

Commit

Permalink
[#873] [#839] fix chained scopes and the :include scope. Credit:
Browse files Browse the repository at this point in the history
Matt Jones
  • Loading branch information
bryanlarsen committed Jan 17, 2011
1 parent e0330b3 commit b46beb9
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions hobo/lib/hobo/scopes/named_scope_extensions.rb
@@ -1,24 +1,32 @@
module ActiveRecord
module NamedScope
class Scope

delegate :member_class, :to => :proxy_found

class Scope
delegate :member_class, :to => :proxy_found
include Hobo::Scopes::ApplyScopes
end

include Hobo::Scopes::ApplyScopes
module ClassMethods
def scopes
hash = read_inheritable_attribute(:scopes)
if hash.nil?
write_inheritable_attribute(:scopes, new_automatic_scoping_hash(self))
elsif hash.default_proc.nil?
write_inheritable_attribute(:scopes, new_automatic_scoping_hash(self).merge!(hash))
else
hash
end

def respond_to_with_hobo_scopes?(method, include_private=false)
scopes.include?(method) || proxy_scope.respond_to?(method, include_private) || respond_to_without_hobo_scopes?(method, include_private)
end
alias_method_chain :respond_to?, :hobo_scopes

private

def method_missing_with_hobo_scopes(method, *args, &block)
respond_to?(method) # required for side effects, see LH#839
method_missing_without_hobo_scopes(method, *args, &block)
def new_automatic_scoping_hash(o)
hash = Hash.new { |hash, key| o.create_automatic_scope(key) && hash[key] }
hash.meta_eval do
define_method :include? do |key, *args|
super(key, *args) || o.create_automatic_scope(key)
end
end
hash
end
alias_method_chain :method_missing, :hobo_scopes

end
end
end

0 comments on commit b46beb9

Please sign in to comment.