acts_as_commentable_with_replies 0.0.3 → 0.0.5
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.
|
@@ -4,7 +4,7 @@ module ActsAsCommentableWithReplies
|
|
|
4
4
|
def self.included base
|
|
5
5
|
base.class_eval do
|
|
6
6
|
belongs_to :commentable, :polymorphic => true
|
|
7
|
-
has_many :comments, :as => :commentable do
|
|
7
|
+
has_many :comments, :as => :commentable, :dependent => :delete_all do
|
|
8
8
|
def commenters
|
|
9
9
|
includes(:commenter).map(&:commenter)
|
|
10
10
|
end
|
|
@@ -21,48 +21,41 @@ module ActsAsCommentableWithReplies
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# voting
|
|
24
|
-
def comment
|
|
24
|
+
def comment args = {}
|
|
25
25
|
return nil if args[:commenter].nil? || args[:message].nil?
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
__comment__ = Comment.new(
|
|
28
28
|
:commentable => self,
|
|
29
29
|
:commenter => args[:commenter],
|
|
30
30
|
:message => args[:message]
|
|
31
31
|
)
|
|
32
32
|
|
|
33
|
-
if
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if __comment__.save
|
|
34
|
+
update_comments_counter
|
|
35
|
+
__comment__.move_to_child_of(args[:parent]) if !args[:parent].nil?
|
|
36
|
+
__comment__
|
|
37
37
|
else
|
|
38
38
|
nil
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
|
-
alias :comment! :comment
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
updates = {}
|
|
47
|
-
if self.respond_to?(:cached_comments_total=)
|
|
48
|
-
updates[:cached_comments_total] = count_comments_total(true)
|
|
49
|
-
end
|
|
50
|
-
self.update_attributes(updates, :without_protection => true) if updates.size > 0
|
|
42
|
+
def commented_by? commenter
|
|
43
|
+
__comments__ = find_comments :commenter_id => commenter.id, :commenter_type => commenter.class.name
|
|
44
|
+
__comments__.count > 0
|
|
51
45
|
end
|
|
52
46
|
|
|
53
47
|
|
|
54
|
-
#
|
|
55
|
-
def
|
|
56
|
-
if
|
|
57
|
-
|
|
48
|
+
# caching
|
|
49
|
+
def update_comments_counter
|
|
50
|
+
if self.respond_to?(:cached_comments_total=)
|
|
51
|
+
self.class.where(:id => self.id).update_all(:cached_comments_total => self.comments.count)
|
|
58
52
|
end
|
|
59
|
-
find_comments.count
|
|
60
53
|
end
|
|
61
54
|
|
|
62
55
|
|
|
63
56
|
# results
|
|
64
|
-
def find_comments
|
|
65
|
-
comments.where(extra_conditions)
|
|
57
|
+
def find_comments extra_conditions = {}
|
|
58
|
+
self.comments.where(extra_conditions)
|
|
66
59
|
end
|
|
67
60
|
|
|
68
61
|
def root_comments
|
|
@@ -70,13 +63,5 @@ module ActsAsCommentableWithReplies
|
|
|
70
63
|
end
|
|
71
64
|
|
|
72
65
|
|
|
73
|
-
# commenters
|
|
74
|
-
def commented_by?(commenter)
|
|
75
|
-
comments = find_comments :commenter_id => commenter.id, :commenter_type => commenter.class.name
|
|
76
|
-
comments.count > 0
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
66
|
end
|
|
82
67
|
end
|
|
@@ -4,7 +4,7 @@ module ActsAsCommentableWithReplies
|
|
|
4
4
|
def self.included(base)
|
|
5
5
|
base.class_eval do
|
|
6
6
|
belongs_to :commenter, :polymorphic => true
|
|
7
|
-
has_many :comments, :as => :commenter do
|
|
7
|
+
has_many :comments, :as => :commenter, :dependent => :delete_all do
|
|
8
8
|
def commentables
|
|
9
9
|
includes(:commentable).map(&:commentable)
|
|
10
10
|
end
|
|
@@ -13,24 +13,19 @@ module ActsAsCommentableWithReplies
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
# voting
|
|
16
|
-
def comment
|
|
16
|
+
def comment args = {}
|
|
17
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
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
|
|
23
22
|
def commented_on?(commentable)
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
__comments__ = find_comments(:commentable_id => commentable.id, :commentable_type => commentable.class.name)
|
|
24
|
+
__comments__.size > 0
|
|
26
25
|
end
|
|
27
26
|
|
|
28
27
|
def find_comments(extra_conditions = {})
|
|
29
|
-
comments.where(extra_conditions)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def find_comments_for_class(klass, extra_conditions = {})
|
|
33
|
-
find_comments extra_conditions.merge({:commentable_type => klass.name})
|
|
28
|
+
self.comments.where(extra_conditions)
|
|
34
29
|
end
|
|
35
30
|
|
|
36
31
|
end
|
metadata
CHANGED
|
@@ -1,62 +1,55 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acts_as_commentable_with_replies
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
prerelease:
|
|
6
|
-
segments:
|
|
7
|
-
- 0
|
|
8
|
-
- 0
|
|
9
|
-
- 3
|
|
10
|
-
version: 0.0.3
|
|
11
6
|
platform: ruby
|
|
12
|
-
authors:
|
|
7
|
+
authors:
|
|
13
8
|
- Filvo Interactive
|
|
14
9
|
autorequire:
|
|
15
10
|
bindir: bin
|
|
16
11
|
cert_chain: []
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- !ruby/object:Gem::Dependency
|
|
12
|
+
date: 2012-08-06 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
21
15
|
name: rails
|
|
22
|
-
|
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
24
17
|
none: false
|
|
25
|
-
requirements:
|
|
18
|
+
requirements:
|
|
26
19
|
- - ~>
|
|
27
|
-
- !ruby/object:Gem::Version
|
|
28
|
-
|
|
29
|
-
segments:
|
|
30
|
-
- 3
|
|
31
|
-
- 0
|
|
32
|
-
version: "3.0"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '3.0'
|
|
33
22
|
type: :development
|
|
34
|
-
version_requirements: *id001
|
|
35
|
-
- !ruby/object:Gem::Dependency
|
|
36
|
-
name: awesome_nested_set
|
|
37
23
|
prerelease: false
|
|
38
|
-
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
25
|
none: false
|
|
40
|
-
requirements:
|
|
41
|
-
- -
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '3.0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: awesome_nested_set
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '2.0'
|
|
48
38
|
type: :runtime
|
|
49
|
-
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '2.0'
|
|
50
46
|
description: Acts as Commentable with Replies
|
|
51
|
-
email:
|
|
47
|
+
email:
|
|
52
48
|
- info@filvo.com
|
|
53
49
|
executables: []
|
|
54
|
-
|
|
55
50
|
extensions: []
|
|
56
|
-
|
|
57
51
|
extra_rdoc_files: []
|
|
58
|
-
|
|
59
|
-
files:
|
|
52
|
+
files:
|
|
60
53
|
- .gitignore
|
|
61
54
|
- Gemfile
|
|
62
55
|
- LICENSE
|
|
@@ -74,37 +67,32 @@ files:
|
|
|
74
67
|
- lib/generators/acts_as_commentable_with_replies/migration/templates/active_record/migration.rb
|
|
75
68
|
homepage: http://www.filvo.com
|
|
76
69
|
licenses: []
|
|
77
|
-
|
|
78
70
|
post_install_message:
|
|
79
71
|
rdoc_options: []
|
|
80
|
-
|
|
81
|
-
require_paths:
|
|
72
|
+
require_paths:
|
|
82
73
|
- lib
|
|
83
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
75
|
none: false
|
|
85
|
-
requirements:
|
|
86
|
-
- -
|
|
87
|
-
- !ruby/object:Gem::Version
|
|
88
|
-
|
|
89
|
-
segments:
|
|
76
|
+
requirements:
|
|
77
|
+
- - ! '>='
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
segments:
|
|
90
81
|
- 0
|
|
91
|
-
|
|
92
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
|
+
hash: 3742380179039848453
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
84
|
none: false
|
|
94
|
-
requirements:
|
|
95
|
-
- -
|
|
96
|
-
- !ruby/object:Gem::Version
|
|
97
|
-
|
|
98
|
-
segments:
|
|
85
|
+
requirements:
|
|
86
|
+
- - ! '>='
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
segments:
|
|
99
90
|
- 0
|
|
100
|
-
|
|
91
|
+
hash: 3742380179039848453
|
|
101
92
|
requirements: []
|
|
102
|
-
|
|
103
93
|
rubyforge_project:
|
|
104
|
-
rubygems_version: 1.8.
|
|
94
|
+
rubygems_version: 1.8.24
|
|
105
95
|
signing_key:
|
|
106
96
|
specification_version: 3
|
|
107
97
|
summary: A threaded comment system for Rails
|
|
108
98
|
test_files: []
|
|
109
|
-
|
|
110
|
-
has_rdoc:
|