Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mongoid's context only monkey-patched in the development environment …

…+ Some refactoring
  • Loading branch information...
commit 8b8cf2c4ee92bec168c4245968e80a6a929d2cb3 1 parent 3f98edc
@franckverrot authored
Showing with 2 additions and 25 deletions.
  1. +2 −25 mongoid_no_querying_views.rb
View
27 mongoid_no_querying_views.rb
@@ -1,7 +1,7 @@
if Rails.env.development?
module Mongoid #:nodoc:
module Contexts #:nodoc:
- class Mongo
+ %w(Mongo Enumerable).each do |context|
begin
alias :orig_execute :execute
def execute(paginating = false)
@@ -21,27 +21,4 @@ def execute(paginating = false)
end
end
end
-
- module Mongoid #:nodoc:
- module Contexts #:nodoc:
- class Enumerable
- begin
- alias :orig_execute :execute
- def execute(paginating = false)
- first_view = caller.grep(/app\/views/).first
- first_helper = caller.grep(/app\/helpers/).first
-
- # if we're coming from a view, let's analyze the situation
- if !first_view.nil? and (first_helper.nil? or (caller.index(first_view) < caller.index(first_helper)))
- raise "No query from view prohibited, eager-load from a controller instead."
- else
- orig_execute(paginating)
- end
- end
- rescue
- # the adapter has not been instantiated
- end
- end
- end
- end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.