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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d51dd167465cc7e7cfa7292a1d5ab6fe668a0b51
4
- data.tar.gz: 1dca0c84401a50288562fa380416f2b6f6d886a4
3
+ metadata.gz: a700a1c603c1dff97419b559c0f72a3fcfbe0c70
4
+ data.tar.gz: cdab54377ee4ab193bc2db96b63860f8ff96db03
5
5
  SHA512:
6
- metadata.gz: c30f803e905e088b4454d5721d8b86477c93375d48d77e405a6f3958855c20dcb0c4761dea630a7d58b0aeeb0ba9e91b676471e77e282a074bd4f35e2442d9ce
7
- data.tar.gz: c1b027f827e48377e7aeee58e3c62e8ae43ee4d8e08aad6e3ff4874bfc3c4cfe68edc49b1646f45b492d1c66ec10ad3c1c629c8032891b84f0d8c0beaee78969
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 || default_as).to_s.pluralize
25
- self.comment_roles = types.present? ? types : [association_comment_name.to_s.singularize.to_sym]
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
- comment_table_name = self.class.table_name
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
- comment_table_name = self.class.table_name
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, association_name, join_options)
9
- send("define_role_based_inflection_#{Rails.version.first}", role, association_name,join_options)
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, association_name, join_options)
13
- has_many "#{association_name.to_s}".to_sym,
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, association_name, join_options)
18
- has_many "#{association_name.to_s}".to_sym,
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(association_name)
9
- redefine_method("creates_#{association_name.to_s.pluralize}") do |attributes = nil|
10
- send(association_name).create(attributes)
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,3 +1,3 @@
1
1
  module ActsAsCommentableMore
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  RSpec.describe Letter, :type => :model do
4
- it { should have_many(:hide_comments).dependent(:destroy).class_name('CustomComment').conditions(role: 'hide') }
5
- it { should have_many(:show_comments).dependent(:destroy).class_name('CustomComment').conditions(role: 'show') }
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(:comments).dependent(:destroy).class_name('CustomComment').conditions(role: 'comment') }
4
+ it { should have_many(:custom_comments).dependent(:destroy).class_name('CustomComment').conditions(role: 'custom_comment') }
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_commentable_more
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - piya23300