Skip to content

Commit

Permalink
Fix ruby 2.7 warning (avoid evaluating __FILE__) (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
whois-marvin-42 authored and deivid-rodriguez committed Jan 10, 2020
1 parent 77d105d commit 6d4049e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Master (Unreleased)

### Fixed

* use Binding#source_location instead of evaluating __FILE__ to avoid warnings
for Ruby >= 2.6 (#221).

## 3.7.0 (2019-02-21)

* Byebug 11 compatibility, with ruby 2.6 support.
Expand Down
4 changes: 3 additions & 1 deletion lib/pry-byebug/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "pry-byebug/helpers/location"

#
# Main container module for Pry-Byebug functionality
#
Expand All @@ -13,7 +15,7 @@ module PryByebug
# Checks that a target binding is in a local file context.
#
def file_context?(target)
file = target.eval("__FILE__")
file = Helpers::Location.current_file(target)
file == Pry.eval_path || !Pry::Helpers::BaseHelpers.not_a_real_file?(file)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/pry-byebug/commands/breakpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "pry/byebug/breakpoints"
require "pry-byebug/helpers/breakpoints"
require "pry-byebug/helpers/location"
require "pry-byebug/helpers/multiline"

module PryByebug
Expand All @@ -10,6 +11,7 @@ module PryByebug
#
class BreakCommand < Pry::ClassCommand
include Helpers::Breakpoints
include Helpers::Location
include Helpers::Multiline

match "break"
Expand Down
2 changes: 2 additions & 0 deletions lib/pry-byebug/commands/continue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "pry-byebug/helpers/navigation"
require "pry-byebug/helpers/breakpoints"
require "pry-byebug/helpers/location"

module PryByebug
#
Expand All @@ -10,6 +11,7 @@ module PryByebug
class ContinueCommand < Pry::ClassCommand
include Helpers::Navigation
include Helpers::Breakpoints
include Helpers::Location

match "continue"
group "Byebug"
Expand Down
8 changes: 0 additions & 8 deletions lib/pry-byebug/helpers/breakpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ def breakpoints
Pry::Byebug::Breakpoints
end

#
# Current file in the target binding. Used as the default breakpoint
# location.
#
def current_file
target.eval("__FILE__")
end

#
# Prints a message with bold font.
#
Expand Down
24 changes: 24 additions & 0 deletions lib/pry-byebug/helpers/location.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module PryByebug
module Helpers
#
# Compatibility helper to handle source location
#
module Location
module_function

#
# Current file in the target binding. Used as the default breakpoint
# location.
#
def current_file(source = target)
# Guard clause for Ruby >= 2.6 providing now Binding#source_location ...
return source.source_location[0] if source.respond_to?(:source_location)

# ... to avoid warning: 'eval may not return location in binding'
source.eval("__FILE__")
end
end
end
end

0 comments on commit 6d4049e

Please sign in to comment.