Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Separando as regras de negócios do Rails
Search
Celso Crivelaro
July 09, 2016
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Separando as regras de negócios do Rails
Separando as regras de negócios do Rails
Celso Crivelaro
July 09, 2016
More Decks by Celso Crivelaro
See All by Celso Crivelaro
Sistemas de Recomendação
celsocrivelaro
2
250
Big Data para Gerentes de Projetos
celsocrivelaro
0
75
FileSystems em Ruby com FUSE
celsocrivelaro
2
77
Padrões e Boas Práticas de Teste de Tela
celsocrivelaro
0
460
Projeto de APIs
celsocrivelaro
0
190
Testing Network Conditions with ToxiProxy
celsocrivelaro
1
410
Testing Network Conditions with ToxiProxy
celsocrivelaro
0
92
Actor Model in Ruby
celsocrivelaro
0
270
InfluxDB + Grafana
celsocrivelaro
0
280
Other Decks in Programming
See All in Programming
Java 27新機能 / Java 27 new features
kishida
2
210
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
350
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
240
すこし踏み込む CancellationToken
htkym
2
1.7k
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
360
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2.3k
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
260
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5k
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
8
5.6k
速習iPhone Duo対応
yuukiw00w
2
970
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Domain-Driven Transformation
hschwentner
2
2.3k
Featured
See All Featured
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The browser strikes back
jonoalderson
0
1.8k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
570
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
620
Exploring anti-patterns in Rails
aemeredith
4
530
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Optimizing for Happiness
mojombo
378
71k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
How to train your dragon (web standard)
notwaldorf
96
6.9k
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