mm-commentable 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -5
- data/VERSION +1 -1
- data/lib/mongo_mapper/plugins/commentable.rb +4 -7
- data/lib/mongo_mapper/plugins/commentable/comment.rb +12 -2
- data/mm-commentable.gemspec +2 -2
- data/spec/mm-commentable_spec.rb +3 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -25,21 +25,24 @@ Then add the commentable plugin to you MongoMapper::Document
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
You must implement the on_add_comment callback! - however it can be an empty implementation
|
28
|
+
You must implement the #on_add_comment callback! - however it can be an empty implementation
|
29
|
+
It is called when a valid comment is added to the commentable item with #add_comment!
|
29
30
|
|
30
31
|
@post = Post.create
|
31
32
|
@commentor = User.create
|
32
33
|
|
33
34
|
@post.add_comment!("great post..", @user)
|
34
35
|
|
35
|
-
@post.comments_count
|
36
|
-
@posts.comments
|
36
|
+
@post.comments_count # => 1
|
37
|
+
@posts.comments # => [<Comment>]
|
37
38
|
|
38
|
-
The commentor association is polymorphic, so any class will probably work,
|
39
|
+
The commentor association is polymorphic, so any class will probably work,
|
40
|
+
I expect the commentor would normally be an instance of class <User>,
|
41
|
+
but it could be a <Person> or an <Account> and it will still work
|
39
42
|
|
40
43
|
|
41
44
|
== Contributing to mm-commentable
|
42
|
-
|
45
|
+
|
43
46
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
44
47
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
45
48
|
* Fork the project
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
@@ -7,26 +7,23 @@ module MongoMapper
|
|
7
7
|
def self.configure(model)
|
8
8
|
model.class_eval do
|
9
9
|
key :comments_count, Integer, :default => 0
|
10
|
-
|
11
|
-
|
12
|
-
def commentable?; true; end
|
10
|
+
many :comments
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
14
|
module InstanceMethods
|
15
|
+
def commentable?; true; end
|
17
16
|
|
18
17
|
def add_comment!(comment_body, commentor)
|
19
18
|
|
20
19
|
comment = self.comments.build({
|
21
20
|
:body => comment_body,
|
22
|
-
:commentor => commentor
|
23
|
-
:created_at => Time.now
|
21
|
+
:commentor => commentor
|
24
22
|
})
|
25
23
|
|
26
|
-
return false unless comment.
|
24
|
+
return false unless comment.save
|
27
25
|
|
28
26
|
self.increment('comments_count' => 1)
|
29
|
-
|
30
27
|
on_add_comment(comment)
|
31
28
|
end
|
32
29
|
|
@@ -1,12 +1,22 @@
|
|
1
1
|
class Comment
|
2
2
|
include MongoMapper::EmbeddedDocument
|
3
|
+
|
4
|
+
after_create :set_created_at
|
3
5
|
|
4
|
-
key :created_at, Time
|
5
6
|
key :body, String, :required => true
|
6
|
-
|
7
|
+
|
7
8
|
key :commentor_id, ObjectId
|
8
9
|
key :commentor_type, String
|
9
10
|
belongs_to :commentor, :polymorphic => true
|
10
11
|
|
12
|
+
key :created_at, Time
|
13
|
+
|
11
14
|
embedded_in :commentable
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_created_at
|
19
|
+
created_at = Time.now
|
20
|
+
save! unless new_record?
|
21
|
+
end
|
12
22
|
end
|
data/mm-commentable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mm-commentable}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Luke Cunningham"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-02-26}
|
13
13
|
s.description = %q{A very simple mongomapper plugin to make you models commentable}
|
14
14
|
s.email = %q{luke@icaruswings.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/mm-commentable_spec.rb
CHANGED
@@ -26,12 +26,15 @@ describe "MongoMapper::Plugins::ActsAsCommentable" do
|
|
26
26
|
|
27
27
|
it "should add the comment" do
|
28
28
|
@commentable.add_comment!("first comment", @luke)
|
29
|
+
@commentable.reload
|
30
|
+
|
29
31
|
@commentable.comments.size.should equal 1
|
30
32
|
end
|
31
33
|
|
32
34
|
it "should assign the commentor" do
|
33
35
|
@commentable.add_comment!("first comment", @luke)
|
34
36
|
comment = @commentable.comments.first
|
37
|
+
|
35
38
|
comment.commentor_id.should == @luke.id
|
36
39
|
comment.commentor_type.should == @luke.class.name
|
37
40
|
comment.commentor.should == @luke
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.2
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Luke Cunningham
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-26 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|