active_mongo 0.2.0 → 0.2.1
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.
- data/VERSION +1 -1
- data/active_mongo.gemspec +2 -2
- data/lib/active_mongo.rb +9 -1
- data/lib/active_mongo_collection.rb +15 -6
- data/lib/active_mongo_has_many.rb +6 -2
- data/lib/active_mongo_instance.rb +10 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/active_mongo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{active_mongo}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mantas Masalskis"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-05}
|
13
13
|
s.description = %q{Schemaless Mongo ORM for Rails 3.0}
|
14
14
|
s.email = %q{mantas@idev.lt}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/active_mongo.rb
CHANGED
@@ -4,9 +4,17 @@ include Mongo
|
|
4
4
|
|
5
5
|
config = YAML::load(File.open("#{RAILS_ROOT}/config/mongo.yml"))[Rails.env]
|
6
6
|
|
7
|
-
$mongo_conn = Connection.new(config["host"], config["port"], :pool_size =>
|
7
|
+
$mongo_conn = Connection.new(config["host"], config["port"], :pool_size => 10, :timeout => 2)
|
8
8
|
$mongo_db = $mongo_conn.db(config["database"])
|
9
9
|
|
10
|
+
if defined?(PhusionPassenger)
|
11
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
12
|
+
if forked
|
13
|
+
$mongo_db.connect_to_master # Call db.connect_to_master to reconnect here
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
if config["user"]
|
11
19
|
if !$mongo_db.authenticate(config["user"], config["password"])
|
12
20
|
puts "Wrong MongoDB user and/or password!!!"
|
@@ -28,11 +28,12 @@ ActiveMongo::Base.class_eval do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def self.find(attrs = {})
|
32
|
-
|
33
|
-
|
31
|
+
# def self.find(attrs = {})
|
32
|
+
def self.find(selector = nil, *attrs)
|
33
|
+
if selector.class == String || selector.class == Mongo::ObjectID
|
34
|
+
id = Mongo::ObjectID.from_string(selector) if selector.class == String
|
34
35
|
|
35
|
-
id ||=
|
36
|
+
id ||= selector
|
36
37
|
|
37
38
|
obj = self.collection.find_one(id)
|
38
39
|
|
@@ -42,11 +43,19 @@ ActiveMongo::Base.class_eval do
|
|
42
43
|
|
43
44
|
return model
|
44
45
|
else
|
45
|
-
|
46
|
+
selector = self.scope.merge(selector || {}) if self.scope
|
46
47
|
|
47
48
|
ret = []
|
48
49
|
|
49
|
-
|
50
|
+
selector ||= {}
|
51
|
+
|
52
|
+
selector.each do |key, value|
|
53
|
+
if key.to_s.match(/\_id$/) && value.class == String
|
54
|
+
selector[key] = Mongo::ObjectID.from_string(value)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
self.collection.find(selector, attrs[0] || {}).to_a.map do |obj|
|
50
59
|
model = eval(self.name || @name).new
|
51
60
|
|
52
61
|
obj.each {|key, value| model.set_var(key, value) }
|
@@ -8,12 +8,16 @@ module ActiveMongo
|
|
8
8
|
def internal_has_manies_set(name, attrs)
|
9
9
|
@@internal_has_manies ||= {}
|
10
10
|
|
11
|
-
|
11
|
+
name = self.name.to_s+'___'+name.to_s
|
12
|
+
|
13
|
+
@@internal_has_manies[name.to_sym] = attrs if @@internal_has_manies[name.to_sym].nil?
|
12
14
|
end
|
13
15
|
|
14
16
|
def internal_has_manies_get(name)
|
15
17
|
@@internal_has_manies ||= {}
|
16
18
|
|
19
|
+
name = self.name.to_s+'___'+name.to_s
|
20
|
+
|
17
21
|
@@internal_has_manies[name.to_sym]
|
18
22
|
end
|
19
23
|
|
@@ -24,7 +28,7 @@ module ActiveMongo
|
|
24
28
|
return false if self.new_record?
|
25
29
|
|
26
30
|
attrs[:class_name] ||= name.to_s.classify
|
27
|
-
attrs[:foreign_key] ||= name.to_s.singularize.underscore+"_id"
|
31
|
+
attrs[:foreign_key] ||= self.class.name.to_s.singularize.underscore+"_id"
|
28
32
|
|
29
33
|
return eval(attrs[:class_name]).with_scope(attrs[:foreign_key] => self._id )
|
30
34
|
end
|
@@ -2,7 +2,7 @@ ActiveMongo::Base.class_eval do
|
|
2
2
|
def initialize(*attr)
|
3
3
|
@vars = []
|
4
4
|
|
5
|
-
attrs = attr[0] || {}
|
5
|
+
attrs = (attr[0] || {})
|
6
6
|
|
7
7
|
if self.class.attr_accessible_get.any?
|
8
8
|
attrs.delete_if {|key, value| !self.class.attr_accessible_get.include?(key.to_sym) }
|
@@ -28,6 +28,13 @@ ActiveMongo::Base.class_eval do
|
|
28
28
|
h[var] = instance_variable_get("@#{var}")
|
29
29
|
end
|
30
30
|
|
31
|
+
h.each do |key, value|
|
32
|
+
if key.to_s.match(/\_id$/) && value.class == String
|
33
|
+
h[key] = Mongo::ObjectID.from_string(value)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
31
38
|
return h
|
32
39
|
end
|
33
40
|
|
@@ -117,12 +124,12 @@ ActiveMongo::Base.class_eval do
|
|
117
124
|
return self
|
118
125
|
end
|
119
126
|
|
120
|
-
def unset(var)
|
127
|
+
def unset(var, do_not_save = false)
|
121
128
|
self.set_var(var, nil)
|
122
129
|
|
123
130
|
@vars.delete var.to_sym
|
124
131
|
|
125
|
-
return false if self.new_record?
|
132
|
+
return false if self.new_record? || do_not_save
|
126
133
|
|
127
134
|
hash = self.class.collection.find_one self._id
|
128
135
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mantas Masalskis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-05 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|