百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
E

eldr

> 编程语言
开源

一个具有核心灵魂的最小 Ruby 框架

99 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个具有核心灵魂的最小 Ruby 框架

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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