Bldr - Rubyconf 2011 Lightning Talk

6,108 views

Published on

Lightning talk I gave at Rubyconf 2011 on Bldr (https://github.com/ajsharp/bldr)

Published in: Technology
  • Be the first to comment

Bldr - Rubyconf 2011 Lightning Talk

  1. BLDR Minimalist JSON templating DSL Alex Sharp @ajsharpFriday, September 30, 2011
  2. WHO AM I? Alex Sharp (@ajsharp) Ruby Engineer at Zaarly (zaarly.com)Friday, September 30, 2011
  3. WHAT IS ZAARLY? Buyer-centric local commerce platform Heavily api driven (iOS, Android, Web, HTML5 mobile) API only speaks jsonFriday, September 30, 2011
  4. WHY BLDR?Friday, September 30, 2011
  5. LET ME COUNT THE REASONS #as_json quickly gets...unwieldy We need tight control over our json responsesFriday, September 30, 2011
  6. SECURITY EXPLOIT We were leaking information in our json documents we weren’t aware of We didn’t understand #as_json was recursing through relationships and serializing them Not good...Friday, September 30, 2011
  7. TECHCRUNCH STORYFriday, September 30, 2011
  8. BLDR We wanted a simple, declarative DSL for defining JSON responsesFriday, September 30, 2011
  9. BLDR Simple, declarative DSL Works with Sinatra Rails 3 support nearly complete Four DSL methods (object, collection, attribute, attributes)Friday, September 30, 2011
  10. SINATRA get /foo do bar = baz bldr :foo, :locals => {:bar => bar} endFriday, September 30, 2011
  11. SINATRA # foo.bldr object do attribute :foo, bar end # output {"foo": "baz"}Friday, September 30, 2011
  12. ATTRIBUTE LISTS object :post => post do attributes :title, :body end { "post": { "title": "my title", "body": "..." } }Friday, September 30, 2011
  13. IMPLIED OBJECTS object :post do attributes :title, :body end { "post": { "title": "my title", "body": "..." } }Friday, September 30, 2011
  14. DYNAMIC ATTRIBUTES object :post do attribute :comment_count do |post| post.comments.count end end { "post": {"comment_count":1} }Friday, September 30, 2011
  15. OBJECT NESTING object :post => post do attributes :title, :body object :author => post.author do attribute :last_name end end { "post": { "title": "my title", "body": "...", "author": {"last_name": "Doe"} } }Friday, September 30, 2011
  16. ATTRIBUTE ALIASES object :post => post do attributes :title, :body object :author => post.author do attribute :surname => :last_name end end { "post": { "title": "my title", "body": "...", "author": {"surname": "Doe"} } }Friday, September 30, 2011
  17. TOP-LEVEL COLLECTIONS collection :posts => posts do attributes :title, :body attribute :comment_count { |post| post.comments.count } end { "posts": [ { "title": "my title", "comment_count": 2, } ]}Friday, September 30, 2011
  18. NESTED COLLECTIONS collection :posts => posts do collection :comments => current_object.comments do attributes :body, :author, :email end end { "posts": [ { "comments": [ { "body": "...", "author_name": "Comment Troll", "email": "troll@trolling.edu" } ]} ]}Friday, September 30, 2011
  19. OTHER FEATURES Uses multi_json gem -- pick your encoding library Bldr.handlerFriday, September 30, 2011
  20. Bldr.handler BSON::ObjectId do |value| val.to_s # => "4e77a682364141ecf5000002" endFriday, September 30, 2011
  21. MORE INFOFriday, September 30, 2011
  22. MORE INFO github.com/ajsharp/bldr @ajsharp ajsharp@gmail.com zaarly.com / alexjsharp.comFriday, September 30, 2011

×