A Blink Into The Rails Magic

1,513 views

Published on

My presentation at Athens Digital Week '09

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,513
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

A Blink Into The Rails Magic

  1. 1. A blink into the “rails magic”<br />The meta-programming in Rails / Rails as a code generator<br />
  2. 2. Some rights reserved<br />Nikos Dimitrakopoulos, 2009<br />http://blog.nikosd.com<br />
  3. 3. The “classic” rails ingredients<br />MVC<br />DRY<br />COC<br />…<br />
  4. 4. Not for today…<br />MVC<br />DRY<br />COC<br />…<br />
  5. 5. Rails as a code generator<br />
  6. 6. PART I : 100% Static<br />
  7. 7. The directory structure<br />
  8. 8. Models + Tests<br />
  9. 9. Controllers / views + tests<br />
  10. 10. Resources (the whole set)<br />
  11. 11. Even with *implemented* views & controllers (a.k.a. “scaffolds”)<br />
  12. 12.
  13. 13.
  14. 14.
  15. 15.
  16. 16.
  17. 17. Static(*) API<br />
  18. 18.
  19. 19.
  20. 20. Nothing special so far…<br />
  21. 21. PART II : 100% On-the-fly<br />
  22. 22. This is where the actual fun begins!<br />
  23. 23. Some basic stuff: ORM<br />
  24. 24.
  25. 25.
  26. 26.
  27. 27. How does Rails map the attributes???<br />
  28. 28.
  29. 29.
  30. 30. The truth is in the source…<br />
  31. 31.
  32. 32.
  33. 33.
  34. 34.
  35. 35.
  36. 36. A blink into the “magic”<br />
  37. 37.
  38. 38. if we haven’t already generated the “dynamic” methods<br />
  39. 39. if we haven’t already generated the “dynamic” methods<br /><ul><li> generate them</li></li></ul><li>if we haven’t already generated the “dynamic” methods<br /><ul><li> generate them
  40. 40. try to call the method with the given name again!</li></li></ul><li>
  41. 41.
  42. 42. for each column on the db table :<br />
  43. 43. for each column on the db table :<br /><ul><li> define a “read” method</li></li></ul><li>for each column on the db table :<br /><ul><li> define a “read” method </li></ul>(for example the Guest#name)<br />
  44. 44. for each column on the db table :<br /><ul><li> define a “read” method</li></ul>(for example the Guest#name)<br /><ul><li> define a “write” method</li></li></ul><li>for each column on the db table :<br /><ul><li> define a “read” method</li></ul>(for example the Guest#name)<br /><ul><li> define a “write” method</li></ul>(for example the Guest#name = …)<br />
  45. 45. for each column on the db table :<br /><ul><li> define a “read” method</li></ul>(for example the Guest#name)<br /><ul><li> define a “write” method</li></ul>(for example the Guest#name = …)<br /><ul><li> define a “question” method</li></li></ul><li>for each column on the db table :<br /><ul><li> define a “read” method</li></ul>(for example the Guest#name)<br /><ul><li> define a “write” method</li></ul>(for example the Guest#name = …)<br /><ul><li> define a “question” method</li></ul>(for example the Guest#name?)<br />
  46. 46.
  47. 47. PART III : Magic happens Everywhere<br />
  48. 48. On the routes / Controllers<br />
  49. 49.
  50. 50.
  51. 51.
  52. 52.
  53. 53.
  54. 54.
  55. 55. + 3 more by default<br />
  56. 56. + 3 more by default<br />More info on “resources” : <br />http://api.rubyonrails.org/classes/ActionController/Resources.html<br />
  57. 57. On the ORM / Models<br />
  58. 58. Dynamic finders<br />
  59. 59. Dynamic finders<br />
  60. 60. As said this is just a “blink”<br />
  61. 61. Look for more in :<br /><ul><li>ActiveRecordassociations
  62. 62. ActiveRecordnamed_scopes
  63. 63. ActionControllerroutes
  64. 64. ActionControllerrendering
  65. 65. ActionControllerformat
  66. 66. etc…</li></li></ul><li>What do we get from this?<br />
  67. 67. What do we get from this?<br /><ul><li>Glue code</li></li></ul><li>What do we get from this?<br /><ul><li>Glue code
  68. 68. Domain-aware code</li></li></ul><li>What do we get from this?<br /><ul><li>Glue code
  69. 69. Domain-aware code
  70. 70. Out of the box</li></li></ul><li>What do we get from this?<br /><ul><li>Glue code
  71. 71. Domain-aware code
  72. 72. Out of the box
  73. 73. Every time</li></li></ul><li>What do we get from this?<br /><ul><li>Glue code
  74. 74. Domain-aware code
  75. 75. Out of the box
  76. 76. Every time
  77. 77. On every app</li></li></ul><li>Compare it with Java or .Net “enterprise” solutions…<br />
  78. 78. Compare it with Java or .Net “enterprise” solutions…<br />© Rubyrags.com<br />
  79. 79. Implement your own!!!<br />
  80. 80. Implement your own!!!<br />(Jim will give you a hint tomorrow at the Ruby Meetup)<br />
  81. 81. Thanks for your time<br />
  82. 82. Thanks for your time<br />And welcome <br />to themagic world of <br />Rubyand Ruby on Rails<br />

×