Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

eldr

> 编程语言
Open source

A minimal Ruby framework with fire in its heart

99 stars0 likes1 views
WebsiteGitHub

About

A minimal Ruby framework with fire in its heart

Eldr

Eldr is a minimal ruby framework that doesn't hide the rack. It aims to be lightweight, simple, modular and above all, clear. Eldr is a ruby framework without all the magic.

Eldr apps are rack apps like this:

ruby
class App  'txt'}, ['Hello World!']]}
end

run HelloWorld

Route handlers are anything that respond to call and return a valid Rack response. All the http verbs you expect are available:

ruby
get '/',  proc { [200, {'Content-Type' => 'txt'}, ['Hello World!']]}
post '/', proc { [201, {'Content-Type' => 'txt'}, ['Hello World!']]}

etc...

For further usage examples checkout the examples folder

I have already built and released extensions for many common tasks:

  • eldr-sessions: session helpers like signed_in? and current_user?
  • eldr-rendering: a render helper for templating.
  • eldr-assets: asset tag helpers like js('jquery', 'app'), css('app') etc
  • eldr-responders: rails-responder like helpers
  • eldr-action: Action Objects

Quickstart Guides

Hello World

Start by adding the following to your gemfile:

ruby
gem 'edlr'

Then run bundler:

$ bundle install

Now create a new file called app.rb with the following contents:

ruby
class App  path}, [message]]
  end
end

Route Handlers: The Power of Action Objects

In Edlr (just like in Rack) route handlers are things that respond to call. This means we can use everthing from procs, to blocks, to instances of a class.

If we wanted to we could do the following:

ruby
class Handler
  def call(env)
    Rack::Response.new "Hi there Dave!"
  end
end

class App
  get '/', Handler.new
end

This isn't as silly as it might seem. Its a common and powerful pattern that can clean up complex controllers.

Imagine we have a complex show action that takes up hundreds of lines. Our first inclination will be to split this up into different methods on our controller. This would make our show action a lot shorter; but we would have logic for our show action spread across our controller. Our other actions don't need to be able to access the show action's logic. It would be better to have all the logic for the show action in one object.

We can do this by writing our show action as an Action Object. Our action's logic will be contained entirely in this object.

Action objects give us the freedom to instantiatie them, inject things, pass them around, test and generally just engage in whatever sociopathic whimsys we might want to do to them.

Let's take a look at that show action:

ruby
class Show
  attr_accessor :env

  def helper_logic
    # do things here
  end

  def params
    env['eldr.params']
  end

  def call(env)
    @env = env

    helper_logic
    # @cat = Cat.find params[:id]
    Rack::Response.new "Found cat named #{params['name'].capitalize}!"
  end
end

class CatsController
  get '/cats/:name', Show.new
end

run CatsController

Once you start using this pattern you cant stop. Like nutella, you start putting it on everything, trying it on absurd things you know are wrong -- just in case it might work well.

Don't overuse action objects, but remember they are there when you want deliciousness.

Testing Eldr Apps

You are ready to set out on your own but you are afraid of breaking all the things. You need some safety checks to keep you from hurting yourself or your apps. Testing Eldr apps is the same as testing rack apps.

In your spec helper include rack-test. With rspec that would look like this:

ruby
RSpec.configure do |config|
  config.include Rack::Test::Methods
end

Now you need to define your app method so rack-test can mount your app. Eldr apps are rack apps so we can simply return a new instance of it:

ruby
def app
  YourEldrApp.new
end

If you want to test each of your apps individually you can use let to create a new Rack::Test session thingy:

ruby
let(:rt) do
  Rack::Test::Session.new YourEldrApp.new
end

Then you'll be able to access the rack-test methods from rt. For example:

ruby
response = rt.get '/'
response.status.should == 200

Rack apps sure are easy to work with!

See the spec/ in this repo for some specific rspec examples.

Performance

Eldr has been built with perfomance in mind. Right now it performs in the middle of the pack and more performance improvements are forthcoming:

Framework Requests/sec % from best
rack 10282.20 100.0%
hobbit 8853.81 86.11%
roda 8830.00 85.88%
cuba 8517.00 82.83%
lotus-router 8464.81 82.32%
rack-response 7939.67 77.22%
brooklyn 7639.88 74.3%
eldr 7170.15 69.73%
rambutan 6954.75 67.64%
nancy 6516.84 63.38%
gin 3850.00 37.44%
nyny 3745.96 36.43%
sinatra 2740.50 26.65%
rails 2475.50 24.08%
scorched 1692.18 16.46%
ramaze 1490.42 14.5%

See the bench-micro repo to run your own perfomance benchmarks

Help/Resources

You can get help from the following places:

  • @k_2052 Feel free to mention me on twitter for quick questions
  • The Mailing List For questions that aren't a bug or feature request
  • The examples folder in this repo has full runnable versions of the quickstart's examples
  • BuildYourOwnSinatra.com A companion book on building Eldr
  • Issues on this repo for bug reports and feature requests
  • And of course checkout the GitHub org eldr-rb/ for all the Eldr gems.

Contributing

  1. Fork. it
  2. Create. your feature branch (git checkout -b cat-evolver)
  3. Commit. your changes (git commit -am 'Add Cat Evolution')
  4. Test. your changes (always be testing)
  5. Push. to the branch (git push origin cat-evolver)
  6. Pull. Request. (for extra points include funny gif and or pun in comments)

To remember this you can use the easy to remember and totally not tongue-in-check initialism: FCCTPP.

I don't want any of these steps to scare you off. If you don't know how to do something or are struggle getting it to work feel free to create a pull request or issue anyway. I'll be happy to help you get your contributions up to code and into the repo!

License

Licensed under MIT by K-2052.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言