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
41
FileSystems em Ruby com FUSE
celsocrivelaro
2
54
Padrões e Boas Práticas de Teste de Tela
celsocrivelaro
0
350
Projeto de APIs
celsocrivelaro
0
140
Testing Network Conditions with ToxiProxy
celsocrivelaro
1
300
Testing Network Conditions with ToxiProxy
celsocrivelaro
0
76
Actor Model in Ruby
celsocrivelaro
0
220
InfluxDB + Grafana
celsocrivelaro
0
230
Other Decks in Programming
See All in Programming
Doctrine ORMでValue Objectを扱う方法4選 #phpstudy / 4 ways to handle Value Objects with Doctrine ORM
77web
4
110
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
340
受託開発でGitLab CI を活用していく
xiombatsg
1
270
PostmanでAPIの動作確認が楽になった話
h455h1
0
130
try! Swift Tokyo 2024のLT枠に採択されたプロポーザルを出すときに考えていたこと
ski
0
340
SwiftUI Performance 不要なViewの再描画と更新を抑える
bigamitiongit
1
160
Changed Rules: Architectures with Lightweight Stores
manfredsteyer
PRO
0
230
Micro Frontends for Java Microservices - Devnexus 2024
mraible
PRO
0
430
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
460
ゆるい個人開発のススメ
kuroppe1819
10
940
CQRS/ES avec Symfony, c’est (trop) bien !
jeremyfreeagent
1
630
GraphQLサーバの構成要素を整理する #ハッカー鮨 #tsukijigraphql / graphql server technology selection
izumin5210
1
190
Featured
See All Featured
Thoughts on Productivity
jonyablonski
57
3.8k
Large-scale JavaScript Application Architecture
addyosmani
503
110k
The Illustrated Children's Guide to Kubernetes
chrisshort
29
46k
Rebuilding a faster, lazier Slack
samanthasiow
72
8.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
356
22k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Atom: Resistance is Futile
akmur
258
25k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
18
1.7k
Ruby is Unlike a Banana
tanoku
96
10k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
12
1.5k
How to train your dragon (web standard)
notwaldorf
72
5.1k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
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