active_mongo 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/active_mongo.gemspec +3 -2
- data/lib/active_mongo.rb +5 -61
- data/lib/active_mongo_attr_accessible.rb +9 -7
- data/lib/active_mongo_start.rb +64 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
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.
|
8
|
+
s.version = "0.3.0"
|
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-02-
|
12
|
+
s.date = %q{2010-02-06}
|
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 = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/active_mongo_instance.rb",
|
33
33
|
"lib/active_mongo_named_scopes.rb",
|
34
34
|
"lib/active_mongo_scope.rb",
|
35
|
+
"lib/active_mongo_start.rb",
|
35
36
|
"lib/active_mongo_uniquenesss.rb",
|
36
37
|
"test/helper.rb",
|
37
38
|
"test/test_active_mongo.rb"
|
data/lib/active_mongo.rb
CHANGED
@@ -1,64 +1,8 @@
|
|
1
|
-
require 'mongo'
|
2
|
-
require 'active_mongo_uniquenesss'
|
3
|
-
include Mongo
|
4
|
-
|
5
|
-
config = YAML::load(File.open("#{RAILS_ROOT}/config/mongo.yml"))[Rails.env]
|
6
|
-
|
7
|
-
$mongo_conn = Connection.new(config["host"], config["port"], :pool_size => 10, :timeout => 2)
|
8
|
-
$mongo_db = $mongo_conn.db(config["database"])
|
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
|
-
|
18
|
-
if config["user"]
|
19
|
-
if !$mongo_db.authenticate(config["user"], config["password"])
|
20
|
-
puts "Wrong MongoDB user and/or password!!!"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
require 'active_mongo_has_many'
|
25
|
-
require 'active_mongo_attr_accessible'
|
26
|
-
require 'active_mongo_indexes'
|
27
|
-
require 'active_mongo_named_scopes'
|
28
|
-
|
29
1
|
module ActiveMongo
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
extend ActiveModel::Callbacks
|
36
|
-
extend ActiveMongo::Indexes::ClassMethods
|
37
|
-
extend ActiveMongo::AttrAccessible::ClassMethods
|
38
|
-
extend ActiveMongo::NamedScopes::ClassMethods
|
39
|
-
extend ActiveMongo::HasMany::ClassMethods
|
40
|
-
include ActiveMongo::HasMany::InstanceMethods
|
41
|
-
|
42
|
-
define_model_callbacks :create, :save, :update
|
43
|
-
define_model_callbacks :initializer, :only => :after
|
44
|
-
|
45
|
-
class << self; attr_accessor :scope; end
|
46
|
-
|
47
|
-
def self.extended(klass)
|
48
|
-
class << klass
|
49
|
-
alias __old_name name
|
50
|
-
def name(*args, &blk)
|
51
|
-
return @name || self.__old_name
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
self.extended(self)
|
57
|
-
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
railtie_name :active_mongo
|
4
|
+
initializer "active_mongo.initialize_active_mongo" do |app|
|
5
|
+
require 'active_mongo_start'
|
6
|
+
end
|
58
7
|
end
|
59
8
|
end
|
60
|
-
|
61
|
-
|
62
|
-
require 'active_mongo_collection'
|
63
|
-
require 'active_mongo_instance'
|
64
|
-
require 'active_mongo_scope'
|
@@ -2,31 +2,33 @@ module ActiveMongo
|
|
2
2
|
module AttrAccessible
|
3
3
|
module ClassMethods
|
4
4
|
def attr_accessible(*input)
|
5
|
-
@@internal_attr_accessible
|
5
|
+
@@internal_attr_accessible ||= {}
|
6
|
+
@@internal_attr_accessible[self.name] ||= []
|
6
7
|
|
7
8
|
input.each do |field|
|
8
|
-
@@internal_attr_accessible.push(field.to_sym).uniq!
|
9
|
+
@@internal_attr_accessible[self.name].push(field.to_sym).uniq!
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
13
|
def attr_accessible_get
|
13
|
-
@@internal_attr_accessible || []
|
14
|
+
@@internal_attr_accessible[self.name] || []
|
14
15
|
end
|
15
16
|
|
16
17
|
def attr_clear(*input)
|
17
|
-
@@internal_attr_clear
|
18
|
+
@@internal_attr_clear ||= {}
|
19
|
+
@@internal_attr_clear[self.name] ||= []
|
18
20
|
|
19
21
|
input.each do |field|
|
20
|
-
@@internal_attr_clear.push(field.to_sym).uniq!
|
22
|
+
@@internal_attr_clear[self.name].push(field.to_sym).uniq!
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
def attr_accessible_get
|
25
|
-
@@internal_attr_accessible || []
|
27
|
+
@@internal_attr_accessible[self.name] || []
|
26
28
|
end
|
27
29
|
|
28
30
|
def attr_clear_get
|
29
|
-
@@internal_attr_clear || []
|
31
|
+
@@internal_attr_clear[self.name] || []
|
30
32
|
end
|
31
33
|
|
32
34
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'mongo'
|
2
|
+
require 'active_mongo_uniquenesss'
|
3
|
+
include Mongo
|
4
|
+
|
5
|
+
config = YAML::load(File.open("#{RAILS_ROOT}/config/mongo.yml"))[Rails.env]
|
6
|
+
|
7
|
+
$mongo_conn = Connection.new(config["host"], config["port"], :pool_size => 10, :timeout => 2)
|
8
|
+
$mongo_db = $mongo_conn.db(config["database"])
|
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
|
+
|
18
|
+
if config["user"]
|
19
|
+
if !$mongo_db.authenticate(config["user"], config["password"])
|
20
|
+
puts "Wrong MongoDB user and/or password!!!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'active_mongo_has_many'
|
25
|
+
require 'active_mongo_attr_accessible'
|
26
|
+
require 'active_mongo_indexes'
|
27
|
+
require 'active_mongo_named_scopes'
|
28
|
+
|
29
|
+
module ActiveMongo
|
30
|
+
|
31
|
+
class Base
|
32
|
+
include ActiveModel::Conversion
|
33
|
+
include ActiveModel::Validations
|
34
|
+
include ActiveModel::Callbacks
|
35
|
+
extend ActiveModel::Callbacks
|
36
|
+
extend ActiveMongo::Indexes::ClassMethods
|
37
|
+
extend ActiveMongo::AttrAccessible::ClassMethods
|
38
|
+
extend ActiveMongo::NamedScopes::ClassMethods
|
39
|
+
extend ActiveMongo::HasMany::ClassMethods
|
40
|
+
include ActiveMongo::HasMany::InstanceMethods
|
41
|
+
|
42
|
+
define_model_callbacks :create, :save, :update
|
43
|
+
define_model_callbacks :initializer, :only => :after
|
44
|
+
|
45
|
+
class << self; attr_accessor :scope; end
|
46
|
+
|
47
|
+
def self.extended(klass)
|
48
|
+
class << klass
|
49
|
+
alias __old_name name
|
50
|
+
def name(*args, &blk)
|
51
|
+
return @name || self.__old_name
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
self.extended(self)
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
require 'active_mongo_collection'
|
63
|
+
require 'active_mongo_instance'
|
64
|
+
require 'active_mongo_scope'
|
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.
|
4
|
+
version: 0.3.0
|
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-02-
|
12
|
+
date: 2010-02-06 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/active_mongo_instance.rb
|
39
39
|
- lib/active_mongo_named_scopes.rb
|
40
40
|
- lib/active_mongo_scope.rb
|
41
|
+
- lib/active_mongo_start.rb
|
41
42
|
- lib/active_mongo_uniquenesss.rb
|
42
43
|
- test/helper.rb
|
43
44
|
- test/test_active_mongo.rb
|