mongo_doc 0.4.2 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/.gitignore +1 -0
  2. data/HISTORY.md +8 -1
  3. data/README.textile +12 -24
  4. data/Rakefile +58 -11
  5. data/VERSION +1 -1
  6. data/features/embed_hash.feature +16 -0
  7. data/features/step_definitions/document_steps.rb +1 -1
  8. data/features/step_definitions/documents.rb +2 -0
  9. data/features/step_definitions/embed_hash_steps.rb +6 -0
  10. data/features/step_definitions/string_casting_steps.rb +2 -1
  11. data/features/support/support.rb +1 -0
  12. data/lib/mongo_doc/associations/collection_proxy.rb +29 -13
  13. data/lib/mongo_doc/associations/document_proxy.rb +14 -5
  14. data/lib/mongo_doc/associations/hash_proxy.rb +20 -16
  15. data/lib/mongo_doc/associations/proxy_base.rb +21 -26
  16. data/lib/mongo_doc/associations.rb +15 -6
  17. data/lib/mongo_doc/attributes.rb +2 -20
  18. data/lib/mongo_doc/collection.rb +1 -1
  19. data/lib/mongo_doc/connection.rb +1 -1
  20. data/lib/mongo_doc/contexts/ids.rb +3 -3
  21. data/lib/mongo_doc/contexts/mongo.rb +1 -1
  22. data/lib/mongo_doc/document.rb +30 -13
  23. data/lib/mongo_doc/ext/binary.rb +2 -2
  24. data/lib/mongo_doc/ext/dbref.rb +2 -2
  25. data/lib/mongo_doc/ext/min_max_keys.rb +13 -0
  26. data/lib/mongo_doc/ext/object.rb +4 -2
  27. data/lib/mongo_doc/ext/object_id.rb +2 -2
  28. data/lib/mongo_doc/ext.rb +1 -0
  29. data/lib/mongo_doc/finders.rb +2 -2
  30. data/lib/mongo_doc/root.rb +26 -0
  31. data/lib/mongo_doc/validations.rb +16 -0
  32. data/lib/mongo_doc.rb +2 -1
  33. data/lib/mongoid/criterion/optional.rb +1 -1
  34. data/mongo_doc.gemspec +29 -17
  35. data/perf/mongo_doc_object.rb +78 -0
  36. data/perf/mongo_document.rb +78 -0
  37. data/perf/ruby_driver.rb +43 -0
  38. data/spec/associations/collection_proxy_spec.rb +29 -6
  39. data/spec/associations/document_proxy_spec.rb +22 -19
  40. data/spec/associations/hash_proxy_spec.rb +17 -4
  41. data/spec/associations/proxy_base_spec.rb +92 -0
  42. data/spec/associations_spec.rb +4 -16
  43. data/spec/bson_spec.rb +1 -1
  44. data/spec/connection_spec.rb +2 -2
  45. data/spec/contexts/ids_spec.rb +2 -2
  46. data/spec/document_spec.rb +31 -22
  47. data/spec/ext_spec.rb +8 -0
  48. data/spec/root_spec.rb +41 -0
  49. data/spec/validations_spec.rb +30 -0
  50. metadata +46 -23
  51. data/lib/mongo_doc/query.rb +0 -7
  52. data/perf/mongo_doc_runner.rb +0 -90
  53. data/perf/ruby_driver_runner.rb +0 -64
  54. data/spec/query_spec.rb +0 -12
@@ -1,90 +0,0 @@
1
- require "benchmark"
2
- require "ruby-prof"
3
- require "mongo_doc"
4
-
5
- class Person < MongoDoc::Document
6
- key :birth_date
7
- has_one :name
8
- has_one :address
9
- has_many :phones
10
- end
11
-
12
- class Name < MongoDoc::Document
13
- key :given
14
- key :family
15
- key :middle
16
- end
17
-
18
- class Address < MongoDoc::Document
19
- key :street
20
- key :city
21
- key :state
22
- key :post_code
23
- key :type
24
- end
25
-
26
- class Phone < MongoDoc::Document
27
- key :country_code
28
- key :number
29
- key :type
30
- end
31
-
32
- class MongoDocRunner
33
- def self.benchmark
34
- MongoDoc.connect_to_database('mongo_doc_perf_test')
35
- MongoDoc.database.collection('people').drop
36
-
37
- puts "Starting benchmark..."
38
-
39
- 10.times do |n|
40
- person = Person.new(:birth_date => Date.new(1970, 1, 1))
41
- name = Name.new(:given => "James", :family => "Kirk", :middle => "Tiberius")
42
- address = Address.new(:street => "1 Starfleet Command Way", :city => "San Francisco", :state => "CA", :post_code => "94133", :type => "Work")
43
- phone = Phone.new(:country_code => 1, :number => "415-555-1212", :type => "Mobile")
44
- person.name = name
45
- person.address = address
46
- person.phones << phone
47
- person.save
48
- end
49
-
50
- Benchmark.bm do |bm|
51
- bm.report('MongoDoc') do
52
- 10000.times do |n|
53
- person = Person.new(:birth_date => Date.new(1970, 1, 1))
54
- name = Name.new(:given => "James", :family => "Kirk", :middle => "Tiberius")
55
- address = Address.new(:street => "1 Starfleet Command Way", :city => "San Francisco", :state => "CA", :post_code => "94133", :type => "Work")
56
- phone = Phone.new(:country_code => 1, :number => "415-555-1212", :type => "Mobile")
57
- person.name = name
58
- person.address = address
59
- person.phones << phone
60
- person.save
61
- end
62
- end
63
- end
64
-
65
- end
66
-
67
- def self.profile
68
- MongoDoc.connect_to_database('mongo_doc_perf_test')
69
- MongoDoc.database.collection('people').drop
70
-
71
- RubyProf.start
72
-
73
- puts "Starting profiler..."
74
-
75
- 1000.times do |n|
76
- person = Person.new(:birth_date => Date.new(1970, 1, 1))
77
- name = Name.new(:given => "James", :family => "Kirk", :middle => "Tiberius")
78
- address = Address.new(:street => "1 Starfleet Command Way", :city => "San Francisco", :state => "CA", :post_code => "94133", :type => "Work")
79
- phone = Phone.new(:country_code => 1, :number => "415-555-1212", :type => "Mobile")
80
- person.name = name
81
- person.address = address
82
- person.phones << phone
83
- person.save
84
- end
85
-
86
- result = RubyProf.stop
87
- printer = RubyProf::FlatPrinter.new(result)
88
- printer.print(STDOUT, 0)
89
- end
90
- end
@@ -1,64 +0,0 @@
1
- require "rubygems"
2
- require "ruby-prof"
3
- require "mongo_doc"
4
-
5
- class RubyDriverRunner
6
- def self.benchmark
7
- MongoDoc.connect_to_database('mongo_doc_perf_test')
8
- collection = MongoDoc.database.collection('people')
9
- collection.drop
10
-
11
- puts "Starting benchmark..."
12
-
13
- 10.times do |n|
14
- person = {:birth_date => Date.new(1970, 1, 1).to_bson, :phones => []}
15
- name = {:given => "James", :family => "Kirk", :middle => "Tiberius"}
16
- address = {:street => "1 Starfleet Command Way", :city => "San Francisco", :state => "CA", :post_code => "94133", :type => "Work"}
17
- phone = {:country_code => 1, :number => "415-555-1212", :type => "Mobile"}
18
- person[:name] = name
19
- person[:address] = address
20
- person[:phones] << phone
21
- collection.save(person)
22
- end
23
-
24
- Benchmark.bm do |bm|
25
- bm.report('Driver') do
26
- 10000.times do |n|
27
- person = {:birth_date => Date.new(1970, 1, 1).to_bson, :phones => []}
28
- name = {:given => "James", :family => "Kirk", :middle => "Tiberius"}
29
- address = {:street => "1 Starfleet Command Way", :city => "San Francisco", :state => "CA", :post_code => "94133", :type => "Work"}
30
- phone = {:country_code => 1, :number => "415-555-1212", :type => "Mobile"}
31
- person[:name] = name
32
- person[:address] = address
33
- person[:phones] << phone
34
- collection.save(person)
35
- end
36
- end
37
- end
38
- end
39
-
40
- def self.profile
41
- MongoDoc.connect_to_database('mongo_doc_perf_test')
42
- collection = MongoDoc.database.collection('people')
43
- collection.drop
44
-
45
- RubyProf.start
46
-
47
- puts "Starting profiler..."
48
-
49
- 1000.times do |n|
50
- person = {:birth_date => Date.new(1970, 1, 1), :phones => []}
51
- name = {:given => "James", :family => "Kirk", :middle => "Tiberius"}
52
- address = { :street => "1 Starfleet Command Way", :city => "San Francisco", :state => "CA", :post_code => "94133", :type => "Work"}
53
- phone = {:country_code => 1, :number => "415-555-1212", :type => "Mobile"}
54
- person[:name] = name
55
- person[:address] = address
56
- person[:phones] << phone
57
- collection.insert(person)
58
- end
59
-
60
- result = RubyProf.stop
61
- printer = RubyProf::FlatPrinter.new(result)
62
- printer.print(STDOUT, 0)
63
- end
64
- end
data/spec/query_spec.rb DELETED
@@ -1,12 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Query support for MongoDoc" do
4
- describe "#set_modifier" do
5
- it "modifies all simple key/values of the hash to a set modifier" do
6
- key = 'key'
7
- value = 'value'
8
- hash = {key => value}
9
- MongoDoc::Query.set_modifier(hash).should == {'$set' => hash}
10
- end
11
- end
12
- end