acts_as_commentable_with_replies 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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(args = {})
24
+ def comment args = {}
25
25
  return nil if args[:commenter].nil? || args[:message].nil?
26
26
 
27
- comment = Comment.new(
27
+ __comment__ = Comment.new(
28
28
  :commentable => self,
29
29
  :commenter => args[:commenter],
30
30
  :message => args[:message]
31
31
  )
32
32
 
33
- if comment.save
34
- update_cached_comments
35
- comment.move_to_child_of(args[:parent]) if !args[:parent].nil?
36
- comment
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
- # caching
45
- def update_cached_comments
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
- # counting
55
- def count_comments_total(skip_cache = false)
56
- if !skip_cache && self.respond_to?(:cached_comments_total)
57
- return self.send(:cached_comments_total)
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(extra_conditions = {})
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(args = {})
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
- # results
21
+
23
22
  def commented_on?(commentable)
24
- comments = find_comments(:commentable_id => commentable.id, :commentable_type => commentable.class.name)
25
- comments.size > 0
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
@@ -1,3 +1,3 @@
1
1
  module ActsAsCommentableWithReplies
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  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
- hash: 25
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
- date: 2012-07-28 00:00:00 Z
19
- dependencies:
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
- prerelease: false
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
- hash: 7
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
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
39
25
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 2
46
- - 0
47
- version: "2.0"
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
- version_requirements: *id002
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
- hash: 3
89
- segments:
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ segments:
90
81
  - 0
91
- version: "0"
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
- hash: 3
98
- segments:
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ segments:
99
90
  - 0
100
- version: "0"
91
+ hash: 3742380179039848453
101
92
  requirements: []
102
-
103
93
  rubyforge_project:
104
- rubygems_version: 1.8.15
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: