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 block.source_location to get the correct method name for a condition... #588

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/sinatra/base.rb
Expand Up @@ -1201,7 +1201,9 @@ def add_filter(type, path = nil, options = {}, &block)


# Add a route condition. The route is considered non-matching when the # Add a route condition. The route is considered non-matching when the
# block returns false. # block returns false.
def condition(name = "#{caller.first[/`.*'/]} condition", &block) def condition(name = nil, &block)
name ||= "#{caller.detect{|s| s[block.source_location]}[/`.*'/]} condition"

@conditions << generate_method(name, &block) @conditions << generate_method(name, &block)
end end


Expand Down