Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A lightning-fast, batteries-included Ruby web micro-framework.

License

NotificationsYou must be signed in to change notification settings

joshmn/jeanine

Repository files navigation

A Ruby micro-web-framework that gives you enough training wheels to be productive, while being as nearly as fast as Rack itself.

Its design (and some parts of the code) is influenced by/inherited from (thanks!) Ruby on Rails, Rack::App, Hobbit, and Cuba. Without them this is nothing.

jeanine logo

Name

Named after my mom. Because she was the best.

Installation

Add this line to your application's Gemfile:

gem'jeanine'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install jeanine

Basic usage

Drop this intoconfig.ru:

require'bundler/setup'require'jeanine'classApp <Jeanine::Approotdo"Hello world"endendrunApp

$ rackup

Or generate a new app:

$ gem install jeanine$ jeanine new my_api$ cd my_api$ bundle$ rackup

Advanced usage

classApp <Jeanine::Apppath"/posts"dogetdoifrequest.json?renderjson:[]else"Posts index"endendget"new"do"Posts new"endpostdo"Posts post"endpath":id"dogetdo"Posts#{params[:id]}"endmatchvia:[:put,:patch]do"Posts#{request.via}#{params[:id]}"enddeletedo"Posts delete#{params[:id]}"endpath"/comments"dogetdo"Posts#{params[:id]} comments"endendendendend

Plugins

Callbacks

Supportsbefore andafter callbacks (same DSL):

classApp <Jeanine::Appplugin:Callbacksbeforedoputs"All"endbefore/posts/doputs"Before posts"endbefore/posts\/\d*/,/comments\/\d*/doputs"Before posts/:id, comments/:id"response.headers['X-Thing-Id']=params[:id]endend

Rendering

Basic support for rendering. Be explicit.

classApp <Jeanine::Appplugin:Rendering# loads views/root.html.erb and views/layouts/application.html.erbrootdo@title="My cool app"rendertemplate:"root.html.erb",layout:"application.html.erb"endend

Sessions

Uses Rack's session management.

classApp <Jeanine::Appplugin:Sessionrootdosession[:uid]=SecureRandom.hexendend

Error handling

classApp <Jeanine::Appplugin:Rescuablerescue_fromNoMethodError,RuntimeErrordo |exception|response.status=500"Oh no!"endrescue_fromStandardError,with::handle_error!rootdo@title="My cool app"raiseNoMethodErrorrendertemplate:"root.html.erb",layout:"application.html.erb"endprivatedefhandle_error!(exception)response.status=500rendertemplate:"error.html.erb"endend

Development

Ideologies

  • No meaningless metaprogramming = fast

Benchmarks

Requests/second

Benched on a Intel Core i7-8700B / 64GB RAM.

Framework            Requests/sec  % from best----------------------------------------------rack                     17299.31      100.00%jeanine                  16022.71       92.62%rack-response            15462.50       89.38%syro                     15416.13       89.11%watts                    15307.52       88.49%roda                     14550.56       84.11%hanami-router            14342.92       82.91%cuba                     14246.23       82.35%hobbit                   14132.20       81.69%rambutan                 12526.40       72.41%rack-app                 11696.66       67.61%flame                     7931.61       45.85%rails-metal               7761.75       44.87%sinatra                   4616.81       26.69%grape                     2401.66       13.88%hobby                     1805.93       10.44%rails-api                 1593.77        9.21%

Memory

Framework       Allocs/Req Memsize/Req--------------------------------------rack                    40        3408roda                    43        4016syro                    44        4288cuba                    44        4056watts                   46        3648hobbit                  48        4416jeanine                 52        4576hobby                   52        5416rack-response           55        5128rails-metal             59        5848hanami-router           63        5184rambutan                79        6944rack-app                80        8424flame                  115        9648sinatra                179       13440grape                  250       26704rails-api              383       34949

Todo

  • Callback constraints
  • File downloads

Contributing

Bug reports and pull requests are welcome on GitHub athttps://github.com/joshmn/jeanine.

License

The gem is available as open source under the terms of theMIT License.

About

A lightning-fast, batteries-included Ruby web micro-framework.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp