Slide 1

Slide 1 text

❤ 
 Hello ruby kaigi! 
 ❤

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Japan is awesome

Slide 4

Slide 4 text

What have I learned here?

Slide 5

Slide 5 text

One ramen per day is normal

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Juice pack

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Tax free

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Anton Davydov github.com/davydovanton
 twitter.com/anton_davydov davydovanton.com

Slide 14

Slide 14 text

Stickers

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Hanami core

Slide 17

Slide 17 text

ruby rom-rb dry-rb rails crystal etc

Slide 18

Slide 18 text

moscow.rb

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Luca Guidi github.com/jodosha

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

General Ideas

Slide 23

Slide 23 text

Long-term maintenance

Slide 24

Slide 24 text

Modularity Forget about fat models

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Simplicity and Lightweight Framework is just a tool

Slide 27

Slide 27 text

Architecturally Sound Isolation everywhere

Slide 28

Slide 28 text

Zero Monkey-Patching Don’t think about framework or language

Slide 29

Slide 29 text

railshurts.com/quiz

Slide 30

Slide 30 text

railshurts.com/quiz

Slide 31

Slide 31 text

Threadsafe

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

hanami != rails

Slide 34

Slide 34 text

Typical parts of any web project

Slide 35

Slide 35 text

Web Project Business
 logic Data flow

Slide 36

Slide 36 text

Data flow

Slide 37

Slide 37 text

Container Architecture Clean Architecture

Slide 38

Slide 38 text

Project request

Slide 39

Slide 39 text

App App App request

Slide 40

Slide 40 text

App App App lib request

Slide 41

Slide 41 text

App App App lib App App App lib App App App lib request

Slide 42

Slide 42 text

App App App lib App App lib App App App lib request App

Slide 43

Slide 43 text

apps/ ├── admin │ ├── application.rb │ ├── assets │ │ └── ... │ ├── config │ │ └── ... │ ├── controllers │ │ └── ... │ ├── templates │ │ └── ... │ └── views │ └── ... └── web ├── ...

Slide 44

Slide 44 text

Business Logic

Slide 45

Slide 45 text

lib/ ├── project_name │ ├── interactors │ │ └── create_user.rb │ ├── entities │ │ └── user.rb │ ├── mailers │ │ └── templates │ └── repositories │ └── user_repository.rb └── project_name.rb

Slide 46

Slide 46 text

lib/ ├── project_name │ ├── interactors │ │ └── create_user.rb │ ├── entities │ │ └── user.rb │ ├── mailers │ │ └── templates │ └── repositories │ └── user_repository.rb └── project_name.rb

Slide 47

Slide 47 text

lib/ ├── project_name │ ├── interactors │ │ └── create_user.rb │ ├── entities │ │ └── user.rb │ ├── mailers │ │ └── templates │ └── repositories │ └── user_repository.rb └── project_name.rb

Slide 48

Slide 48 text

lib/ ├── project_name │ ├── interactors │ │ └── create_user.rb │ ├── entities │ │ └── user.rb │ ├── mailers │ │ └── templates │ └── repositories │ └── user_repository.rb └── project_name.rb

Slide 49

Slide 49 text

Gems

Slide 50

Slide 50 text

hanami - Base repository, CLI router - Rack compatible HTTP router for Ruby controller - Full featured and fast actions for Rack utils - Ruby core extensions and class utilities model - Persistence with entities and repositories

Slide 51

Slide 51 text

validations - Validations mixin for Ruby objects helpers - View helpers for Ruby applications view - Presentation with a separation assets - Assets management for Ruby mailer - Mail for Ruby applications

Slide 52

Slide 52 text

Differences

Slide 53

Slide 53 text

# rack class HelloApp def call(env) [200, { **env }, ['Hello!']] end end

Slide 54

Slide 54 text

# hanami-router class HelloApp def call(env) [200, { **env }, ['Hello!']] end end router = Hanami::Router.new router.get '/', to: 'hello_app'

Slide 55

Slide 55 text

# sinatra class Hello < Sinatra get '/' do 'Hello!' end end

Slide 56

Slide 56 text

# hanami Hanami::Router.new do get '/' do [200, { **env }, ['Hello!']] end end

Slide 57

Slide 57 text

Rails and Hanami

Slide 58

Slide 58 text

Controllers

Slide 59

Slide 59 text

class UsersController < AC def new end def send_sms end
 private def user_params end end Controllers: Rails

Slide 60

Slide 60 text

Controllers: hanami action module Web::Controllers::Board class Index include Web::Action params do required(:email).filled end def call(params) end end end

Slide 61

Slide 61 text

Controllers: hanami module Web::Controllers::Board class Index include Web::Action params do required(:email).filled end def call(params) end end end

Slide 62

Slide 62 text

Controllers: hanami module Web::Controllers::Board class Index include Web::Action params do required(:email).filled end def call(params) end end end

Slide 63

Slide 63 text

Model

Slide 64

Slide 64 text

class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems, through: :ownerships validates :name, presence: true # ... end Model: Rails

Slide 65

Slide 65 text

class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems, through: :ownerships validates :name, presence: true # ... end Model: Rails

Slide 66

Slide 66 text

class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems, through: :ownerships validates :name, presence: true # ... end Model: Rails

Slide 67

Slide 67 text

class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems, through: :ownerships validates :name, presence: true # ... end Model: Rails

Slide 68

Slide 68 text

class User < ActiveRecord::Base
 include Gravtastic before_destroy :yank_gems has_many :rubygems, through: :ownerships validates :name, presence: true # ... end Model: Rails

Slide 69

Slide 69 text

Model: hanami hanami + ROM = ❤ rom-rb.org

Slide 70

Slide 70 text

Model: hanami entity class User < Hanami::Entity # ... end

Slide 71

Slide 71 text

Model: hanami entity >> user = User.new(id: 1) => #1}> >> user.id => 1 >> user.id = 1 NoMethodError: undefined method `id=' for #1}> Did you mean? id

Slide 72

Slide 72 text

Model: hanami entity >> user = User.new(id: 1) => #1}> >> user.id => 1 >> user.id = 1 NoMethodError: undefined method `id=' for #1}> Did you mean? id

Slide 73

Slide 73 text

Model: hanami entity >> user = User.new(id: 1) => #1}> >> user.id => 1 >> user.id = 1 NoMethodError: undefined method `id=' for #1}> Did you mean? id

Slide 74

Slide 74 text

class UserRepository < Hanami::Repository associations do has_many :books end def find_by_name(name) users # => ROM relation users.where(name: name).limit(1).order { id }.one end end Model: hanami repository

Slide 75

Slide 75 text

>> repo = UserRepository.new => # >> repo.find(1) => # >> repo.find_by_name(‘Anton’) => # Model: hanami repository

Slide 76

Slide 76 text

View

Slide 77

Slide 77 text

View: Rails rails view (partials?) + rails helper

Slide 78

Slide 78 text

View: Hanami hanami view (ruby class) + templates

Slide 79

Slide 79 text

Assets

Slide 80

Slide 80 text

Pros and Cons

Slide 81

Slide 81 text

No magic

Slide 82

Slide 82 text

module Web::Controllers::Board class Index include Web::Action def call(params) end end end

Slide 83

Slide 83 text

Action test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[] } it 'is successful' do response = action.call(params) response[0].must_equal 200 end end

Slide 84

Slide 84 text

Action test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[] } it 'is successful' do response = action.call(params) response[0].must_equal 200 end end

Slide 85

Slide 85 text

Action test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[] } it 'is successful' do response = action.call(params) response[0].must_equal 200 end end

Slide 86

Slide 86 text

No monkey-patching

Slide 87

Slide 87 text

Best practices

Slide 88

Slide 88 text

Dependency Injection

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

The logic separation

Slide 91

Slide 91 text

Interactors out the box

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

TDD

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

TDD

Slide 98

Slide 98 text

Good but not great documentation

Slide 99

Slide 99 text

Missing Gems

Slide 100

Slide 100 text

WebSockets
 Pagination
 WebPack GraphQL
 Devise 2016

Slide 101

Slide 101 text

WebSockets
 Pagination
 WebPack GraphQL
 Devise Now

Slide 102

Slide 102 text

awesome-hanami.org

Slide 103

Slide 103 text

Projects are good
 for new contributors

Slide 104

Slide 104 text

www.ossboard.org

Slide 105

Slide 105 text

octostar.herokuapp.com

Slide 106

Slide 106 text

contributors.hanamirb.org

Slide 107

Slide 107 text

Contacts hanamirb.org gitter.im/hanami/chat discuss.hanamirb.org

Slide 108

Slide 108 text

github.com/davydovanton
 twitter.com/anton_davydov davydovanton.com Thank you ❤