diff --git a/lib/has_many_polymorphs/debugging_tools.rb b/lib/has_many_polymorphs/debugging_tools.rb
index 46e091e..9b4dd05 100644
--- a/lib/has_many_polymorphs/debugging_tools.rb
+++ b/lib/has_many_polymorphs/debugging_tools.rb
@@ -9,7 +9,7 @@
Enabled by default when HMP_DEBUG is set.
-Ouputs a folder generated_models/ in RAILS_ROOT containing valid Ruby files explaining all the ActiveRecord relationships set up by the plugin, as well as listing the line in the plugin that called each particular association method.
+Ouputs a folder generated_models/ in Rails.root containing valid Ruby files explaining all the ActiveRecord relationships set up by the plugin, as well as listing the line in the plugin that called each particular association method.
== Ruby-debug
@@ -19,7 +19,7 @@
== Trace
-Enable by setting HMP_DEBUG to "ruby-debug".
+Enable by setting HMP_DEBUG to "trace".
Outputs an indented trace of relevant method calls as they occur.
@@ -41,7 +41,8 @@ class << ActiveRecord::Base
end
unless defined? GENERATED_CODE_DIR
- GENERATED_CODE_DIR = "#{RAILS_ROOT}/generated_models"
+ base_dir = defined?(Rails) ? Rails.root.expand_path : '/tmp'
+ GENERATED_CODE_DIR = "#{base_dir}/generated_models"
begin
system "rm -rf #{GENERATED_CODE_DIR}"
@@ -57,8 +58,8 @@ def method_missing(method_name, *args, &block)
Dir.chdir GENERATED_CODE_DIR do
filename = "#{demodulate(self.name.underscore)}.rb"
contents = File.open(filename).read rescue "\nclass #{self.name}\n\nend\n"
- line = caller[1][/\:(\d+)\:/, 1]
- contents[-5..-5] = "\n #{method_name} #{args[0..-2].inspect[1..-2]},\n #{args[-1].inspect[1..-2].gsub(" :", "\n :").gsub("=>", " => ")}\n#{ block ? " #{block.inspect.sub(/\@.*\//, '@')}\n" : ""} # called from line #{line}\n\n"
+ callfile, callline = caller[2][%r!/.*/(.*?:\d+)!, 1].split(':')
+ contents[-5..-5] = "\n #{method_name} #{args[0..-2].inspect[1..-2]},\n #{args[-1].inspect[1..-2].gsub(" :", "\n :").gsub("=>", " => ")}\n#{ block ? " #{block.inspect.sub(/\@.*\//, '@')}\n" : ""} # called from #{callfile}, line #{callline}\n\n"
File.open(filename, "w") do |file|
file.puts contents
end