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
170
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
200
Big Data para Gerentes de Projetos
celsocrivelaro
0
45
FileSystems em Ruby com FUSE
celsocrivelaro
2
55
Padrões e Boas Práticas de Teste de Tela
celsocrivelaro
0
390
Projeto de APIs
celsocrivelaro
0
140
Testing Network Conditions with ToxiProxy
celsocrivelaro
1
330
Testing Network Conditions with ToxiProxy
celsocrivelaro
0
77
Actor Model in Ruby
celsocrivelaro
0
230
InfluxDB + Grafana
celsocrivelaro
0
240
Other Decks in Programming
See All in Programming
Clean Architecture by TypeScript & NestJS
ryounasso
0
150
【Go言語】ジェネリクス
tomo1227
0
170
なぜ宣言的 UI は壊れにくいのか / Why declarative UI is less fragile
uenitty
29
13k
わかりやすい正解を捨てて、コトに向き合う - スクラムフェス金沢2024 スポンサーセッション
yusukekokubo
0
170
大規模マルチテナントを解決するYugabyteDBという選択肢
nnaka2992
1
250
Trial
cairolibrary720
1
130
HMSコンペ 11th Solution (team : kansai-kaggler)
t88
1
680
Xcode 16のPreviewModifierと@Previewableを活用した効率的なプレビュー方法の考察
ojun9
2
160
さきがけから振り返るアーキテクチャ刷新 / Reflecting on the Architectural Renewal from the Vanguard
nrslib
2
770
英語
s_shimotori
1
220
はしめてのプログラミングとロボット制御
watawatavoltage
0
290
CSC307 Lecture 10
javiergs
PRO
0
310
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
12
3.8k
Unsuck your backbone
ammeep
666
57k
Bash Introduction
62gerente
607
210k
Scaling GitHub
holman
458
140k
Build your cross-platform service in a week with App Engine
jlugia
227
17k
GraphQLとの向き合い方2022年版
quramy
36
13k
Clear Off the Table
cherdarchuk
89
320k
The Mythical Team-Month
searls
217
43k
A Modern Web Designer's Workflow
chriscoyier
689
190k
The Illustrated Children's Guide to Kubernetes
chrisshort
39
47k
How to Think Like a Performance Engineer
csswizardry
4
590
Designing for humans not robots
tammielis
247
25k
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