mongo_record 0.5 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +12 -14
- data/lib/mongo_record.rb +3 -0
- data/lib/mongo_record/base.rb +23 -9
- data/mongo-record.gemspec +2 -2
- data/tests/student.rb +6 -1
- metadata +21 -4
data/README.rdoc
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
= Welcome to MongoRecord
|
2
2
|
|
3
|
-
|
4
|
-
Mongo[http://www.mongodb.org/] database.
|
3
|
+
== Unsupported
|
5
4
|
|
6
|
-
|
5
|
+
Note: MongoRecord is no longer supported by its authors. For a list of MongoDB object mappers, see http://is.gd/gdehy.
|
6
|
+
|
7
|
+
== What MongoRecord was
|
8
|
+
|
9
|
+
MongoRecord is an ActiveRecord-like framework for
|
10
|
+
MongoDB[http://www.mongodb.org/].
|
11
|
+
|
12
|
+
This document assumes you have read the MongoDB documentation.
|
7
13
|
|
8
14
|
A quick code sample:
|
9
15
|
|
@@ -33,16 +39,9 @@ A quick code sample:
|
|
33
39
|
|
34
40
|
== Installation
|
35
41
|
|
36
|
-
First set up Gemcutter
|
37
|
-
|
38
|
-
$ gem install gemcutter
|
39
|
-
$ gem tumble
|
40
|
-
|
41
|
-
Then install
|
42
|
-
|
43
42
|
$ gem install mongo_record
|
44
43
|
|
45
|
-
MongoRecord depends on the Mongo Ruby Driver, version 0.
|
44
|
+
MongoRecord depends on the Mongo Ruby Driver, version 0.20.1 or higher.
|
46
45
|
Installing the MongoRecord gem will also install the Mongo Ruby Driver if you
|
47
46
|
don't have it already.
|
48
47
|
|
@@ -90,6 +89,5 @@ Nate Wiger, http://github.com/nateware
|
|
90
89
|
* Scoped dynamic finders to each instance, so rows with varying attributes work
|
91
90
|
* Added row.attributes helper to enable use of ActiveRecord::Callbacks if desired
|
92
91
|
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
Camilo Lopez
|
93
|
+
* Updates for later driver releases.
|
data/lib/mongo_record.rb
CHANGED
data/lib/mongo_record/base.rb
CHANGED
@@ -684,7 +684,7 @@ module MongoRecord
|
|
684
684
|
return "'#{val.gsub(/\'/, "\\\\'")}'" # " <= for Emacs font-lock
|
685
685
|
end
|
686
686
|
|
687
|
-
def fields_from(a)
|
687
|
+
def fields_from(a)
|
688
688
|
return nil unless a
|
689
689
|
a = [a] unless a.kind_of?(Array)
|
690
690
|
a += ['_id'] # always return _id
|
@@ -760,6 +760,7 @@ module MongoRecord
|
|
760
760
|
# Initialize a new object with either a hash of values or a row returned
|
761
761
|
# from the database.
|
762
762
|
def initialize(row={})
|
763
|
+
|
763
764
|
case row
|
764
765
|
when Hash
|
765
766
|
row.each { |k, val|
|
@@ -989,22 +990,35 @@ module MongoRecord
|
|
989
990
|
# Initialize ivar. +name+ must include the leading '@'.
|
990
991
|
def init_ivar(ivar_name, val)
|
991
992
|
sym = ivar_name[1..-1].to_sym
|
993
|
+
value = nil
|
994
|
+
|
992
995
|
if self.class.subobjects.keys.include?(sym)
|
993
996
|
if val.instance_of? BSON::DBRef
|
994
997
|
val = self.class.collection.db.dereference(val)
|
995
998
|
end
|
996
|
-
|
999
|
+
value = self.class.subobjects[sym].new(val)
|
1000
|
+
#instance_variable_set(ivar_name, self.class.subobjects[sym].new(val))
|
1001
|
+
|
997
1002
|
elsif self.class.arrays.keys.include?(sym)
|
998
1003
|
klazz = self.class.arrays[sym]
|
999
1004
|
val = [val] unless val.kind_of?(Array)
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1005
|
+
|
1006
|
+
value = val.collect do |v|
|
1007
|
+
if v.instance_of? BSON::DBRef
|
1008
|
+
v = self.class.collection.db.dereference(v)
|
1009
|
+
end
|
1010
|
+
v.kind_of?(MongoRecord::Base) ? v : klazz.new(v)
|
1011
|
+
end
|
1012
|
+
else
|
1013
|
+
|
1014
|
+
value = val
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
if self.class.field_names.include?(sym)
|
1018
|
+
__send__(sym.to_s + '=', value)
|
1019
|
+
|
1006
1020
|
else
|
1007
|
-
instance_variable_set(ivar_name,
|
1021
|
+
instance_variable_set(ivar_name, value)
|
1008
1022
|
end
|
1009
1023
|
end
|
1010
1024
|
|
data/mongo-record.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'mongo_record'
|
3
|
-
s.version = '0.5'
|
3
|
+
s.version = '0.5.1'
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = 'ActiveRecord-like models for MongoDB'
|
6
|
-
s.description = '
|
6
|
+
s.description = 'Note: this gem is no longer offically supported by 10gen. For a list of MongoDB object mappers, see http://is.gd/gdehy'
|
7
7
|
|
8
8
|
s.add_dependency('mongo', ['>= 0.20.1'])
|
9
9
|
|
data/tests/student.rb
CHANGED
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'address')
|
|
3
3
|
|
4
4
|
class Score < MongoRecord::Base
|
5
5
|
|
6
|
-
field :grade
|
6
|
+
field :grade, :graded_at
|
7
7
|
has_one :for_course, :class_name => 'Course' # Mongo will store course db reference, not duplicate object
|
8
8
|
|
9
9
|
def passed?
|
@@ -14,6 +14,11 @@ class Score < MongoRecord::Base
|
|
14
14
|
"#@for_course: #@grade"
|
15
15
|
end
|
16
16
|
|
17
|
+
def grade=(val)
|
18
|
+
@graded_at = Time.now
|
19
|
+
@grade = val
|
20
|
+
end
|
21
|
+
|
17
22
|
end
|
18
23
|
|
19
24
|
class Student < MongoRecord::Base
|
metadata
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 5
|
8
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
9
11
|
platform: ruby
|
10
12
|
authors:
|
11
13
|
- Jim Menard
|
@@ -14,16 +16,18 @@ autorequire:
|
|
14
16
|
bindir: bin
|
15
17
|
cert_chain: []
|
16
18
|
|
17
|
-
date: 2010-
|
19
|
+
date: 2010-10-22 00:00:00 -04:00
|
18
20
|
default_executable:
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
21
23
|
name: mongo
|
22
24
|
prerelease: false
|
23
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
28
|
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 77
|
27
31
|
segments:
|
28
32
|
- 0
|
29
33
|
- 20
|
@@ -31,7 +35,7 @@ dependencies:
|
|
31
35
|
version: 0.20.1
|
32
36
|
type: :runtime
|
33
37
|
version_requirements: *id001
|
34
|
-
description:
|
38
|
+
description: "Note: this gem is no longer offically supported by 10gen. For a list of MongoDB object mappers, see http://is.gd/gdehy"
|
35
39
|
email: mongodb-user@googlegroups.com
|
36
40
|
executables: []
|
37
41
|
|
@@ -51,6 +55,15 @@ files:
|
|
51
55
|
- Rakefile
|
52
56
|
- mongo-record.gemspec
|
53
57
|
- LICENSE
|
58
|
+
- tests/address.rb
|
59
|
+
- tests/course.rb
|
60
|
+
- tests/student.rb
|
61
|
+
- tests/class_in_module.rb
|
62
|
+
- tests/test_log_device.rb
|
63
|
+
- tests/test_mongo.rb
|
64
|
+
- tests/test_sql.rb
|
65
|
+
- tests/track2.rb
|
66
|
+
- tests/track3.rb
|
54
67
|
has_rdoc: true
|
55
68
|
homepage: http://www.mongodb.org
|
56
69
|
licenses: []
|
@@ -63,23 +76,27 @@ rdoc_options:
|
|
63
76
|
require_paths:
|
64
77
|
- lib
|
65
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
66
80
|
requirements:
|
67
81
|
- - ">="
|
68
82
|
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
69
84
|
segments:
|
70
85
|
- 0
|
71
86
|
version: "0"
|
72
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
73
89
|
requirements:
|
74
90
|
- - ">="
|
75
91
|
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
76
93
|
segments:
|
77
94
|
- 0
|
78
95
|
version: "0"
|
79
96
|
requirements: []
|
80
97
|
|
81
98
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.3.
|
99
|
+
rubygems_version: 1.3.7
|
83
100
|
signing_key:
|
84
101
|
specification_version: 3
|
85
102
|
summary: ActiveRecord-like models for MongoDB
|