Created
July 6, 2012 03:02
-
-
Save miyagawa/3057813 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'timecop' | |
module ActiveRecordDetectTimeInScopes | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def scope(*args) | |
scope_caller = caller | |
Timecop.travel(Time.now) do | |
Timecop.top_stack_item.define_singleton_method :time do | |
warn "WARNING: You have a scope with Time evaluated immediately in its args. " + | |
"You might want to use lambda.\n" + | |
Rails.backtrace_cleaner.clean(scope_caller).map { |trace| "\t#{trace}" }.join("\n") | |
super() | |
end | |
super | |
end | |
end | |
end | |
end | |
ActiveRecord::Base.send(:include, ActiveRecordDetectTimeInScopes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crap it won't work - needs to hook before the scope args are evaluated!