3. arboreal
Growing Trees
(restaurant)
(hotel)
Melbourne
Sydney
Geelong
Victoria NSW (sight)
WA Australia
New Zealand
Pacific
Europe
Asia
WORLD
Americas Africa
4. arboreal
how do I select this?
Melbourne
Sydney
Geelong
Victoria NSW
WA Australia
New Zealand
Pacific
Europe
Asia
WORLD
Americas Africa
5. arboreal
Path 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.ancestors
SELECT * 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
8. arboreal
@australia.descendants
SELECT * 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.subtree
SELECT * 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))
end
end
@australia.contained_pois
SELECT ... 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_pois
SELECT ... 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
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
end
end
16. # BEFORE ... representative
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
end
end
# 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
end
end
17. # XML ... representative
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
end
end
# 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
end
end.to_s
25. sham
rack
It’s just Rack!
ShamRack.at("www.example.com”) do |env|
[
"200 OK",
{ "Content-type" => "text/plain" },
"Hello, world!"
]
end
ShamRack.at("www.example.com").rackup do
use Some::Middleware
use Some::Other::Middleware
run MyApp.new
end
26. sham
rack
It’s just Rack!
ShamRack.at("www.example.com").sinatra do
get "/hello/:subject" do
"Hello, #{params[:subject]}"
end
end