acts_as_commentable 4.0.1 → 4.0.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.
- checksums.yaml +15 -0
- data/README.rdoc +33 -11
- data/lib/commentable_methods.rb +39 -13
- data/lib/generators/comment/{USEGA → USAGE} +0 -0
- metadata +7 -9
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDQyZmE5ZjZmMmNhMDE1MTk2YzcwOTA1ZGE2N2ViMjZlNTE4NzQ3NQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDRjMzI1NTNkMjVkMDgxZTk5MzM5ZTNiMzU0ODlkZmM3MmFjOTRkYQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjI5OWEyZmJkNjJjMTRhNmEzZGY2ODMwNTdjOGFmNjNiNGYxNjI3Y2EwODhj
|
10
|
+
YTVmZDkzOTRlMjcxMDU2NjVlMTQzZjdkYTE4MWQ0NTYxNGMyZDM2ZjM0MzQ3
|
11
|
+
MDdmY2Y4ZjBiZDZlY2UzNjlhM2VlMjdkNjNlNTZlYzg2NzY3YjM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWI1MzQ5NTQyZmYzZGNlMjFmOGM1ODIwMjA2ZGExYTI1NmI4NDNmOTU3MjQ0
|
14
|
+
NjE3Yzc3MDY3NDE3ZjI4ZTAyNjdlYWIyM2ZhYmFhMmYwNjdhM2E5N2Q1YjMw
|
15
|
+
OTBlZDA1NWE5ZjIzOGQwZmU5MGRmM2Q1ZDMzMzk1MmI2M2I1NzA=
|
data/README.rdoc
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
= Acts As Commentable
|
2
2
|
|
3
|
-
|
3
|
+
Provides a single Comment model that can be attached to any model(s) within your app. It creates
|
4
|
+
a Comment model and handles the plumbing between that model and any models that you declare to be
|
5
|
+
commentable models.
|
6
|
+
|
4
7
|
|
5
8
|
== Installation :
|
6
9
|
|
@@ -16,7 +19,7 @@ Add the following line to your Gemfile
|
|
16
19
|
|
17
20
|
=== Rails 2
|
18
21
|
|
19
|
-
gem 'acts_as_commentable', git: 'git@github.com:jackdempsey/acts_as_commentable.git'
|
22
|
+
gem 'acts_as_commentable', git: 'git@github.com:jackdempsey/acts_as_commentable.git', branch: '2.x'
|
20
23
|
|
21
24
|
|
22
25
|
== Generator
|
@@ -30,29 +33,33 @@ Add the following line to your Gemfile
|
|
30
33
|
|
31
34
|
script/generate comment
|
32
35
|
|
33
|
-
Then migrate your database:
|
36
|
+
Then migrate your database to add the comments model:
|
34
37
|
|
35
38
|
rake db:migrate
|
36
39
|
|
37
40
|
== Usage
|
38
|
-
|
39
|
-
Make
|
41
|
+
|
42
|
+
Make the desired ActiveRecord model act as commentable:
|
40
43
|
|
41
44
|
class Post < ActiveRecord::Base
|
42
45
|
acts_as_commentable
|
43
46
|
end
|
44
|
-
|
45
|
-
Add a comment to a model instance:
|
47
|
+
|
48
|
+
Add a comment to a model instance by adding the following to the controller:
|
46
49
|
|
47
50
|
commentable = Post.create
|
48
|
-
commentable.comments.create
|
51
|
+
comment = commentable.comments.create
|
52
|
+
comment.title = "First comment."
|
53
|
+
comment.comment = "This is the first comment."
|
54
|
+
comment.save
|
55
|
+
|
49
56
|
|
50
|
-
Fetch comments for
|
57
|
+
Fetch comments for the commentable model by adding the following to the view:
|
51
58
|
|
52
59
|
commentable = Post.find(1)
|
53
60
|
comments = commentable.comments.recent.limit(10).all
|
54
61
|
|
55
|
-
|
62
|
+
You can also add different types of comments to a model:
|
56
63
|
|
57
64
|
class Todo < ActiveRecord::Base
|
58
65
|
acts_as_commentable :public, :private
|
@@ -60,11 +67,26 @@ Add multiple type of comments to a model:
|
|
60
67
|
|
61
68
|
*Note:* This feature is only available from version 4.0 and above
|
62
69
|
|
63
|
-
|
70
|
+
To fetch the different types of comments for this model:
|
64
71
|
|
65
72
|
public_comments = Todo.find(1).public_comments
|
66
73
|
private_comments = Todo.find(1).private_comments
|
67
74
|
|
75
|
+
|
76
|
+
By default, `acts_as_commentable` will assume you are using a `Comment` model.
|
77
|
+
To change this, or change any other join options, pass in an options hash:
|
78
|
+
|
79
|
+
class Todo < ActiveRecord::Base
|
80
|
+
acts_as_commentable { class_name: 'MyComment' }
|
81
|
+
end
|
82
|
+
|
83
|
+
This also works in conjunction with comment types:
|
84
|
+
|
85
|
+
class Todo < ActiveRecord::Base
|
86
|
+
acts_as_commentable :public, :private, { class_name: 'MyComment' }
|
87
|
+
end
|
88
|
+
|
89
|
+
|
68
90
|
== Credits
|
69
91
|
|
70
92
|
Xelipe - This plugin is heavily influenced by Acts As Taggable.
|
data/lib/commentable_methods.rb
CHANGED
@@ -6,30 +6,56 @@ module Juixe
|
|
6
6
|
module Commentable #:nodoc:
|
7
7
|
|
8
8
|
def self.included(base)
|
9
|
-
base.extend ClassMethods
|
9
|
+
base.extend ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module HelperMethods
|
13
|
+
private
|
14
|
+
def define_role_based_inflection(role)
|
15
|
+
send("define_role_based_inflection_#{Rails.version.first}", role)
|
16
|
+
end
|
17
|
+
|
18
|
+
def define_role_based_inflection_3(role)
|
19
|
+
has_many "#{role.to_s}_comments".to_sym,
|
20
|
+
has_many_options(role).merge(:conditions => { role: role.to_s })
|
21
|
+
end
|
22
|
+
|
23
|
+
def define_role_based_inflection_4(role)
|
24
|
+
has_many "#{role.to_s}_comments".to_sym,
|
25
|
+
-> { where(role: role.to_s) },
|
26
|
+
has_many_options(role)
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_many_options(role)
|
30
|
+
{:class_name => "Comment",
|
31
|
+
:as => :commentable,
|
32
|
+
:dependent => :destroy,
|
33
|
+
:before_add => Proc.new { |x, c| c.role = role.to_s }
|
34
|
+
}
|
35
|
+
end
|
10
36
|
end
|
11
37
|
|
12
38
|
module ClassMethods
|
39
|
+
include HelperMethods
|
40
|
+
|
13
41
|
def acts_as_commentable(*args)
|
14
|
-
|
42
|
+
options = args.to_a.flatten.compact.partition{ |opt| opt.kind_of? Hash }
|
43
|
+
comment_roles = options.last.blank? ? nil : options.last.flatten.compact.map(&:to_sym)
|
44
|
+
|
45
|
+
join_options = options.first.blank? ? [{}] : options.first
|
46
|
+
throw 'Only one set of options can be supplied for the join' if join_options.length > 1
|
47
|
+
join_options = join_options.first
|
15
48
|
|
16
49
|
class_attribute :comment_types
|
17
50
|
self.comment_types = (comment_roles.blank? ? [:comments] : comment_roles)
|
18
51
|
|
19
|
-
options = ((args.blank? or args[0].blank?) ? {} : args[0])
|
20
|
-
|
21
52
|
if !comment_roles.blank?
|
22
53
|
comment_roles.each do |role|
|
23
|
-
|
24
|
-
-> { where(role: role.to_s) },
|
25
|
-
{:class_name => "Comment",
|
26
|
-
:as => :commentable,
|
27
|
-
:dependent => :destroy,
|
28
|
-
:before_add => Proc.new { |x, c| c.role = role.to_s }}
|
54
|
+
define_role_based_inflection(role)
|
29
55
|
end
|
30
|
-
has_many :all_comments, {:as => :commentable, :dependent => :destroy, class_name:
|
56
|
+
has_many :all_comments, { :as => :commentable, :dependent => :destroy, class_name: 'Comment' }.merge(join_options)
|
31
57
|
else
|
32
|
-
has_many :comments, {:as => :commentable, :dependent => :destroy}
|
58
|
+
has_many :comments, {:as => :commentable, :dependent => :destroy}.merge(join_options)
|
33
59
|
end
|
34
60
|
|
35
61
|
comment_types.each do |role|
|
@@ -40,7 +66,7 @@ module Juixe
|
|
40
66
|
Comment.find_comments_for_commentable(commentable, obj.id, "#{role.to_s}")
|
41
67
|
end
|
42
68
|
|
43
|
-
def self.find_#{method_name}_by_user(user)
|
69
|
+
def self.find_#{method_name}_by_user(user)
|
44
70
|
commentable = self.base_class.name
|
45
71
|
Comment.where(["user_id = ? and commentable_type = ? and role = ?", user.id, commentable, "#{role.to_s}"]).order("created_at DESC")
|
46
72
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_commentable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
5
|
-
prerelease:
|
4
|
+
version: 4.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein
|
9
8
|
autorequire: acts_as_commentable
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-10-02 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Plugin/gem that provides comment functionality
|
15
14
|
email: unknown@juixe.com
|
@@ -21,36 +20,35 @@ extra_rdoc_files:
|
|
21
20
|
files:
|
22
21
|
- MIT-LICENSE
|
23
22
|
- README.rdoc
|
23
|
+
- init.rb
|
24
|
+
- install.rb
|
24
25
|
- lib/acts_as_commentable.rb
|
25
26
|
- lib/comment_methods.rb
|
26
27
|
- lib/commentable_methods.rb
|
28
|
+
- lib/generators/comment/USAGE
|
27
29
|
- lib/generators/comment/comment_generator.rb
|
28
30
|
- lib/generators/comment/templates/comment.rb
|
29
31
|
- lib/generators/comment/templates/create_comments.rb
|
30
|
-
- lib/generators/comment/USEGA
|
31
|
-
- init.rb
|
32
|
-
- install.rb
|
33
32
|
homepage: http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
|
34
33
|
licenses: []
|
34
|
+
metadata: {}
|
35
35
|
post_install_message:
|
36
36
|
rdoc_options: []
|
37
37
|
require_paths:
|
38
38
|
- lib
|
39
39
|
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
40
|
requirements:
|
42
41
|
- - ! '>='
|
43
42
|
- !ruby/object:Gem::Version
|
44
43
|
version: '0'
|
45
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
-
none: false
|
47
45
|
requirements:
|
48
46
|
- - ! '>='
|
49
47
|
- !ruby/object:Gem::Version
|
50
48
|
version: '0'
|
51
49
|
requirements: []
|
52
50
|
rubyforge_project:
|
53
|
-
rubygems_version:
|
51
|
+
rubygems_version: 2.2.2
|
54
52
|
signing_key:
|
55
53
|
specification_version: 3
|
56
54
|
summary: Plugin/gem that provides comment functionality
|