Harbor Framework We've got you covered.
One of our major focuses is simplicity, but that doesn't mean we're short on features. You can check out the documentation, but here's an overview of some of the features of Harbor.
Ports
We call Harbor applications "ports" — and we find that it's an appropriate metaphor for how Harbor applications can be assembled. Harbor makes it trivial to extract common functionality from applications to create common components. You can take a look at some of our own open sourced ports to get ideas.
Need to change a view from an existing port? Not a problem! Harbor maintains an array of view paths which allows you to selectively alter existing views, as well as supporting a generic plugin system for views. Need to add add some bit of functionality? We've got support for both events and hooks. And of course, you can always re-route the request.
API Stability
No one likes it when APIs break for no reason. So here's our promise: we're not going to break interfaces between releases unless it's really necessary — because we don't have any more time than you do to rewrite an existing application.
Active Support
We use Harbor every day to develop and maintain over a dozen public sites. Long-lingering bugs are simply not an option. If you run into a bug, send us an email, or even better, a pull request on GitHub, and it will be fixed.
If you need additional help, please contact us to discuss a plan for paid support.
And More...
There's much more, of course, to Harbor so here's a quick rundown of some of the other features we love about Harbor.
Harbor::Container
Harbor includes a simple accessor-based dependency injector called Harbor::Container. It's what allows us to easily configure services and still use POROs wherever possible. For example, when you want to route actions to controllers, it will use the container you provide to retrieve the controller and set @request, @response, and any other necessary services (such as a logger or mailer). Below is a fully functional application using a container and controller.
# config.ru
require "rubygems"
require "harbor"
require "logger"
class UserManagement < Harbor::Application
def self.routes(services)
Harbor::Router.new do
using services, Users do
get("/users/:id") do |users, request|
users.show(request["id"])
end
end
end
end
end
class Users
attr_accessor :request, :response, :logger
def show(id)
logger.info "Viewing #{id}." if logger
response.puts "Viewing #{id}"
end
end
services = Harbor::Container.new
services.register("logger", Logger.new($stdout, :debug))
run UserManagement.new(services, "development")
This makes it really easy to test your controllers, emails, scripts, and more:
services.register("users", Users)
services.register("request", Harbor::Test::Request)
services.register("response", Harbor::Test::Response)
users = services.get("users")
assert_nothing_raised { users.show(1) }
Harbor::Events and Harbor::Hooks
More features which helps make it easy to re-use applications:
class Users
include Harbor::Events
include Harbor::Hooks
before :update do
# ...
end
def update(id, params)
user = User.get(id)
user.update_attributes(params)
raise_event :user_updated, user
end
end
Users.register_event(:user_updated) do |user|
# ...
end
Harbor::Mailer
Harbor includes a fully-featured email system built on our own mail_builder gem, with configurable mail servers (Harbor includes both Sendmail and SMTP support). Best of all, Harbor mailers will accept anything that responds to #to_s as the HTML and Plain-Text bodies:
# config.ru
services.register("mail_server", Harbor::MailServers::Sendmail)
services.register("mailer", Harbor::Mailer)
# controllers/account
class Account
attr_accessor :mailer
def update(id, params)
mailer.html = Harbor::View.new("mailers/account/updated", :user => user)
mailer.text = Harbor::View.new("mailers/account/updated.txt.erb", :user => user)
mailer.send!
end
end
Harbor::Daemon
Writing daemonizable scripts may not be something you have to write every day, but when you need them they're indispensable. Harbor::Daemon makes it possible to write reliable and testable scripts.
Harbor::Contrib::Debug
Harbor includes a great debugging bar in the form of a Rack Middleware, which can help you keep an eye on your page with load time, query count, and any messages dumped to the logger:
And of course you can click to get more details: