Created
October 24, 2008 13:18
-
-
Save jblanche/19419 to your computer and use it in GitHub Desktop.
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
module ScopedObject | |
def named_scope_first(name, options = {}, &block) | |
name = name.to_sym | |
scopes[name] = lambda do |parent_scope, *args| | |
Scope.new(parent_scope, case options | |
when Hash | |
options | |
when Proc | |
options.call(*args) | |
end, &block).first | |
end | |
(class << self; self end).instance_eval do | |
define_method name do |*args| | |
scopes[name].call(self, *args) | |
end | |
end | |
end | |
def self.included(mod) | |
puts "#{self} included in #{mod}" | |
end | |
class Scope < ActiveRecord::NamedScope::Scope | |
end | |
end | |
ActiveRecord::NamedScope::ClassMethods.send :include, ScopedObject | |
ActiveRecord::Base.send :include, ActiveRecord::NamedScope |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment