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

Off the Rails, on the way to Hanami

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?

weLaika

November 29, 2016
Tweet

More Decks by weLaika

Other Decks in Technology

Transcript

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

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

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

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

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

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

    -> lazy loading production -> eager loading Hanami -> eager loading only MINIMAL & LIGHTWEIGHT
  7. 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
  8. Torino Coding Society, 29 novembre 2016 RAILS PROJECT STRUCTURE app/

    |—assets/ |—controllers/ |—helpers/ |—models/ |—views/ bin/ config/ |—routes.rb db/ lib/ |—task/ test/
  9. 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/
  10. 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
  11. 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
  12. 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
  13. Torino Coding Society, 29 novembre 2016 HANAMI ACTIONS flying_trainer/ |—apps/

    |—airport/ |—controllers/ |—home/ |—index.rb |—pilots/ |—index.rb |—show.rb |—delete.rb |—planes/
  14. 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
  15. Torino Coding Society, 29 novembre 2016 HANAMI VIEWS flying_trainer/ |—apps/

    |—airport/ |—views/ |—home/ |—index.rb |—pilots/ |—index.rb |—show.rb |—delete.rb |—planes/
  16. 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
  17. 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/
  18. 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
  19. 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…
  20. Torino Coding Society, 29 novembre 2016 ROUTES • get '/foobars/:id',

    to: ‘controller#action' • post '/foobars/:id', to: ‘controller#action’ • resources :foobars • root ‘/’ any more…
  21. Torino Coding Society, 29 novembre 2016 PRO • Minimal and

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

    Deep knowledge of Ruby • Poor documentation CONS