z, ? | toggle help (this) |
space, → | next slide |
shift-space, ← | previous slide |
d | toggle debug mode |
## <ret> | go to slide # |
c, t | table of contents (vi) |
f | toggle footer |
r | reload slides |
n | toggle notes |
p | run preshow |
# it’s in the standard library
# and has Marshal and YAML backends
require 'yaml/store'
store = YAML::Store.new 'quotes.yml'
# quotes are author + text structures
Quote = Struct.new(:author, :text)
store.transaction do # a read/write transaction…
store['db'] ||= []
store['db'] << Quote.new('Charlie Gibbs',
'A database is a black hole into which you put your data.')
store['db'] << Quote.new('Will Jessop',
'MySQL is truly the PHP of the database world.')
end # …is atomically committed here
# read-only transactions can be concurrent
# and raise when you try to write anything
store.transaction(true) do
store['db'].each do |quote|
puts quote.text
puts '-- ' + quote.author
puts
end
end
$ ruby quotes.rb
A database is a black hole into which you put your data.
-- Charlie Gibbs
MySQL is truly the PHP of the database world.
-- Will Jessop
$ cat quotes.yml
---
db:
- !ruby/struct:Quote
author: Charlie Gibbs
text: A database is a black hole into which you put your data.
- !ruby/struct:Quote
author: Will Jessop
text: MySQL is truly the PHP of the database world.
{ $ref: <collection>, $id: <object_id> }
require 'candy'
class Conference
include Candy::Piece
end
rubyconf = Conference.new
# connects to localhost:27017 and ‘chastell’ db if needed
# and saves a new document to the ‘Conference’ collection
rubyconf.location = 'New Orleans' # method_missing resaves
rubyconf.events = { parties: { thursday: '&block Party' } }
rubyconf.events.parties.thursday #=> '&block Party'
require 'ambition/adapters/active_record'
class Person < ActiveRecord::Base
end
Person.select do |p|
(p.country == 'USA' && p.age >= 21) ||
(p.country != 'USA' && p.age >= 18)
end
# SELECT * FROM people
# WHERE (
# (people.country = 'USA' AND people.age >= 21) OR
# (people.country <> 'USA' AND people.age >= 18)
# )
require 'ambition/adapters/active_ldap'
class Person < ActiveLdap::Base
end
Person.select do |p|
(p.country == 'USA' && p.age >= 21) ||
(p.country != 'USA' && p.age >= 18)
end
# (|
# (& (country=USA) (age>=21) )
# (& (!(country=USA)) (age>=18) )
# )