forked from mongomapper/mongomapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmconsole
executable file
·59 lines (44 loc) · 1.02 KB
/
mmconsole
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__) + '/../lib')
begin
require 'mongo_mapper'
require 'irb'
rescue LoadError
require 'rubygems'
retry
end
IRB.setup(nil)
irb = IRB::Irb.new
IRB.conf[:MAIN_CONTEXT] = irb.context
irb.context.evaluate("require 'irb/completion'", 0)
irb.context.evaluate(%@
MongoMapper.database = "mm-test"
$db = MongoMapper.database
@, 0)
puts %@
Welcome to the MongoMapper Console!
Example 1:
things = $db.collection("things")
things.insert("name" => "Raw Thing")
things.insert("name" => "Another Thing", "date" => Time.now)
cursor = things.find("name" => "Raw Thing")
puts cursor.next_object.inspect
Example 2:
class Thing
include MongoMapper::Document
key :name, String, :required => true
key :date, Time
end
thing = Thing.new
thing.name = "My thing"
thing.date = Time.now
thing.save
all_things = Thing.all
puts all_things.map { |object| object.name }.inspect
@
trap("SIGINT") do
irb.signal_handle
end
catch(:IRB_EXIT) do
irb.eval_input
end