active_mongo 0.1.1 → 0.1.2
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/README.textile +91 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/active_mongo.gemspec +4 -4
- data/lib/active_mongo_instance.rb +6 -5
- metadata +4 -4
- data/README.rdoc +0 -7
data/README.textile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
h1. ActiveMongo
|
2
|
+
|
3
|
+
ActiveMongo is a Rails 3.0 and Ruby 1.9 compatible Mongo ORM.
|
4
|
+
|
5
|
+
It currently supports all common validations, find (single or many items) and has_many association.
|
6
|
+
|
7
|
+
Feel free to it if you're adventurous.
|
8
|
+
|
9
|
+
h2. Installation
|
10
|
+
|
11
|
+
# Add to your Rails application Gemfile
|
12
|
+
# Run gem bundle
|
13
|
+
# Load gem. For example, create initializer that says "require 'active_mongo'"
|
14
|
+
# Create config/mongo.yml. Format is the same as database.yml. Database, host and port are required
|
15
|
+
# Create a model, which is a subclass of ActiveMonog::Base
|
16
|
+
|
17
|
+
h2. Usage
|
18
|
+
|
19
|
+
h3. Validations
|
20
|
+
|
21
|
+
All ActiveModel validations are supported. validates_uniqueness_of with optional :scope => [:column] is available too.
|
22
|
+
|
23
|
+
h3. Collection methods
|
24
|
+
|
25
|
+
<pre><code>
|
26
|
+
Model.find(ID) # get by ID
|
27
|
+
Model.find #get whole collection
|
28
|
+
Model.find(args) #run a query, args are the same as for mongo_ruby_driver
|
29
|
+
|
30
|
+
Model.destroy_all
|
31
|
+
Model.destroy_all(args)
|
32
|
+
</code></pre>
|
33
|
+
|
34
|
+
h3. Create an object
|
35
|
+
|
36
|
+
<pre><code>
|
37
|
+
Model.new()
|
38
|
+
Model.new(:attribute => "value")
|
39
|
+
|
40
|
+
Model.save
|
41
|
+
</code></pre>
|
42
|
+
|
43
|
+
h3. Update an object
|
44
|
+
|
45
|
+
<pre><code>
|
46
|
+
object.attribute = "value" #No need to declare anywhere before setting, see?
|
47
|
+
object.update_attributes(:attribute => "value") #does not save!
|
48
|
+
|
49
|
+
object.unset(:attribute) #removes :attribute from the object and saves ONLY this change
|
50
|
+
|
51
|
+
object.save
|
52
|
+
object.save(false) #do not run validations
|
53
|
+
</code></pre>
|
54
|
+
|
55
|
+
h3. Destroy object
|
56
|
+
|
57
|
+
<pre><code>
|
58
|
+
object.destroy
|
59
|
+
</code></pre>
|
60
|
+
|
61
|
+
h3. HasMany Associations
|
62
|
+
|
63
|
+
<pre><code>
|
64
|
+
#in model
|
65
|
+
has_many :items#, :class_name => "Item", :foreign_key => "item_id"
|
66
|
+
|
67
|
+
#in code
|
68
|
+
object.items.find()
|
69
|
+
object.items.remove_all()
|
70
|
+
object.items.new()
|
71
|
+
</code></pre>
|
72
|
+
|
73
|
+
h3. Mass assignment
|
74
|
+
|
75
|
+
You can limit what may be assigned by passing a hash to #new or #update_attributes with this option.
|
76
|
+
|
77
|
+
<pre><code>
|
78
|
+
attr_accessible :attribute
|
79
|
+
</code></pre>
|
80
|
+
|
81
|
+
h2. Coming soon
|
82
|
+
|
83
|
+
* Named scopes
|
84
|
+
* Callbacks
|
85
|
+
* Tests
|
86
|
+
* Mongo authentication support
|
87
|
+
* Documentation
|
88
|
+
|
89
|
+
h2. License
|
90
|
+
|
91
|
+
This code is distributed under MIT license.
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ begin
|
|
8
8
|
gem.summary = %Q{Schemaless Mongo ORM for Rails 3.0}
|
9
9
|
gem.description = %Q{Schemaless Mongo ORM for Rails 3.0}
|
10
10
|
gem.email = "mantas@idev.lt"
|
11
|
-
gem.homepage = "http://github.com/mantas/
|
11
|
+
gem.homepage = "http://github.com/mantas/ActiveMongo"
|
12
12
|
gem.authors = ["Mantas Masalskis"]
|
13
13
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
14
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/active_mongo.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{active_mongo}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
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"]
|
@@ -14,13 +14,13 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.email = %q{mantas@idev.lt}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README.
|
17
|
+
"README.textile"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
22
|
"LICENSE",
|
23
|
-
"README.
|
23
|
+
"README.textile",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"active_mongo.gemspec",
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"test/helper.rb",
|
35
35
|
"test/test_active_mongo.rb"
|
36
36
|
]
|
37
|
-
s.homepage = %q{http://github.com/mantas/
|
37
|
+
s.homepage = %q{http://github.com/mantas/ActiveMongo}
|
38
38
|
s.rdoc_options = ["--charset=UTF-8"]
|
39
39
|
s.require_paths = ["lib"]
|
40
40
|
s.rubygems_version = %q{1.3.5}
|
@@ -29,8 +29,8 @@ ActiveMongo::Base.class_eval do
|
|
29
29
|
return h
|
30
30
|
end
|
31
31
|
|
32
|
-
def save
|
33
|
-
return false if !self.valid?
|
32
|
+
def save(do_validate = true)
|
33
|
+
return false if do_validate && !self.valid?
|
34
34
|
|
35
35
|
id = self.class.collection.save(self.to_hash)
|
36
36
|
|
@@ -76,6 +76,10 @@ ActiveMongo::Base.class_eval do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def unset(var)
|
79
|
+
self.set_var(var, nil)
|
80
|
+
|
81
|
+
@vars.delete var.to_sym
|
82
|
+
|
79
83
|
return false if self.new_record?
|
80
84
|
|
81
85
|
hash = self.class.collection.find_one self._id
|
@@ -84,9 +88,6 @@ ActiveMongo::Base.class_eval do
|
|
84
88
|
|
85
89
|
self.class.collection.save(hash)
|
86
90
|
|
87
|
-
self.set_value(var, nil)
|
88
|
-
|
89
|
-
@vars.delete var.to_sym
|
90
91
|
|
91
92
|
true
|
92
93
|
end
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mantas Masalskis
|
@@ -30,12 +30,12 @@ extensions: []
|
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
32
|
- LICENSE
|
33
|
-
- README.
|
33
|
+
- README.textile
|
34
34
|
files:
|
35
35
|
- .document
|
36
36
|
- .gitignore
|
37
37
|
- LICENSE
|
38
|
-
- README.
|
38
|
+
- README.textile
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
41
|
- active_mongo.gemspec
|
@@ -49,7 +49,7 @@ files:
|
|
49
49
|
- test/helper.rb
|
50
50
|
- test/test_active_mongo.rb
|
51
51
|
has_rdoc: true
|
52
|
-
homepage: http://github.com/mantas/
|
52
|
+
homepage: http://github.com/mantas/ActiveMongo
|
53
53
|
licenses: []
|
54
54
|
|
55
55
|
post_install_message:
|
data/README.rdoc
DELETED