Skip to content

Instantly share code, notes, and snippets.

View KeithHanson's full-sized avatar

Keith Hanson KeithHanson

View GitHub Profile
[Streaming Active(62)] >
Invalid command. Type help to see a summary of valid commands.
[Streaming Active(89)] > show_current
Ce soir c'est la petite siréne.
[Streaming Active(116)] > show_current
@thedeadbaby Nope, I am positive.
[Streaming Active(129)] > show_current
@scottmccloud @markcrilley Agree. As a reader of manga, the best novels are those that are "written" from the heart, not by the book.
[Streaming Active(155)] > show_current
ROBERTOS. Yummmmmm
MongoMapper.database = "mongo_test"
class FirstDocument
include MongoMapper::Document
key :message, String
many :second_documents
end
class Person
include MongoMapper::Document
key :first_name, String
key :last_name, String
key :age, Integer
key :born_at, Time
key :active, Boolean
key :fav_colors, Array
person = Person.create({
:first_name => 'John',
:last_name => 'Nunemaker',
:age => 27,
:born_at => Time.mktime(1981, 11, 25, 2, 30),
:active => true,
:fav_colors => %w(red green blue)
})
person.first_name = 'Johnny'
person.save
person.destroy
# or you could do this to destroy
Person.destroy(person.id)
class Person
include MongoMapper::Document
key :first_name, String
key :last_name, String
key :age, Integer
key :born_at, Time
key :active, Boolean
key :fav_colors, Array
#Create a new person instance
person = Person.new
#Inject two new Address instances
#Notice how we don't save the Address instances before injecting them...
person.addresses << Address.new(:city => 'South Bend', :state => 'IN')
person.addresses << Address.new(:city => 'Chicago', :state => 'IL')
#When we save the person object, the addresses are injected into the person record automatically
person.save
{"last_name"=>"Nunemaker",
"age"=>27,
"born_at"=>Wed Nov 25 02:30:00 -0600 1981,
"fav_colors"=>["red", "green", "blue"],
"first_name"=>"John",
"active"=>true,
"addresses" => [{"city"=>"South Bend", "state"=>"IN"}, {"city"=>"Chicago", "state"=>"IL"}]
}
irb(main)> Person.all(:conditions => {:last_name => 'Nunemaker'}, :order => 'first_name')
=> [#<Person last_name: Nunemaker, fav_colors: redgreenblue, born_at: Wed Nov 25 02:30:00 -0600 1981, age: 27, active: true, first_name: John>]
irb(main):024:0> Person.first(:conditions => {"addresses.city" => "South Bend"})
=> #<Person last_name: Nunemaker, fav_colors: redgreenblue, born_at: Wed Nov 25 02:30:00 -0600 1981, age: 27, active: true, first_name: John>