HANAMI FOR RAILS DEVELOPERS AGENDA ▸ What is Hanami? ▸ Architecture and key features ▸ Container architecture ▸ Models ▸ Views and templates ▸ Controllers and actions ▸ Practical basics ▸ What’s hot and what’s not
HANAMI FOR RAILS DEVELOPERS WHAT IS HANAMI? ▸ “Hanami is a modern web framework for Ruby” created by Luca Guidi ▸ Promoting incremental design and separation of concerns beyond traditional MVC ▸ Multi application approach - container architecture
HANAMI FOR RAILS DEVELOPERS CONTAINER ARCHITECTURE ▸ Hanami architecture can host several applications in the same Ruby process ▸ Each of them can be a component, such as the user facing web interface, the admin pane, metrics, HTTP API etc. ▸ These apps are a delivery mechanism to the business logic that lives under lib/ (entities, repositories, mailers) ▸ Generators: hanami new demoapp --application_name=api hanami generate app admin
HANAMI FOR RAILS DEVELOPERS MODELS ▸ Model = Entity + Repository ▸ Entities hold the models attributes, but it doesn't deal with the persistence layer ▸ Repositories are responsible for dealing with the persistence of entities (storage independent) ▸ Shared between the Hanami applications ▸ Querying methods (like where, limit, order) are private to the repository context
HANAMI FOR RAILS DEVELOPERS VIEWS AND TEMPLATES ▸ Rails views == Hanami templates ▸ A view is an object that's responsible for rendering a template ▸ Partials, similar to Rails ▸ Presenters included in framework ▸ Many supported rendering engines, including ERb, Haml, Slim, CoffeeScript, SASS etc.
HANAMI FOR RAILS DEVELOPERS CONTROLLERS AND ACTIONS ▸ Controllers are simply modules that group many actions together ▸ Controller actions are classes (single responsibility!) ▸ Using expose method to expose variable of the action with the view ▸ Validations are performed in Controller Actions using dry- validations ▸ Callbacks support, easy error handling etc.
HANAMI FOR RAILS DEVELOPERS class Admin::UsersController < ActionController::Base def index @users = User.all end def show @user = User.find_by(id: params[:id]) end end RUBY ON RAILS app/controllers/admin/users_controller.rb
HANAMI FOR RAILS DEVELOPERS module Admin::Controllers::Users class Index include Admin::Action expose :users def call(params) @users = UserRepository.new.all end end end module Admin::Controllers::Users class Show include Admin::Action expose :user def call(params) @user = UserRepository.new.find(id: params[:id]) end end end HANAMI apps/admin/controllers/users/index.rb apps/admin/controllers/users/show.rb
HANAMI FOR RAILS DEVELOPERS WHAT’S HOT… ▸ Default architecture and conventions that make the app scalable and easy to test ▸ Working and maintained alternative for Rails ▸ Strong CLI
HANAMI FOR RAILS DEVELOPERS …AND WHAT’S NOT ▸ Immature in terms of ecosystem - the community is still young, most popular gems are targeting Rails ▸ Be prepared to "roll up your sleeves" to get to the bottom of issues, figure how to do things that aren't covered by the guides