Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Separando as regras de negócios do Rails
Search
Celso Crivelaro
July 09, 2016
Programming
0
180
Separando as regras de negócios do Rails
Separando as regras de negócios do Rails
Celso Crivelaro
July 09, 2016
Tweet
Share
More Decks by Celso Crivelaro
See All by Celso Crivelaro
Sistemas de Recomendação
celsocrivelaro
2
210
Big Data para Gerentes de Projetos
celsocrivelaro
0
54
FileSystems em Ruby com FUSE
celsocrivelaro
2
64
Padrões e Boas Práticas de Teste de Tela
celsocrivelaro
0
410
Projeto de APIs
celsocrivelaro
0
150
Testing Network Conditions with ToxiProxy
celsocrivelaro
1
380
Testing Network Conditions with ToxiProxy
celsocrivelaro
0
80
Actor Model in Ruby
celsocrivelaro
0
250
InfluxDB + Grafana
celsocrivelaro
0
260
Other Decks in Programming
See All in Programming
AIともっと楽するE2Eテスト
myohei
9
3.2k
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
2
820
Streamlitで実現できるようになったこと、実現してくれたこと
ayumu_yamaguchi
2
230
iOS開発スターターキットの作り方
akidon0000
0
210
「次に何を学べばいいか分からない」あなたへ──若手エンジニアのための学習地図
panda_program
3
660
Google I/O Extended Incheon 2025 ~ What's new in Android development tools
pluu
1
200
LLMは麻雀を知らなすぎるから俺が教育してやる
po3rin
2
1.3k
変化を楽しむエンジニアリング ~ いままでとこれから ~
murajun1978
0
520
AIに安心して任せるためにTypeScriptで一意な型を作ろう
arfes0e2b3c
0
270
なぜあなたのオブザーバビリティ導入は頓挫するのか
ryota_hnk
3
510
SwiftでMCPサーバーを作ろう!
giginet
PRO
2
210
Workers を定期実行する方法は一つじゃない
rokuosan
0
130
Featured
See All Featured
Scaling GitHub
holman
461
140k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.6k
RailsConf 2023
tenderlove
30
1.2k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Unsuck your backbone
ammeep
671
58k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
How to Think Like a Performance Engineer
csswizardry
25
1.8k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Art, The Web, and Tiny UX
lynnandtonic
301
21k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Transcript
Separando as regras de negócio do Rails Celso Crivelaro @celsocrivelaro
DEVELOPER @
None
Rails revolucionou frameworks MVC
Convenção sobre Configuração Muitos plugins / gems Documentação Baixo tempo
para subir um projeto
Mas não são todos que concordam...
None
None
Onde está o problema?
Sua App não é o Rails
None
Controller Model View
View não é só HTML
Model não é ActiveRecord
Comunidade Ruby se preocupa pouco com Arquitetura OO
account.rb 439 linhas account_spec.rb 1045 linhas
Dificuldades no upgrade de versão do Rails Má arquitetura torna
os testes difíceis Alterações no software são caras Difícil de dividir a app em várias
Como podemos desacoplar?
Views
Entrada de dados
controllers/users_controller.rb views/users/new.html.erb
controllers/users_controller.rb
Fácil mas problemático
Cadastro em passos Formulário preenche vários modelos Diferentes interfaces: Web
+ API
https://gist.github.com/peternixey/1978249 Mass Assignment => Strong Parameters
Form Objects
forms/user_form.rb
controllers/users_controllers.rb
Exibição de dados
Presenter Objects
controllers/users_controllers.rb presenters/user_show_presenter.rb views/users/show.erb.html
Mock nos testes Favorece Duck-typing
Models
ActiveRecord
ORM Regras de preenchimento Quanto menos regras de negócio melhor
Evite usar callbacks
Regras de Consulta
Policy Objects
Tem sentido levar estes métodos para todo lado? Métodos de
checagem / permissionamento
policies/user_policy.rb
http://ruby-doc.org/stdlib-2.3.0/libdoc/forwardable/rdoc/Forwardable.html
Regras de Ação
Service Objects
Métodos de ação Usa vários modelos Lógica de negócio complexa
Usa várias integrações
services/user_billing_service.rb
Invocando alguns Design Patterns
Pipeline / Chain of Responsibility
None
Strategy
None
Dicas Finais
Estude muito OO Estude arquitetura OO Desacople o seu código
Tente fazer algo sem o Rails
Referências
http://solnic.eu/2016/05/22/my-time-with-rails-is-up.html
http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
None
None
None
None
Obrigado! @celsocrivelaro http://crivelaro.me