acts_as_commentable_more 1.2.1 → 1.2.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 +4 -4
- data/lib/acts_as_commentable_more/commentable_methods.rb +3 -5
- data/lib/acts_as_commentable_more/helpers/comment/callbacks_helper.rb +3 -5
- data/lib/acts_as_commentable_more/helpers/post/associations_helper.rb +6 -6
- data/lib/acts_as_commentable_more/helpers/post/methods_helper.rb +3 -3
- data/lib/acts_as_commentable_more/version.rb +1 -1
- data/test/dummy/spec/models/letter_spec.rb +2 -2
- data/test/dummy/spec/models/topic_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a700a1c603c1dff97419b559c0f72a3fcfbe0c70
|
4
|
+
data.tar.gz: cdab54377ee4ab193bc2db96b63860f8ff96db03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 493e49085a113635c59a4fa3e5d48816840eb792d88c2edb9605209036a259ff811d5fe1fb89ec4fa6d49e24c05b480fb5c68f3b5841578f763fd94febaa0fb6
|
7
|
+
data.tar.gz: 77c8f29135dc326f76564dc61ee3f6f729d33f2ef3b5317e070955cf663c61001c7a0cae24d4a604a7ba5c2399d89511d3fbc3b2bab913c51e0111e2d8532789
|
@@ -15,14 +15,12 @@ module ActsAsCommentableMore
|
|
15
15
|
mattr_accessor :comment_roles
|
16
16
|
|
17
17
|
default_options = {as: :commentable, dependent: :destroy, class_name: 'Comment'}
|
18
|
-
default_as = :comments
|
19
|
-
default_roles = [default_as.to_s.singularize.to_sym]
|
20
18
|
|
21
19
|
types = types.flatten.compact.map(&:to_sym)
|
22
20
|
|
23
21
|
association_options = default_options.merge(options.compact)
|
24
|
-
association_comment_name = (as ||
|
25
|
-
self.comment_roles = types.present? ? types : [association_comment_name.
|
22
|
+
association_comment_name = (as || association_options[:class_name].demodulize.underscore.to_sym).to_s.pluralize
|
23
|
+
self.comment_roles = types.present? ? types : [association_comment_name.singularize.to_sym]
|
26
24
|
self.comment_model = association_options[:class_name].classify.constantize
|
27
25
|
enable_counter_cache = counter_cache
|
28
26
|
|
@@ -54,7 +52,7 @@ module ActsAsCommentableMore
|
|
54
52
|
end
|
55
53
|
|
56
54
|
# counter cache for comment model
|
57
|
-
define_counter_cache_role_comment_callback(association_options[:as]) if enable_counter_cache
|
55
|
+
define_counter_cache_role_comment_callback(association_comment_name, association_options[:as]) if enable_counter_cache
|
58
56
|
|
59
57
|
end
|
60
58
|
|
@@ -5,7 +5,7 @@ module ActsAsCommentableMore
|
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
|
-
def define_counter_cache_role_comment_callback commentable_name
|
8
|
+
def define_counter_cache_role_comment_callback association_comment_name, commentable_name
|
9
9
|
never_has_counter_cache = !comment_model._create_callbacks.select {|cb| cb.kind == :after }.collect(&:filter).include?(:acts_as_commentable_more_increment!)
|
10
10
|
|
11
11
|
if never_has_counter_cache
|
@@ -15,8 +15,7 @@ module ActsAsCommentableMore
|
|
15
15
|
end
|
16
16
|
|
17
17
|
comment_model.redefine_method("acts_as_commentable_more_increment!") do
|
18
|
-
|
19
|
-
all_counter_field = "#{comment_table_name}_count"
|
18
|
+
all_counter_field = "#{association_comment_name}_count"
|
20
19
|
role_counter_field = "#{self.role.to_s}_#{all_counter_field}"
|
21
20
|
post_model = self.send("#{commentable_name}_type").classify.constantize
|
22
21
|
attributes_post = post_model.column_names
|
@@ -31,8 +30,7 @@ module ActsAsCommentableMore
|
|
31
30
|
comment_model.send(:private, "acts_as_commentable_more_increment!".to_sym)
|
32
31
|
|
33
32
|
comment_model.redefine_method("acts_as_commentable_more_decrement!") do
|
34
|
-
|
35
|
-
all_counter_field = "#{comment_table_name}_count"
|
33
|
+
all_counter_field = "#{association_comment_name}_count"
|
36
34
|
role_counter_field = "#{self.role.to_s}_#{all_counter_field}"
|
37
35
|
post_model = self.send("#{commentable_name}_type").classify.constantize
|
38
36
|
attributes_post = post_model.column_names
|
@@ -5,17 +5,17 @@ module ActsAsCommentableMore
|
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
|
-
def define_role_based_inflection(role,
|
9
|
-
send("define_role_based_inflection_#{Rails.version.first}", role,
|
8
|
+
def define_role_based_inflection(role, association_comment_name, join_options)
|
9
|
+
send("define_role_based_inflection_#{Rails.version.first}", role, association_comment_name,join_options)
|
10
10
|
end
|
11
11
|
|
12
|
-
def define_role_based_inflection_3(role,
|
13
|
-
has_many "#{
|
12
|
+
def define_role_based_inflection_3(role, association_comment_name, join_options)
|
13
|
+
has_many "#{association_comment_name.to_s}".to_sym,
|
14
14
|
has_many_options(role, join_options).merge(:conditions => { role: role.to_s })
|
15
15
|
end
|
16
16
|
|
17
|
-
def define_role_based_inflection_4(role,
|
18
|
-
has_many "#{
|
17
|
+
def define_role_based_inflection_4(role, association_comment_name, join_options)
|
18
|
+
has_many "#{association_comment_name.to_s}".to_sym,
|
19
19
|
-> { includes(join_options[:as].to_sym, :user).where(role: role.to_s) },
|
20
20
|
has_many_options(role, join_options)
|
21
21
|
end
|
@@ -5,9 +5,9 @@ module ActsAsCommentableMore
|
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
|
-
def define_create_role_comments(
|
9
|
-
redefine_method("creates_#{
|
10
|
-
send(
|
8
|
+
def define_create_role_comments(association_comment_name)
|
9
|
+
redefine_method("creates_#{association_comment_name.to_s.pluralize}") do |attributes = nil|
|
10
|
+
send(association_comment_name).create(attributes)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
RSpec.describe Letter, :type => :model do
|
4
|
-
it { should have_many(:
|
5
|
-
it { should have_many(:
|
4
|
+
it { should have_many(:hide_custom_comments).dependent(:destroy).class_name('CustomComment').conditions(role: 'hide') }
|
5
|
+
it { should have_many(:show_custom_comments).dependent(:destroy).class_name('CustomComment').conditions(role: 'show') }
|
6
6
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
RSpec.describe Topic, :type => :model do
|
4
|
-
it { should have_many(:
|
4
|
+
it { should have_many(:custom_comments).dependent(:destroy).class_name('CustomComment').conditions(role: 'custom_comment') }
|
5
5
|
end
|