One project, 3 gems
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

One project, 3 gems

on

  • 1,124 views

Three handy Ruby gems inspired by the same project at Lonely Planet.

Three handy Ruby gems inspired by the same project at Lonely Planet.

Statistics

Views

Total Views
1,124
Views on SlideShare
992
Embed Views
132

Actions

Likes
0
Downloads
4
Comments
0

6 Embeds 132

http://localhost 68
http://dogbiscuit.org 58
http://www.dogbiscuit.org 3
http://dogbiscuit.local 1
http://static.slidesharecdn.com 1
http://dogbiscuit.nfshost.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

One project, 3 gems Presentation Transcript

  • 1. One project,three gems Mike Williams Cogent Consulting in association with
  • 2. Architecture“Atlas” <stuff/>
  • 3. arborealGrowing Trees (restaurant) (hotel) Melbourne Sydney Geelong Victoria NSW (sight) WA Australia New Zealand Pacific Europe Asia WORLD Americas Africa
  • 4. arborealhow do I select this? Melbourne Sydney Geelong Victoria NSW WA Australia New Zealand Pacific Europe Asia WORLD Americas Africa
  • 5. arborealPath Enumeration@victoria = Place.find_by_name(“Victoria”)@victoria.ancestry_string#=> “-4-14-15-” Melbourne Sydney Geelong Victoria NSW Australia 15 WA New Zealand Pacific 14 Europe WORLD 4 Asia Americas Africa
  • 6. arboreal@victoria.ancestorsSELECT * FROM places WHERE (id in (4,14,15)) Melbourne Sydney Geelong Victoria NSW Australia 15 WA New Zealand Pacific 14 Europe WORLD 4 Asia Americas Africa
  • 7. arboreal@australia = Place.find_by_name(“Australia”)@australia.childrenSELECT * FROM places WHERE (places.parent_id = 15) Melbourne Sydney Geelong Victoria NSW Australia 15 WA New Zealand Pacific Europe Asia WORLD Americas Africa
  • 8. arboreal@australia.descendantsSELECT * FROM places WHERE (places.ancestry_string like ‘-4-14-15-%’) “-4-14-15-22-” Melbourne Sydney “-4-14-15-16-” Geelong Victoria NSW “-4-14-15-” WA Australia New Zealand Pacific Europe Asia WORLD Americas Africa
  • 9. arboreal@australia.subtreeSELECT * FROM places WHERE (places.id = 15 OR places.ancestry_string like ‘-4-14-15-%’) “-4-14-15-22-” Melbourne Sydney “-4-14-15-16-” Geelong Victoria NSW “-4-14-15-” Australia 15 WA New Zealand Pacific Europe Asia WORLD Americas Africa
  • 10. arboreal@australia.subtree.scope(:find, :conditions)#=> [“places.id = ? OR places.ancestry_string like ?”, 15, “-4-14-15-%”]class Place def contained_pois Poi.scoped(:include => :place, :conditions => subtree.scope(:find, :conditions)) endend@australia.contained_poisSELECT ... FROM pois LEFT OUTER JOIN places ON places.id = pois.place_id WHERE (places.id = 15 OR places.ancestry_string like ‘-4-14-15-%’)
  • 11. arboreal@australia.contained_poisSELECT ... FROM pois LEFT OUTER JOIN places ON places.id = pois.place_id WHERE (places.id = 15 OR places.ancestry_string like ‘-4-14-15-%’) Melbourne Sydney Geelong Victoria NSW WA Australia New Zealand Pacific Europe Asia WORLD Americas Africa
  • 12. GET http://stuff.local/places/15/pois “Atlas” <pois/>
  • 13. <pois type="array"> <poi> <created-at type="datetime">2010-08-25T23:35:59Z</created-at> <email nil="true"></email> <id type="integer">6</id> <latitude type="decimal">-37.8002389992226</latitude> <longitude type="decimal">144.901535511017</longitude> <name>Footscray Market</name> <place-id type="integer">26</place-id> <review>A frenetic covered food market.</review> <type>See</type> <updated-at type="datetime">2010-08-25T23:35:59Z</updated-at> <url nil="true"></url> </poi> <poi> <created-at type="datetime">2010-08-25T23:35:59Z</created-at> <email nil="true"></email> <id type="integer">7</id> <latitude type="decimal">-37.8020224141169</latitude> <longitude type="decimal">144.983611106873</longitude> <name>Panama Dining Room</name> <place-id type="integer">26</place-id> <review>Franco-Fitzroy pub grub and ersatz Manhattan views.</review> <type>Eat</type> <updated-at type="datetime">2010-08-25T23:35:59Z</updated-at> <url nil="true"></url> </poi> ...
  • 14. <pois type="array"> <poi href="http://stuff.local/pois/6"> <name>Footscray Market</name> <type>See</type> <review>A frenetic covered food market.</review> <place href="http://stuff.local/places/26"> <name>Melbourne</name> </place> </poi> <poi href="http://stuff.local/pois/7"> <name>Panama Dining Room</name> <type>Eat</type> <review>Franco-Fitzroy pub grub and ersatz Manhattan views.</review> <place href="http://stuff.local/places/26"> <name>Melbourne</name> </place> </poi> <poi href="http://stuff.local/pois/8"> <name>Sydney Opera House</name> <type>See</type> <review/> <place href="http://stuff.local/places/17"> <name>Sydney</name> </place> </poi></pois>
  • 15. # BEFORE ...xml.pois :type => “array” do @pois.each do |poi| xml.poi :href => poi_url(poi) do xml.name(poi.name) xml.type(poi.type) xml.review(poi.review) xml.place :href => place_url(poi.place) do xml.name poi.place.name end end endend
  • 16. # BEFORE ... representativexml.pois :type => “array” do @pois.each do |poi| xml.poi :href => poi_url(poi) do xml.name(poi.name) xml.type(poi.type) xml.review(poi.review) xml.place :href => place_url(poi.place) do xml.name poi.place.name end end endend# AFTER ...Representative::Xml.new(xml) do |r| r.list_of :pois, @pois, :item_attributes => {:href => method(:poi_url)} do r.element :name r.element :type r.element :review r.element :place, :href => method(:place_url) do r.element :name end endend
  • 17. # XML ... representativeRepresentative::Xml.new(xml) do |r| r.list_of :pois, @pois, :item_attributes => {:href => method(:poi_url)} do r.element :name r.element :type r.element :review r.element :place, :href => method(:place_url) do r.element :name end endend# JSON ...Representative::Json.new do |r| r.list_of :pois, @pois, :item_attributes => {:href => method(:poi_url)} do r.element :name r.element :type r.element :review r.element :place, :href => method(:place_url) do r.element :name end endend.to_s
  • 18. <pois type="array"> <poi href="http://stuff.local/pois/6"> <name>Footscray Market</name> <type>See</type> <review>A frenetic covered food market.</review> <place href="http://stuff.local/places/26"> <name>Melbourne</name> </place> </poi> <poi href="http://stuff.local/pois/7"> <name>Panama Dining Room</name> <type>Eat</type> <review>Franco-Fitzroy pub grub and ersatz Manhattan views.</review> <place href="http://stuff.local/places/26"> <name>Melbourne</name> </place> </poi> <poi href="http://stuff.local/pois/8"> <name>Sydney Opera House</name> <type>See</type> <review/> <place href="http://stuff.local/places/17"> <name>Sydney</name> </place> </poi></pois>
  • 19. representative[ { "name": "Footscray Market", "type": "See", "review": "A frenetic covered food market.", "place": { "name": "Melbourne" } }, { "name": "Panama Dining Room", "type": "Eat", "review": "Franco-Fitzroy pub grub and ersatz Manhattan views.", "place": { "name": "Melbourne" } }, { "name": "Sydney Opera House", "type": "See", "review": null, "place": { "name": "Sydney" } }]
  • 20. “Atlas” <pois/>
  • 21. <pois/> something that wants POI data
  • 22. <pois/> somethingfake that wantsAtlas POI data
  • 23. sham rackrequire ‘fakeweb’FakeWeb.register_uri(:get, “http://www.example.com/hello”, :body => “Hello World!”)require ‘webmock’stub_request(:get, “www.example.com/hello”).to_return(:body => “Hello, World!”)require ‘sham_rack’ShamRack.at(“www.example.com”).stub.register_resource(“/hello”, “Hello, World!”)
  • 24. sham rackIt’s just Rack!client Net::HTTP Sham Rack Rack app
  • 25. sham rackIt’s just Rack!ShamRack.at("www.example.com”) do |env| [ "200 OK", { "Content-type" => "text/plain" }, "Hello, world!" ]endShamRack.at("www.example.com").rackup do use Some::Middleware use Some::Other::Middleware run MyApp.newend
  • 26. sham rackIt’s just Rack!ShamRack.at("www.example.com").sinatra do get "/hello/:subject" do "Hello, #{params[:subject]}" endend
  • 27. http://github.com/mdub/arborealhttp://github.com/mdub/representativehttp://github.com/mdub/sham_rack