mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Use Kernel#caller_locations (2.x) (#1491)
Ruby 2.x+ has a built-in implementation of `caller_locations`, which differs slightly from the Sinatra implementation of the same name. This removes the customized implementation in favor of the system one Co-authored-by: Jordan Owens <jkowens@gmail.com>
This commit is contained in:
parent
fb64f4f4b4
commit
ab29667040
2 changed files with 7 additions and 11 deletions
|
@ -900,9 +900,10 @@ module Sinatra
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile_block_template(template, options, &body)
|
def compile_block_template(template, options, &body)
|
||||||
caller = settings.caller_locations.first
|
first_location = caller_locations.first
|
||||||
path = options[:path] || caller[0]
|
path, line = first_location.path, first_location.lineno
|
||||||
line = options[:line] || caller[1]
|
path = options[:path] || path
|
||||||
|
line = options[:line] || line
|
||||||
template.new(path, line.to_i, options, &body)
|
template.new(path, line.to_i, options, &body)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1553,12 +1554,6 @@ module Sinatra
|
||||||
cleaned_caller(1).flatten
|
cleaned_caller(1).flatten
|
||||||
end
|
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
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Starts the server by running the Rack Handler.
|
# Starts the server by running the Rack Handler.
|
||||||
|
|
|
@ -299,8 +299,9 @@ module Sinatra
|
||||||
end
|
end
|
||||||
|
|
||||||
def template(name, &block)
|
def template(name, &block)
|
||||||
filename, line = caller_locations.first
|
first_location = caller_locations.first
|
||||||
templates[name] = [block, filename, line.to_i]
|
filename, line = first_location.path, first_location.lineno
|
||||||
|
templates[name] = [block, filename, line]
|
||||||
end
|
end
|
||||||
|
|
||||||
def layout(name=:layout, &block)
|
def layout(name=:layout, &block)
|
||||||
|
|
Loading…
Reference in a new issue