Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Off the Rails, on the way to Hanami

E22edc988280c3b6ff183318bc1590c2?s=47 weLaika
November 29, 2016

Off the Rails, on the way to Hanami

Ritorniamo a parlare di framework per applicazioni web con Hanami!

Hanami offre un’incredibile velocità grazie ai suoi componenti minimalisti e un approccio multi-applicazione .

Un framework così giovane sarà in grado di reggere il confronto con un titano come Rails?

E22edc988280c3b6ff183318bc1590c2?s=128

weLaika

November 29, 2016
Tweet

Transcript

  1. OFF THE RAILS ON THE WAY TO HANAMI Torino Coding

    Society, 29 novembre 2016
  2. Torino Coding Society, 29 novembre 2016 WHO AM I STEFANO

    PAU Web Developer @ weLaika @ramensoup7
  3. Torino Coding Society, 29 novembre 2016 WHAT IS HANAMI Web

    Framework for Ruby LUCA GUIDI @jodosha
  4. Torino Coding Society, 29 novembre 2016 WHY HANAMI • A

    valid alternative • Minimal and lightweight • Force the developer to write neatly • Modular approach
  5. LIGHTWEIGHT Torino Coding Society, 29 novembre 2016 MINIMAL

  6. MINIMAL & LIGHTWEIGHT Torino Coding Society, 29 novembre 2016 NEW

    PROJECT 20 40 60 80 Mb Sinatra Hanami Rails 100 (Ruby 2.3.0)
  7. Torino Coding Society, 29 novembre 2016 SAME PROJECT 20 40

    60 80 Mb Sinatra Hanami Rails 100 MINIMAL & LIGHTWEIGHT (Ruby 2.3.0)
  8. Torino Coding Society, 29 novembre 2016 CONSTANTS AUTOLOADING Rails {development/test

    -> lazy loading production -> eager loading Hanami -> eager loading only MINIMAL & LIGHTWEIGHT
  9. Torino Coding Society, 29 novembre 2016 MINIMAL & LIGHTWEIGHT Version:

    0.1 - 0.8: • associations not implemented • manual mapping 0.9: • experimental associations • auto-mapping TOO MUCH
  10. RAILS Torino Coding Society, 29 novembre 2016 DIFFERENT APPROACH THAN

  11. Torino Coding Society, 29 novembre 2016 RAILS PROJECT STRUCTURE app/

    |—assets/ |—controllers/ |—helpers/ |—models/ |—views/ bin/ config/ |—routes.rb db/ lib/ |—task/ test/
  12. Torino Coding Society, 29 novembre 2016 HANAMI PROJECT STRUCTURE apps/

    |—app1/ |—assets/ |—config/ |—routes.rb |—controllers/ |—templates/ |—views/ app2/ […] config/ db/ lib/ spec/ lib/ |—project_name/ |—entities/ |—repositories/
  13. Torino Coding Society, 29 novembre 2016 HANAMI MODELS flying_trainer/ |—apps/

    |—airport/ |—api/ |—dashboard/ |—lib/ |—flying_trainer/ |—entities/ |—pilot.rb |—plane.rb |—repositories/ |—pilot_repository.rb |—plane_repository.rb
  14. Torino Coding Society, 29 novembre 2016 HANAMI REPOSITORIES class PilotRepository

    < Hanami::Repository def self.pilots pilot_db.all end def self.delete_last_pilot pilot_db.delete(pilot_db.last) end private def pilot_db new end end
  15. Torino Coding Society, 29 novembre 2016 HANAMI ENTITIES class Pilot

    < Hanami::Entity attr_accessor :flag def flagged flag = true end def flagged? return true if flag end end
  16. Torino Coding Society, 29 novembre 2016 HANAMI ACTIONS flying_trainer/ |—apps/

    |—airport/ |—controllers/ |—home/ |—index.rb |—pilots/ |—index.rb |—show.rb |—delete.rb |—planes/
  17. Torino Coding Society, 29 novembre 2016 HANAMI ACTIONS module Airport::Controllers::Pilots

    class Index include Airport::Action expose :pilots, :first_pilot def call(params) @pilots = PilotRepository.all_pilots @first_pilot = @pilots.first @some_pilots = PilotRepository.all_pilots end end end
  18. Torino Coding Society, 29 novembre 2016 HANAMI VIEWS flying_trainer/ |—apps/

    |—airport/ |—views/ |—home/ |—index.rb |—pilots/ |—index.rb |—show.rb |—delete.rb |—planes/
  19. Torino Coding Society, 29 novembre 2016 HANAMI VIEWS module Airport::Views::Pilots

    class Show include Airport::View def capitalized_first_pilot first_pilot.name.capitalize end end end
  20. Torino Coding Society, 29 novembre 2016 HANAMI TEMPLATES flying_trainer/ |—apps/

    |—airport/ |—templates/ |—home/ |—index.html.erb |—pilots/ |—index.html.erb |—show.html.erb |—planes/
  21. Torino Coding Society, 29 novembre 2016 MODULES OR MONOLITH

  22. Torino Coding Society, 29 novembre 2016 MONOLITH a good solution

    for the first 2-3 years, but then…
  23. None
  24. Torino Coding Society, 29 novembre 2016 MODULAR • easy maintenance

    • you can start to build a monolith, but you can easily pass to a modular structure
  25. Torino Coding Society, 29 novembre 2016 SOMETHING ELSE

  26. Torino Coding Society, 29 novembre 2016 COMMAND LINE • hanami

    new project • hanami generate app action model migration mailer • hanami routes • hanami db create drop prepare any more…
  27. Torino Coding Society, 29 novembre 2016 ROUTES • get '/foobars/:id',

    to: ‘controller#action' • post '/foobars/:id', to: ‘controller#action’ • resources :foobars • root ‘/’ any more…
  28. Torino Coding Society, 29 novembre 2016 DATABASE • MySQL •

    PostgreSQL • SQLite3
  29. Torino Coding Society, 29 novembre 2016 PRO • Minimal and

    lightweight • Force the developer to write neatly • Modular approach
  30. Torino Coding Society, 29 novembre 2016 • Crude framework •

    Deep knowledge of Ruby • Poor documentation CONS
  31. Torino Coding Society, 29 novembre 2016 SOME INFOS • hanamirb.org

    • awesome-hanami.org
  32. QUESTIONS ANSWERS

  33. Torino Coding Society, 29 novembre 2016 THANK YOU EVERYBODY