I just started playing with Sinatra today in the effort to create a
very simple database application. My goal is a simple REST service
that you hand hierarchical keys like "/Service/LDAP" and it hands you
back a value like "
ldap.example.com." I want some of these keys to be
user-specific, so I wired in LDAP authentication (amazing that this
works as easily as it does).
So I keep winding up with blocks that look like this (protected! is
based on the code from the FAQ; ignore the fact that "system version"
probably shouldn't require login):
get '/System/version' do
protected!
{ '/System/version' => '0.1' }.to_json
end
I'd like to pull out the common code in something like this:
def value(key, &block)
get key do
{ key => block.call }.to_json
end
end
value '/System/version' do
protected!
'0.1'
end
But if I do this, then the block won't be able to see protected! when
it executes. If I move value() into helpers, then my main code can't
see it.
Similarly, is there any way to get the name of the current route in
the block? There's params, but I want the entire string, and I can't
find a value in params that gives me that.
Thanks,
-Rob