Module: RorVsWild::Location
- Included in:
- Client
- Defined in:
- lib/rorvswild/location.rb
Class Method Summary collapse
Instance Method Summary collapse
- #app_root_regex ⇒ Object
- #extract_most_relevant_location(stack) ⇒ Object
- #gem_home ⇒ Object
- #gem_home_regex ⇒ Object
- #relative_path(path) ⇒ Object
Class Method Details
.cleanup_method_name(method) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/rorvswild/location.rb', line 3 def self.cleanup_method_name(method) method.sub!("block in ".freeze, "".freeze) method.sub!("in `".freeze, "".freeze) method.sub!("'".freeze, "".freeze) method.index("_app_views_".freeze) == 0 ? nil : method end |
.split_file_location(location) ⇒ Object
10 11 12 13 14 |
# File 'lib/rorvswild/location.rb', line 10 def self.split_file_location(location) file, line, method = location.split(":") method = cleanup_method_name(method) if method [file, line, method] end |
Instance Method Details
#app_root_regex ⇒ Object
22 23 24 |
# File 'lib/rorvswild/location.rb', line 22 def app_root_regex @app_root_regex ||= RorVsWild.default_client.app_root ? /\A#{RorVsWild.default_client.app_root}/ : nil end |
#extract_most_relevant_location(stack) ⇒ Object
16 17 18 19 20 |
# File 'lib/rorvswild/location.rb', line 16 def extract_most_relevant_location(stack) location = stack.find { |str| str =~ app_root_regex && !(str =~ gem_home_regex) } if app_root_regex location ||= stack.find { |str| !(str =~ gem_home_regex) } if gem_home_regex RorVsWild::Location.split_file_location(relative_path(location || stack.first)) end |
#gem_home ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rorvswild/location.rb', line 30 def gem_home if ENV["GEM_HOME"] && !ENV["GEM_HOME"].empty? ENV["GEM_HOME"] elsif ENV["GEM_PATH"] && !(first_gem_path = ENV["GEM_PATH"].split(":").first) first_gem_path if first_gem_path && !first_gem_path.empty? end end |
#gem_home_regex ⇒ Object
26 27 28 |
# File 'lib/rorvswild/location.rb', line 26 def gem_home_regex @gem_home_regex ||= gem_home ? /\A#{gem_home}/.freeze : /\/gems\//.freeze end |
#relative_path(path) ⇒ Object
38 39 40 |
# File 'lib/rorvswild/location.rb', line 38 def relative_path(path) app_root_regex ? path.sub(app_root_regex, "".freeze) : path end |