Slide 1

Slide 1 text

V ALIDATIONS IN Ruby Krzysztof W a wer 23.03.2016 TRUG

Slide 2

Slide 2 text

ABOUT ME • E-MAIL: krzysztof.w a [email protected] • Twitter:
 https://twitter.com/w afcio • GITHUB:
 https://github.com/w afcio

Slide 3

Slide 3 text

V ALIDATION ???

Slide 4

Slide 4 text

Ruby on rails ACTIVE MODEL & ACTIVE RECORD Active Model Active Record

Slide 5

Slide 5 text

ACTIVE MODEL V ALIDATIONS • acceptance • confirmation • exclusion • format • inclusion • length • numericality • presence • uniqueness*

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

UNIQUENESS V ALIDATION

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Ruby on Rails • Strong Parameters http://edgeguides.rubyonrails.org/action_controller_overview.html#strong-parameters

Slide 10

Slide 10 text

STRONG PARAMETERS { name: „John”, surname: „Doe” } { name: „John” }

Slide 11

Slide 11 text

STRONG PARAMETERS { name: „John”, surname: „Doe” } ActionController::UnpermittedParameters: found unpermitted keys: surname ActionController::Parameters.action_on_unpermitted_parameters = :raise

Slide 12

Slide 12 text

HTTP Requests GET POST GET, POST (JSON) String String String Integer …

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

HANAMI-V ALIDATIONS https://github.com/hanami/v alidations#v alidations •ACCEPTANCE •CONFIRMATION •EXCLUSION •INCLUSION •PRESENCE •FORMAT* •SIZE* •TYPE (Coercions)

Slide 15

Slide 15 text

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.”

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

DRY-V ALIDATION LATEST VERSION: 0.7.0 RELEASE DATE: 16.03.2016 http://dry-rb.org/gems/dry-v alidation/

Slide 18

Slide 18 text

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 • …

Slide 19

Slide 19 text

???