Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Kernel#caller_locations (2.x) #1491

Merged
merged 6 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Avoid shadowing caller_locations
Ruby 2.x+ has a built-in implementation of `caller_locations`,
which differs slightly from the Sinatra implementation of the same.
This removes the customized implementation in favor of the system one
  • Loading branch information
julik authored and jkowens committed Oct 4, 2021
commit 1f6ad766e17567dc516b4c1300bf49da46d0addf
6 changes: 1 addition & 5 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1557,11 +1557,7 @@ def caller_files
cleaned_caller(1).flatten
end

# Like caller_files, but containing Arrays rather than strings with the
# first element being the file, and the second being the line.
def caller_locations
cleaned_caller 2
end
public :caller_locations
jkowens marked this conversation as resolved.
Show resolved Hide resolved

private

Expand Down
5 changes: 3 additions & 2 deletions sinatra-contrib/lib/sinatra/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ def disable(*opts)
end

def template(name, &block)
filename, line = caller_locations.first
templates[name] = [block, filename, line.to_i]
first_location = caller_locations.first
filename, line = first_location.path, first_location.lineno
templates[name] = [block, filename, line]
end

def layout(name=:layout, &block)
Expand Down