Sinatra::Bind
Binds instance method to routes.
Installation
Add this line to your application's Gemfile:
gem 'sinatra-bind'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sinatra-bind
Usage
You can define a route without block smoothly.
class App < Sinatra::Base
register Sinatra::Bind
def index
"hello world"
end
on "/", to: :index
end
If specified the :type option, it will be used as request method.
class App < Sinatra::Base
register Sinatra::Bind
def index
"hello world"
end
on "/", to: :index, type: :post
end
If passed :before
or :after
inn the :type
option, it will be added as the filters.
class App < Sinatra::Base
register Sinatra::Bind
def before_index
@foo = "bob"
end
def index
"hello #{@foo}"
end
on "/", to: :before_index, type: :before
on "/", to: :index
end
Contributing
- Fork it ( https://github.com/namusyaka/sinatra-bind/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request