Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

What would you like to complain about? [ ] Too much magic [ ] Too much boilerplate source: @phillip_webb

Slide 3

Slide 3 text

What would you like to complain about? [ ✔ ] Too much magic [ ] Too much boilerplate source: @phillip_webb

Slide 4

Slide 4 text

ARJAN VAN DER GAAG (@AVDGAAG) HANAMI …because sometimes, you need to
 re-invent the wheel

Slide 5

Slide 5 text

ARJAN VAN DER GAAG arjanvandergaag.nl • @avdgaag • brightin

Slide 6

Slide 6 text

“Hanami is a Ruby MVC web framework comprised of many micro-libraries. It has a simple, stable API, a minimal DSL, and prioritises the use of plain objects over magical, over-complicated classes with too much responsibility.”

Slide 7

Slide 7 text

“The natural repercussion of using simple objects with clear responsibilities
 is more boilerplate code.”

Slide 8

Slide 8 text

ARJAN VAN DER GAAG (@AVDGAAG) CONTROLLER

Slide 9

Slide 9 text

ARJAN VAN DER GAAG (@AVDGAAG) class Create include Web::Action def call(params) # book = ... redirect_to routes.book_path(book.id) end end

Slide 10

Slide 10 text

ARJAN VAN DER GAAG (@AVDGAAG) class Create include Web::Action params do param :book do param :pages, type: Integer, size: 0..9999 param :title, presence: true end end def call(params) if params.valid? # ... end end end

Slide 11

Slide 11 text

ARJAN VAN DER GAAG (@AVDGAAG) MINIMAL INTERFACES

Slide 12

Slide 12 text

ARJAN VAN DER GAAG (@AVDGAAG) class Show include Web::Action expose :book def call(params) @book = BookRepository.find(params[:id]) end end

Slide 13

Slide 13 text

ARJAN VAN DER GAAG (@AVDGAAG) RSpec.describe Show do it 'is successful' do response = Show.new.call('id' => '1') expect(response[0]).to eql(200) end end

Slide 14

Slide 14 text

ARJAN VAN DER GAAG (@AVDGAAG) class Show include Web::Action expose :book def initialize(repository: BookRepository) @repository = repository end def call(params) @book = @repository.find(params[:id]) end end

Slide 15

Slide 15 text

ARJAN VAN DER GAAG (@AVDGAAG) RSpec.describe Show do it 'exposes the book found in the repository' do book = Book.new action = Show.new(repository: double(find: book)) action.call('id' => '1') expect(action.exposures[:book]).to be(book) end end

Slide 16

Slide 16 text

ARJAN VAN DER GAAG (@AVDGAAG) VIEW

Slide 17

Slide 17 text

ARJAN VAN DER GAAG (@AVDGAAG) class ApplicationController < ActionController::Base helper :all end

Slide 18

Slide 18 text

ARJAN VAN DER GAAG (@AVDGAAG) module Web::Views::Books class Index include Web::View end end

Slide 19

Slide 19 text

ARJAN VAN DER GAAG (@AVDGAAG) module Web::Views::Books class Index include Web::View def render 'hello, world' end end end

Slide 20

Slide 20 text

ARJAN VAN DER GAAG (@AVDGAAG) module Web::Views::Books class Index include Web::View include MyHelper end end

Slide 21

Slide 21 text

ARJAN VAN DER GAAG (@AVDGAAG) module Web::Views::Books class Index include Web::View def books locals[:books] end end end

Slide 22

Slide 22 text

ARJAN VAN DER GAAG (@AVDGAAG) module Web::Views::Books class Index include Web::View def books locals[:books].map do |book| Web::Presenters::BookPresenter.new(book) end end end end

Slide 23

Slide 23 text

ARJAN VAN DER GAAG (@AVDGAAG) module Web::Presenters class BookPresenter include Hanami::Presenter def title super.upcase end end end

Slide 24

Slide 24 text

ARJAN VAN DER GAAG (@AVDGAAG) module Web::Presenters class BookPresenter include Hanami::Presenter def title super.upcase end end end book = Book.new(title: 'Pride & Prejudice') presenter = Web::Presenters::BookPresenter.new(book) presenter.title # => "PRIDE & PREJUDICE"

Slide 25

Slide 25 text

ARJAN VAN DER GAAG (@AVDGAAG) MODEL

Slide 26

Slide 26 text

ARJAN VAN DER GAAG (@AVDGAAG) class Book include Hanami::Entity attributes :title, :author, :pages end Book.new(title: '1984') # => #

Slide 27

Slide 27 text

ARJAN VAN DER GAAG (@AVDGAAG) class BookRepository include Hanami::Repository end BookRepository.find(1) # => # BookRepository.persist(Book.new(title: '1984')) # => #

Slide 28

Slide 28 text

ARJAN VAN DER GAAG (@AVDGAAG) class AccountRepository include Hanami::Repository def self.find_by_username(username) query do where(username: username) end.first end end

Slide 29

Slide 29 text

ARJAN VAN DER GAAG (@AVDGAAG) MONOLITH FIRST

Slide 30

Slide 30 text

LIB APPS/WEB

Slide 31

Slide 31 text

LIB APPS/WEB APPS/API

Slide 32

Slide 32 text

LIB APPS/WEB APPS/ADMIN APPS/API

Slide 33

Slide 33 text

ARJAN VAN DER GAAG (@AVDGAAG) WASTE OF EFFORT TO RE- CREATE LOTS OF MOSTLY THE SAME TOOLS?

Slide 34

Slide 34 text

ARJAN VAN DER GAAG (@AVDGAAG) SOMETIMES, YOU NEED TO
 RE-INVENT THE WHEEL

Slide 35

Slide 35 text

“With large, ongoing software projects, a lot of the features that help with simple demo apps become irrelevant. Or worse, they become disadvantages and bottlenecks, and sometimes downright obstacles to any further development.” Filip Hracek, The ‘Hello World’ Fallacy

Slide 36

Slide 36 text

ARJAN VAN DER GAAG (@AVDGAAG) SIMPLICITY > CONVENIENCE

Slide 37

Slide 37 text

ARJAN VAN DER GAAG (@AVDGAAG) YOU’RE WRITING RUBY

Slide 38

Slide 38 text

What would you like to complain about? [ ✔ ] Too much magic [ ] Too much boilerplate source: @phillip_webb

Slide 39

Slide 39 text

ARJAN VAN DER GAAG (@AVDGAAG) SEE HANAMIRB.ORG

Slide 40

Slide 40 text

ARJAN VAN DER GAAG (@AVDGAAG) EMACS INTEGRATION https://github.com/avdgaag/projectile-hanami

Slide 41

Slide 41 text

ARJAN VAN DER GAAG arjanvandergaag.nl • @avdgaag • brightin