acts_as_commentable_with_replies 0.0.1 → 0.0.3
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.md +94 -3
- data/acts_as_commentable_with_replies.gemspec +0 -2
- data/lib/acts_as_commentable_with_replies.rb +1 -2
- data/lib/acts_as_commentable_with_replies/commentable.rb +4 -3
- data/lib/acts_as_commentable_with_replies/commenter.rb +2 -1
- data/lib/acts_as_commentable_with_replies/version.rb +1 -1
- metadata +5 -35
data/README.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# Acts As Commentable With Replies
|
2
2
|
|
3
|
-
|
3
|
+
## Please don't use it as of now. Because it's under testing.
|
4
|
+
|
5
|
+
Acts As Commentable With Replies is a Ruby Gem specifically written for Rails/ActiveRecord models.
|
6
|
+
The main goals of this gem are:
|
7
|
+
|
8
|
+
- Allow any model to be commentable.
|
9
|
+
- Allow any model to post comment. In other words, comments do not have to come from a user,
|
10
|
+
they can come from any model (such as a Group or Team).
|
11
|
+
- Provide an easy to write/read syntax.
|
4
12
|
|
5
13
|
## Installation
|
6
14
|
|
@@ -16,9 +24,92 @@ Or install it yourself as:
|
|
16
24
|
|
17
25
|
$ gem install acts_as_commentable_with_replies
|
18
26
|
|
27
|
+
|
28
|
+
### Database Migrations & Model Generator
|
29
|
+
|
30
|
+
Acts As Commentable With Replies uses a comments table to store all comments. To
|
31
|
+
generate migration, model just use.
|
32
|
+
|
33
|
+
rails generate acts_as_commentable_with_replies:migration
|
34
|
+
rake db:migrate
|
35
|
+
|
36
|
+
You will get a performance increase by adding in cached columns to your model's
|
37
|
+
tables. You will have to do this manually through your own migrations. See the
|
38
|
+
caching section of this document for more information.
|
39
|
+
|
19
40
|
## Usage
|
20
41
|
|
21
|
-
|
42
|
+
### Commentable Models
|
43
|
+
|
44
|
+
class Post < ActiveRecord::Base
|
45
|
+
acts_as_commentable
|
46
|
+
end
|
47
|
+
|
48
|
+
@post = Post.new(:title => 'my post!')
|
49
|
+
@post.save
|
50
|
+
|
51
|
+
@post.comment(:commenter => @user, :message => 'hello this is my comment!')
|
52
|
+
@post.comments.size # => 1
|
53
|
+
|
54
|
+
You can also use it as a reply system in comments
|
55
|
+
|
56
|
+
@comment = Comment.find(1)
|
57
|
+
@post.comment(:commenter => @user, :message => 'nice!', :parent => @comment)
|
58
|
+
|
59
|
+
|
60
|
+
### Commenter Models
|
61
|
+
|
62
|
+
class User < ActiveRecord::Base
|
63
|
+
acts_as_commenter
|
64
|
+
end
|
65
|
+
|
66
|
+
@post = Post.find(1)
|
67
|
+
@user = User.find(1)
|
68
|
+
@user.comment(:commentable => @post, :message => 'Comment posted through Commenter')
|
69
|
+
|
70
|
+
|
71
|
+
### Some Useful syntaxes
|
72
|
+
|
73
|
+
# to check whether or not user has posted comment on it
|
74
|
+
@post.commented_by?(@user)
|
75
|
+
|
76
|
+
#or
|
77
|
+
@user.commented_on?(@post)
|
78
|
+
|
79
|
+
# to get the list of root comments, not replies
|
80
|
+
@post.root_comments
|
81
|
+
|
82
|
+
|
83
|
+
### Caching
|
84
|
+
|
85
|
+
To speed up performance you can add cache columns to your commentable model's table. These
|
86
|
+
columns will automatically be updated after each comment. For example, if we wanted
|
87
|
+
to speed up @post we would use the following migration:
|
88
|
+
|
89
|
+
class AddCachedCommentsToPosts < ActiveRecord::Migration
|
90
|
+
def self.up
|
91
|
+
add_column :posts, :cached_comments_total, :integer, :default => 0
|
92
|
+
add_index :posts, :cached_comments_total
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.down
|
96
|
+
remove_column :posts, :cached_comments_total
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
## TODO
|
102
|
+
|
103
|
+
Don't know. Haven't decided yet.
|
104
|
+
|
105
|
+
|
106
|
+
## Credits
|
107
|
+
* [Ryan T](https://github.com/ryanto) - This gem is heavily influenced from [acts_as_voteable]
|
108
|
+
* [Evan David Light](https://github.com/elight) - Because this gem is inspired from [acts_as_commentable_with_threading].
|
109
|
+
But [acts_as_commentable_with_threading] only supports user as commenter and there are no shortcuts to create comment.
|
110
|
+
|
111
|
+
Thank you guys! Without you I don't know if it was possible or not!
|
112
|
+
|
22
113
|
|
23
114
|
## Contributing
|
24
115
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'active_support/inflector'
|
3
|
-
|
3
|
+
require 'awesome_nested_set'
|
4
4
|
|
5
5
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
6
|
|
@@ -9,7 +9,6 @@ module ActsAsCommentableWithReplies
|
|
9
9
|
if defined?(ActiveRecord::Base)
|
10
10
|
require 'acts_as_commentable_with_replies/extenders/commentable'
|
11
11
|
require 'acts_as_commentable_with_replies/extenders/commenter'
|
12
|
-
#require 'acts_as_commentable_with_replies/comment'
|
13
12
|
ActiveRecord::Base.extend ActsAsCommentableWithReplies::Extenders::Commentable
|
14
13
|
ActiveRecord::Base.extend ActsAsCommentableWithReplies::Extenders::Commenter
|
15
14
|
end
|
@@ -22,7 +22,7 @@ module ActsAsCommentableWithReplies
|
|
22
22
|
|
23
23
|
# voting
|
24
24
|
def comment(args = {})
|
25
|
-
return
|
25
|
+
return nil if args[:commenter].nil? || args[:message].nil?
|
26
26
|
|
27
27
|
comment = Comment.new(
|
28
28
|
:commentable => self,
|
@@ -33,11 +33,12 @@ module ActsAsCommentableWithReplies
|
|
33
33
|
if comment.save
|
34
34
|
update_cached_comments
|
35
35
|
comment.move_to_child_of(args[:parent]) if !args[:parent].nil?
|
36
|
-
|
36
|
+
comment
|
37
37
|
else
|
38
|
-
|
38
|
+
nil
|
39
39
|
end
|
40
40
|
end
|
41
|
+
alias :comment! :comment
|
41
42
|
|
42
43
|
|
43
44
|
# caching
|
@@ -14,9 +14,10 @@ module ActsAsCommentableWithReplies
|
|
14
14
|
|
15
15
|
# voting
|
16
16
|
def comment(args = {})
|
17
|
-
return
|
17
|
+
return nil if args[:commentable].nil? || args[:message].nil?
|
18
18
|
args[:commentable].comment args.merge({:commenter => self})
|
19
19
|
end
|
20
|
+
alias :comment! :comment
|
20
21
|
|
21
22
|
# results
|
22
23
|
def commented_on?(commentable)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_commentable_with_replies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Filvo Interactive
|
@@ -32,40 +32,10 @@ dependencies:
|
|
32
32
|
version: "3.0"
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: activerecord
|
37
|
-
prerelease: false
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 7
|
44
|
-
segments:
|
45
|
-
- 3
|
46
|
-
- 0
|
47
|
-
version: "3.0"
|
48
|
-
type: :runtime
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: activesupport
|
52
|
-
prerelease: false
|
53
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
|
-
requirements:
|
56
|
-
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
hash: 7
|
59
|
-
segments:
|
60
|
-
- 3
|
61
|
-
- 0
|
62
|
-
version: "3.0"
|
63
|
-
type: :runtime
|
64
|
-
version_requirements: *id003
|
65
35
|
- !ruby/object:Gem::Dependency
|
66
36
|
name: awesome_nested_set
|
67
37
|
prerelease: false
|
68
|
-
requirement: &
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
69
39
|
none: false
|
70
40
|
requirements:
|
71
41
|
- - ">="
|
@@ -76,7 +46,7 @@ dependencies:
|
|
76
46
|
- 0
|
77
47
|
version: "2.0"
|
78
48
|
type: :runtime
|
79
|
-
version_requirements: *
|
49
|
+
version_requirements: *id002
|
80
50
|
description: Acts as Commentable with Replies
|
81
51
|
email:
|
82
52
|
- info@filvo.com
|