Module: NoQueryingViews

Defined in:
lib/no_querying_views.rb

Instance Method Summary collapse

Instance Method Details

#exec_query(*args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/no_querying_views.rb', line 18

def exec_query(*args)
  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 && (first_helper.nil? || (caller.index(first_view) < caller.index(first_helper)))
    reason = first_view || first_helper
    file, line, _ = reason.split(':')
    raise NoQueryingViewError, "Latest query located in #{file}, line #{line}"
  else
    super(*args)
  end
end