Virtus Lightning Talk

Virtus Lightning Talk

A lightning talk about the Virtus gem. https://github.com/solnic/virtus

638d7e4bb8d455e8149b2f46355c0973?s=128

Samson Ootoovak

April 29, 2014
Tweet

Transcript

  1. VIRTUS

  2. WHAT IS VIRTUS?

  3. A GEM THAT CAME OUT OF THE RUBY OBJECT MAPPER

    (ROM) PROJECT.
  4. ROM IS AN IMPLEMENTATION OF THE DATA MAPPER PATTERN IN

    RUBY.
  5. WRITTEN MAINLY BY PIOTR SOLNICA.

  6. IT WAS DEVELOPED AS MANY SINGLE RESPONSIBILITY GEMS.

  7. THE VIRTUS PART PROVIDES A COMMON API FOR DEFINING ATTRIBUTES

    ON A MODEL.
  8. THE LARGES FEATURE OF WHICH IS BEING ABLE TO DEFINE

    CUSTOM DATA-TYPE COERCIONS.
  9. WHAT DO I USE IT FOR?

  10. FORM OBJECTS!

  11. WHAT ARE FORM OBJECTS?

  12. FORM OBJECTS ARE MODELS THAT BACK YOUR WEB FORMS.

  13. THEY ARE THE ENTRANCE WAY BETWEEN THE WIDER WORLD AND

    YOUR APP CODE.
  14. USING ACTIVEMODEL::MODEL IN RAILS MAKES YOUR POROS PLAY NICE WITH

    ACTIONPACK (LIKE FORM HELPERS).
  15. THIS MEANS YOU CAN USE RAILS FORM NICETIES WITHOUT FEELING

    LIKE EVERY MODEL WITH A FORM HAS TO BE AN ACTIVERECORD MODEL.
  16. OR USING THE HORRIBLE MESS THAT IS NESTED ATTRIBUTES.

  17. OR DIFFERENT CONTEXTS FOR THE SAME MODEL REQUIRING DIFFERENT VALIDATIONS.

  18. ADDING VIRTUS ON TOP OF THAT MAKES IT EASIER TO

    INSURE YOUR DATA IS SANITISED.
  19. c l a s s U s e r P

    h o n e i n c l u d e V i r t u s . m o d e l i n c l u d e A c t i v e M o d e l : : M o d e l a t t r i b u t e : n a m e , S t r i n g a t t r i b u t e : p h o n e _ t y p e , S t r i n g a t t r i b u t e : p h o n e _ n u m b e r , I n t e g e r v a l i d a t e s _ p r e s e n c e _ o f : n a m e d e f p e r s i s t e d ? ; f a l s e ; e n d d e f s a v e ; v a l i d ? ; e n d e n d
  20. c l a s s U s e r P

    h o n e i n c l u d e V i r t u s . m o d e l i n c l u d e A c t i v e M o d e l : : M o d e l a t t r i b u t e : n a m e , S t r i n g a t t r i b u t e : p h o n e _ t y p e , P h o n e T y p e a t t r i b u t e : p h o n e _ n u m b e r , P h o n e N u m b e r v a l i d a t e s _ p r e s e n c e _ o f : n a m e d e f p e r s i s t e d ? ; f a l s e ; e n d d e f s a v e ; v a l i d ? ; e n d e n d
  21. WHAT ELSE CAN VIRTUS BE USED FOR?

  22. VALUE OBJECTS!

  23. c l a s s G e o L o

    c a t i o n i n c l u d e V i r t u s . v a l u e _ o b j e c t v a l u e s d o a t t r i b u t e : l a t i t u d e a t t r i b u t e : l o n g i t u d e e n d e n d
  24. WHO AM I?

  25. SAMSON OOTOOVAK (@OOTOOVAK) SOON TO BE TEACHING AT ENSPIRAL DEV

    ACADEMY