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
Validations in Ruby
Search
Krzysztof Wawer
March 23, 2016
Programming
0
120
Validations in Ruby
Krzysztof Wawer
March 23, 2016
Tweet
Share
More Decks by Krzysztof Wawer
See All by Krzysztof Wawer
The Good Architecture
wafcio
0
520
GIT - Good Practices
wafcio
0
45
Slim Ruby on Rails: Controllers & Middlewares
wafcio
1
120
Dry System
wafcio
0
85
dry-validations
wafcio
0
140
Generating a CSV file with ROM
wafcio
0
220
Trailblazer bez trailblazera
wafcio
0
150
ActiveRecord, DataMapper czy Agregacja encji
wafcio
0
110
Jak (nie) używać Service Object
wafcio
0
140
Other Decks in Programming
See All in Programming
CSC307 Lecture 09
javiergs
PRO
1
500
実用的かつリーズナブルな 「Azure × Gemini × LINE」~キャラクターBot 実装ライブデモ~
tomodo_ysys
1
170
【Go言語】golangci-lintの使い方
tomo1227
0
270
しくじり先生 Image Matching Challenge 2024 編
goosehaaan
0
810
初心者がおさえておきたいAWS CDKのベストプラクティス 2024
konokenj
15
7.3k
TiDB Serverless ~理想のServerless DBを考える~
soso_15315
1
160
Harnessing Large Language Models for Training-free Video Anomaly Detection
tereka114
1
1.3k
From Spring Boot 2 to Spring Boot 3 with Java 22 and Jakarta EE
ivargrimstad
0
1.9k
社内 LT 会を発足し、アウトプット文化を醸成させるために考えたこと・やったこと / Starting internal LT meetings and fostering an output culture
mackey0225
3
120
ドメイン駆動設計の実践
masuda220
PRO
17
5.2k
Jetpack for KMP
fornewid
1
290
유연한 Composable 설계
l2hyunwoo
0
380
Featured
See All Featured
Clear Off the Table
cherdarchuk
89
320k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
90
47k
From Idea to $5000 a Month in 5 Months
shpigford
377
46k
Why Our Code Smells
bkeepers
PRO
332
56k
Web development in the modern age
philhawksworth
203
10k
Six Lessons from altMBA
skipperchong
24
3.2k
We Have a Design System, Now What?
morganepeng
46
7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
18
1.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
652
58k
Fontdeck: Realign not Redesign
paulrobertlloyd
79
5.1k
What's new in Ruby 2.0
geeforr
338
31k
Code Review Best Practice
trishagee
58
16k
Transcript
V ALIDATIONS IN Ruby Krzysztof W a wer 23.03.2016 TRUG
ABOUT ME • E-MAIL: krzysztof.w a
[email protected]
• Twitter: https://twitter.com/w
afcio • GITHUB: https://github.com/w afcio
V ALIDATION ???
Ruby on rails ACTIVE MODEL & ACTIVE RECORD Active Model
Active Record
ACTIVE MODEL V ALIDATIONS • acceptance • confirmation • exclusion
• format • inclusion • length • numericality • presence • uniqueness*
UNIQUENESS V ALIDATION
[email protected]
exists ?
[email protected]
exists ? Email
doesn’t exist Email doesn’t exist Create
[email protected]
Create
[email protected]
Created! Created! 1 2
UNIQUENESS V ALIDATION
UNIQUENESS V ALIDATION
[email protected]
exists ?
[email protected]
exists ? Email
doesn’t exist Email doesn’t exist Create
[email protected]
Create
[email protected]
Created! ActiveRecord::RecordNotUnique 1 2
Ruby on Rails • Strong Parameters http://edgeguides.rubyonrails.org/action_controller_overview.html#strong-parameters
STRONG PARAMETERS { name: „John”, surname: „Doe” } { name:
„John” }
STRONG PARAMETERS { name: „John”, surname: „Doe” } ActionController::UnpermittedParameters: found
unpermitted keys: surname ActionController::Parameters.action_on_unpermitted_parameters = :raise
HTTP Requests GET POST GET, POST (JSON) String String String
Integer …
HANAMI http://hanamirb.org https://github.com/hanami •hanami-controller •HANAMI-MODEL •HANAMI-HELPERS •HANAMI-MAILER •HANAMI-VIEW •HANAMI-V ALIDATIONS
•HANAMI-ASSETS •HANAMI-UTILS Luca Guidi
HANAMI-V ALIDATIONS https://github.com/hanami/v alidations#v alidations •ACCEPTANCE •CONFIRMATION •EXCLUSION •INCLUSION •PRESENCE
•FORMAT* •SIZE* •TYPE (Coercions)
HANAMI-V ALIDATIONS • numericality V ALIDATION DoesN’t Exist • „The
framework will treat as V alid any blank attributes, without PRESENCE, for both FORMAT and SIZE predicates.”
DRY https://github.com/dry-rb •DRY-AUTO_INJECT •DRY-COMPONENT •DRY-CONFIGURABLE •DRY-CONSTRUCTOR •DRY-CONTAINER •DRY-EQUALIZER •DRY-INITALIZER •DRY-LOGIC
•DRY-PIPELINE •DRY-TRANSACTION •DRY-TYPES •DRY-V ALIDATION
DRY-V ALIDATION LATEST VERSION: 0.7.0 RELEASE DATE: 16.03.2016 http://dry-rb.org/gems/dry-v alidation/
DRY-V ALIDATION When to use? V ALIDATION OF: • form
params • „GET” params • JSON params • Y AML DOCUMENTS • application configuration • replacement of ActiveRecord / ActiveModel::Validations • replacement of StrongParameters • …
???