A minimal Ruby framework with fire in its heart
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:
class App 'txt'}, ['Hello World!']]}
end
run HelloWorldRoute handlers are anything that respond to call and return a valid Rack response. All the http verbs you expect are available:
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:
signed_in? and current_user?render helper for templating.js('jquery', 'app'), css('app') etcStart by adding the following to your gemfile:
gem 'edlr'Then run bundler:
$ bundle installNow create a new file called app.rb with the following contents:
class App path}, [message]]
end
endIn 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:
class Handler
def call(env)
Rack::Response.new "Hi there Dave!"
end
end
class App
get '/', Handler.new
endThis 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:
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 CatsControllerOnce 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.
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:
RSpec.configure do |config|
config.include Rack::Test::Methods
endNow 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:
def app
YourEldrApp.new
endIf you want to test each of your apps individually you can use let to create a new Rack::Test session thingy:
let(:rt) do
Rack::Test::Session.new YourEldrApp.new
endThen you'll be able to access the rack-test methods from rt. For example:
response = rt.get '/'
response.status.should == 200Rack apps sure are easy to work with!
See the spec/ in this repo for some specific rspec examples.
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
You can get help from the following places:
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!
Licensed under MIT by K-2052.
No open issues yet, or sync has not completed.