fuck_comments 2.3.4

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.
Files changed (171) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +30 -0
  3. data/.ruby-gemset.example +1 -0
  4. data/.ruby-version.example +1 -0
  5. data/.rvmrc.example +1 -0
  6. data/.travis.yml +5 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +338 -0
  10. data/Rakefile +1 -0
  11. data/app/assets/javascripts/the_comments.js.coffee +108 -0
  12. data/app/assets/javascripts/the_comments_manage.js.coffee +27 -0
  13. data/app/assets/stylesheets/the_comments.css.scss +248 -0
  14. data/app/controllers/_templates_/comments_controller.rb +44 -0
  15. data/app/controllers/concerns/the_comments/controller.rb +197 -0
  16. data/app/controllers/concerns/the_comments/view_token.rb +20 -0
  17. data/app/helpers/render_comments_tree_helper.rb +111 -0
  18. data/app/models/_templates_/comment.rb +38 -0
  19. data/app/models/concerns/the_comments/comment.rb +116 -0
  20. data/app/models/concerns/the_comments/comment_states.rb +80 -0
  21. data/app/models/concerns/the_comments/commentable.rb +69 -0
  22. data/app/models/concerns/the_comments/user.rb +56 -0
  23. data/app/views/the_comments/_tree.html.erb +3 -0
  24. data/app/views/the_comments/haml/_additional_info.html.haml +13 -0
  25. data/app/views/the_comments/haml/_comment.html.haml +1 -0
  26. data/app/views/the_comments/haml/_comment_body.html.haml +25 -0
  27. data/app/views/the_comments/haml/_comment_edit.html.haml +26 -0
  28. data/app/views/the_comments/haml/_form.html.haml +8 -0
  29. data/app/views/the_comments/haml/_guest_form.html.haml +22 -0
  30. data/app/views/the_comments/haml/_logined_form.html.haml +18 -0
  31. data/app/views/the_comments/haml/_manage_controls.html.haml +30 -0
  32. data/app/views/the_comments/haml/_sidebar.html.haml +9 -0
  33. data/app/views/the_comments/haml/_sidebar_admin.html.haml +12 -0
  34. data/app/views/the_comments/haml/_sidebar_backlink.html.haml +3 -0
  35. data/app/views/the_comments/haml/_sidebar_user.html.haml +29 -0
  36. data/app/views/the_comments/haml/_tree.html.haml +16 -0
  37. data/app/views/the_comments/haml/manage.html.haml +26 -0
  38. data/app/views/the_comments/slim/_additional_info.html.slim +13 -0
  39. data/app/views/the_comments/slim/_comment.html.slim +1 -0
  40. data/app/views/the_comments/slim/_comment_body.html.slim +24 -0
  41. data/app/views/the_comments/slim/_comment_edit.html.slim +26 -0
  42. data/app/views/the_comments/slim/_form.html.slim +8 -0
  43. data/app/views/the_comments/slim/_guest_form.html.slim +22 -0
  44. data/app/views/the_comments/slim/_logined_form.html.slim +18 -0
  45. data/app/views/the_comments/slim/_manage_controls.html.slim +30 -0
  46. data/app/views/the_comments/slim/_sidebar.html.slim +9 -0
  47. data/app/views/the_comments/slim/_sidebar_admin.html.slim +12 -0
  48. data/app/views/the_comments/slim/_sidebar_backlink.html.slim +3 -0
  49. data/app/views/the_comments/slim/_sidebar_user.html.slim +29 -0
  50. data/app/views/the_comments/slim/_tree.html.slim +16 -0
  51. data/app/views/the_comments/slim/index.html.slim +18 -0
  52. data/app/views/the_comments/slim/manage.html.slim +26 -0
  53. data/app/views/the_comments/slim/my_comments.html.slim +28 -0
  54. data/config/initializers/the_comments.rb +15 -0
  55. data/config/locales/en.yml +68 -0
  56. data/config/locales/ru.yml +71 -0
  57. data/config/routes.rb +38 -0
  58. data/db/migrate/20130101010101_the_comments_change_user.rb +18 -0
  59. data/db/migrate/20130101010102_the_comments_create_comments.rb +50 -0
  60. data/db/migrate/20130101010103_the_comments_change_commentable.rb +13 -0
  61. data/docs/admin_ui_installation.md +145 -0
  62. data/docs/advanced_installation.md +185 -0
  63. data/docs/comment_api.md +58 -0
  64. data/docs/commentable_api.md +59 -0
  65. data/docs/config_file.md +27 -0
  66. data/docs/content_preprocessors.md +73 -0
  67. data/docs/customazation_of_views.md +30 -0
  68. data/docs/denormalization_and_recent_comments.md +40 -0
  69. data/docs/documentation.md +29 -0
  70. data/docs/generators.md +74 -0
  71. data/docs/pagination.md +123 -0
  72. data/docs/routes.md +77 -0
  73. data/docs/screencast.jpg +0 -0
  74. data/docs/the_comments.jpg +0 -0
  75. data/docs/the_comments_view_1.gif +0 -0
  76. data/docs/the_comments_view_2.gif +0 -0
  77. data/docs/the_comments_view_3.gif +0 -0
  78. data/docs/the_comments_view_4.gif +0 -0
  79. data/docs/the_comments_view_5.gif +0 -0
  80. data/docs/user_api.md +75 -0
  81. data/docs/what_is_comcoms.md +63 -0
  82. data/docs/whats_wrong_with_other_gems.md +28 -0
  83. data/docs/where_is_example_application.md +37 -0
  84. data/gem_version.rb +3 -0
  85. data/lib/generators/the_comments/USAGE +44 -0
  86. data/lib/generators/the_comments/the_comments_generator.rb +56 -0
  87. data/lib/generators/the_comments/views_generator.rb +79 -0
  88. data/lib/the_comments/config.rb +39 -0
  89. data/lib/the_comments/version.rb +1 -0
  90. data/lib/the_comments.rb +27 -0
  91. data/spec/dummy_app/.gitignore +18 -0
  92. data/spec/dummy_app/.rspec +1 -0
  93. data/spec/dummy_app/Gemfile +43 -0
  94. data/spec/dummy_app/README.md +33 -0
  95. data/spec/dummy_app/Rakefile +6 -0
  96. data/spec/dummy_app/app/assets/images/.keep +0 -0
  97. data/spec/dummy_app/app/assets/javascripts/admin_panel.js +5 -0
  98. data/spec/dummy_app/app/assets/javascripts/application.js +16 -0
  99. data/spec/dummy_app/app/assets/stylesheets/admin_panel.css +3 -0
  100. data/spec/dummy_app/app/assets/stylesheets/app.css.scss +4 -0
  101. data/spec/dummy_app/app/assets/stylesheets/application.css +16 -0
  102. data/spec/dummy_app/app/controllers/application_controller.rb +7 -0
  103. data/spec/dummy_app/app/controllers/comments_controller.rb +28 -0
  104. data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
  105. data/spec/dummy_app/app/controllers/posts_controller.rb +13 -0
  106. data/spec/dummy_app/app/controllers/users_controller.rb +7 -0
  107. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  108. data/spec/dummy_app/app/mailers/.keep +0 -0
  109. data/spec/dummy_app/app/models/.keep +0 -0
  110. data/spec/dummy_app/app/models/comment.rb +32 -0
  111. data/spec/dummy_app/app/models/concerns/.keep +0 -0
  112. data/spec/dummy_app/app/models/post.rb +17 -0
  113. data/spec/dummy_app/app/models/user.rb +21 -0
  114. data/spec/dummy_app/app/views/layouts/admin.html.haml +25 -0
  115. data/spec/dummy_app/app/views/layouts/application.html.haml +20 -0
  116. data/spec/dummy_app/app/views/posts/index.html.haml +22 -0
  117. data/spec/dummy_app/app/views/posts/show.html.haml +7 -0
  118. data/spec/dummy_app/bin/bundle +3 -0
  119. data/spec/dummy_app/bin/rails +4 -0
  120. data/spec/dummy_app/bin/rake +4 -0
  121. data/spec/dummy_app/config/application.rb +23 -0
  122. data/spec/dummy_app/config/boot.rb +4 -0
  123. data/spec/dummy_app/config/database.yml +11 -0
  124. data/spec/dummy_app/config/environment.rb +5 -0
  125. data/spec/dummy_app/config/environments/development.rb +29 -0
  126. data/spec/dummy_app/config/environments/production.rb +80 -0
  127. data/spec/dummy_app/config/environments/test.rb +36 -0
  128. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  129. data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
  130. data/spec/dummy_app/config/initializers/inflections.rb +16 -0
  131. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  132. data/spec/dummy_app/config/initializers/secret_token.rb +12 -0
  133. data/spec/dummy_app/config/initializers/session_store.rb +3 -0
  134. data/spec/dummy_app/config/initializers/sorcery.rb +437 -0
  135. data/spec/dummy_app/config/initializers/the_comments.rb +15 -0
  136. data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
  137. data/spec/dummy_app/config/locales/en.yml +23 -0
  138. data/spec/dummy_app/config/routes.rb +19 -0
  139. data/spec/dummy_app/config.ru +4 -0
  140. data/spec/dummy_app/db/migrate/20130712061503_sorcery_core.rb +16 -0
  141. data/spec/dummy_app/db/migrate/20130712065951_create_posts.rb +11 -0
  142. data/spec/dummy_app/db/migrate/20131027185332_change_user.the_comments_engine.rb +19 -0
  143. data/spec/dummy_app/db/migrate/20131027185333_create_comments.the_comments_engine.rb +51 -0
  144. data/spec/dummy_app/db/migrate/20131027185334_change_commentable.the_comments_engine.rb +14 -0
  145. data/spec/dummy_app/db/schema.rb +74 -0
  146. data/spec/dummy_app/db/seeds.rb +42 -0
  147. data/spec/dummy_app/lib/assets/.keep +0 -0
  148. data/spec/dummy_app/lib/tasks/.keep +0 -0
  149. data/spec/dummy_app/lib/tasks/app_bootstrap.rake +15 -0
  150. data/spec/dummy_app/log/.keep +0 -0
  151. data/spec/dummy_app/public/404.html +58 -0
  152. data/spec/dummy_app/public/422.html +58 -0
  153. data/spec/dummy_app/public/500.html +57 -0
  154. data/spec/dummy_app/public/favicon.ico +0 -0
  155. data/spec/dummy_app/public/robots.txt +5 -0
  156. data/spec/dummy_app/spec/factories/post.rb +6 -0
  157. data/spec/dummy_app/spec/factories/user.rb +6 -0
  158. data/spec/dummy_app/spec/models/user_counters_spec.rb +339 -0
  159. data/spec/dummy_app/spec/spec_helper.rb +29 -0
  160. data/spec/dummy_app/test/controllers/.keep +0 -0
  161. data/spec/dummy_app/test/fixtures/.keep +0 -0
  162. data/spec/dummy_app/test/helpers/.keep +0 -0
  163. data/spec/dummy_app/test/integration/.keep +0 -0
  164. data/spec/dummy_app/test/mailers/.keep +0 -0
  165. data/spec/dummy_app/test/models/.keep +0 -0
  166. data/spec/dummy_app/test/test_helper.rb +15 -0
  167. data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
  168. data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
  169. data/the_comments.gemspec +23 -0
  170. data/views_converter.rb +16 -0
  171. metadata +332 -0
@@ -0,0 +1,29 @@
1
+ #### INSTALLATION
2
+ * :white_check_mark:   [ADVANCED INSTALLATION](advanced_installation.md)
3
+ * :white_check_mark:   [ADMIN UI INSTALLATION](admin_ui_installation.md)
4
+ * :white_check_mark:   [Routing](routes.md)
5
+ * :white_check_mark:   [Generators](generators.md)
6
+
7
+ #### API
8
+ * :white_check_mark:   [User API](user_api.md)
9
+ * :white_check_mark:   [Comment API](comment_api.md)
10
+ * :white_check_mark:   [Commentable API](commentable_api.md)
11
+
12
+ #### Understanding
13
+ * :white_check_mark:   [What is ComComs?](what_is_comcoms.md)
14
+ * :white_check_mark:   [Denormalization and Recent comments](denormalization_and_recent_comments.md)
15
+ * :white_check_mark:   [What's wrong with other gems?](whats_wrong_with_other_gems.md)
16
+ * :white_check_mark:   [Why TheComments is better than others gems?](whats_wrong_with_other_gems.md#why-thecomments-is-better-than-others-gems)
17
+
18
+ #### Customazation
19
+ * :white_check_mark:   [Views](customazation_of_views.md)
20
+ * :white_check_mark:   [Text Preprocessors - Sanitize, Markdown etc.](content_preprocessors.md)
21
+
22
+ #### Configuration
23
+ * :white_check_mark:   [the_comments.rb config file](config_file.md)
24
+
25
+ #### Q&A
26
+ * :white_check_mark:   [I want not to use kaminari for Admin UI](pagination.md)
27
+ * :white_check_mark:   [Where is example application?](where_is_example_application.md)
28
+ * :white_check_mark:   [How can I run tests?](where_is_example_application.md#run-tests)
29
+
@@ -0,0 +1,74 @@
1
+ ←   [documentation](documentation.md)
2
+
3
+ ## Generators
4
+
5
+ ```ruby
6
+ rails g the_comments NAME
7
+ rails g the_comments:views NAME
8
+ ```
9
+
10
+ #### Migrations
11
+
12
+ ```ruby
13
+ rake the_comments_engine:install:migrations
14
+ ```
15
+
16
+ ### Full list
17
+
18
+ ```ruby
19
+ rails g the_comments --help
20
+ ```
21
+
22
+ #### Main
23
+
24
+ ```ruby
25
+ rails g the_comments install
26
+ ```
27
+
28
+ This will create:
29
+
30
+ * config/initializers/the_comments.rb
31
+ * app/controllers/comments_controller.rb
32
+ * app/models/comment.rb
33
+
34
+ #### Controllers
35
+
36
+ ```ruby
37
+ rails g the_comments controllers
38
+ ```
39
+
40
+ This will create:
41
+
42
+ * app/controllers/comments_controller.rb
43
+
44
+ #### Models
45
+
46
+ ```ruby
47
+ rails g the_comments models
48
+ ```
49
+
50
+ This will create:
51
+
52
+ * app/models/comment.rb
53
+
54
+ #### Config
55
+
56
+ ```ruby
57
+ rails g the_comments config
58
+ ```
59
+
60
+ #### Locals
61
+
62
+ ```ruby
63
+ rails g the_comments locales
64
+ ```
65
+
66
+ #### Views
67
+
68
+ ```ruby
69
+ rails g the_comments:views js
70
+ rails g the_comments:views css
71
+ rails g the_comments:views assets
72
+ rails g the_comments:views helper
73
+ rails g the_comments:views views
74
+ ```
@@ -0,0 +1,123 @@
1
+ ←   [documentation](documentation.md)
2
+
3
+ ## I want not to use kaminari for Admin UI
4
+
5
+ By default we use Kaminari pagination for Admin UI.
6
+
7
+ But you can change this. For example, your **comments_controller.rb** looks like this:
8
+
9
+ **app/controllers/comments_controller.rb**
10
+
11
+ ```ruby
12
+ class CommentsController < ApplicationController
13
+ # layout 'admin'
14
+
15
+ # Define your restrict methods and use them like this:
16
+ #
17
+ # before_action :user_required, except: %w[index create]
18
+ # before_action :owner_required, except: %w[index create]
19
+ # before_action :admin_required, only: %w[total_draft total_published total_deleted total_spam]
20
+
21
+ include TheComments::Controller
22
+
23
+ # >>> include TheComments::Controller <<<
24
+ # (!) Almost all methods based on *current_user* method
25
+ #
26
+ # 1. Controller's public methods list:
27
+ # You can redifine it for your purposes
28
+ # public
29
+ # %w[ manage index create edit update ]
30
+ # %w[ my_comments my_draft my_published ]
31
+ # %w[ draft published deleted spam ]
32
+ # %w[ to_draft to_published to_deleted to_spam ]
33
+ # %w[ total_draft total_published total_deleted total_spam ]
34
+ #
35
+ #
36
+ # 2. Controller's private methods list:
37
+ # You can redifine it for your purposes
38
+ #
39
+ # private
40
+ # %w[ comment_template comment_partial ]
41
+ # %w[ denormalized_fields request_data_for_comment define_commentable ]
42
+ # %w[ comment_params patch_comment_params ]
43
+ # %w[ ajax_requests_required cookies_required ]
44
+ # %w[ empty_trap_required tolerance_time_required ]
45
+
46
+ # KAMINARI pagination:
47
+ # following methods based on gem "kaminari"
48
+ # You should redefine them if you use something else
49
+ #
50
+ # public
51
+ # %w[ manage index edit ]
52
+ # %w[ draft published deleted spam ]
53
+ # %w[ my_comments my_draft my_published ]
54
+ # %w[ total_draft total_published total_deleted total_spam ]
55
+ end
56
+ ```
57
+
58
+ There is we can see comments about kaminari. So, we can try to change it.
59
+
60
+ There is example how it can be in your real app:
61
+
62
+ ```ruby
63
+ class CommentsController < ApplicationController
64
+ layout 'admin'
65
+
66
+ before_action :user_required, except: %w[index create]
67
+ before_action :owner_required, except: %w[index create]
68
+ before_action :admin_required, only: %w[total_draft total_published total_deleted total_spam]
69
+
70
+ include TheComments::Controller
71
+
72
+ public
73
+
74
+ def index
75
+ @comments = ::Comment.with_state(:published).recent.super_paginator(params)
76
+ render comment_template(:index)
77
+ end
78
+
79
+ def manage
80
+ @comments = current_user.comcoms.active.recent.super_paginator(params)
81
+ render comment_template(:manage)
82
+ end
83
+
84
+ def my_comments
85
+ @comments = current_user.my_comments.active.recent.super_paginator(params)
86
+ render comment_template(:my_comments)
87
+ end
88
+
89
+ def edit
90
+ @comments = current_user.comcoms.where(id: params[:id]).super_paginator(params)
91
+ render comment_template(:manage)
92
+ end
93
+
94
+ %w[draft published deleted].each do |state|
95
+ define_method "#{state}" do
96
+ @comments = current_user.comcoms.with_state(state).recent.super_paginator(params)
97
+ render comment_template(:manage)
98
+ end
99
+
100
+ define_method "total_#{state}" do
101
+ @comments = ::Comment.with_state(state).recent.super_paginator(params)
102
+ render comment_template(:manage)
103
+ end
104
+
105
+ unless state == 'deleted'
106
+ define_method "my_#{state}" do
107
+ @comments = current_user.my_comments.with_state(state).recent.super_paginator(params)
108
+ render comment_template(:my_comments)
109
+ end
110
+ end
111
+ end
112
+
113
+ def spam
114
+ @comments = current_user.comcoms.where(spam: true).recent.super_paginator(params)
115
+ render comment_template(:manage)
116
+ end
117
+
118
+ def total_spam
119
+ @comments = ::Comment.where(spam: true).recent.super_paginator(params)
120
+ render comment_template(:manage)
121
+ end
122
+ end
123
+ ```
data/docs/routes.md ADDED
@@ -0,0 +1,77 @@
1
+ &larr; &nbsp; [documentation](documentation.md)
2
+
3
+ ## TheComments Routes
4
+
5
+ **config/routes.rb**
6
+
7
+ ```ruby
8
+ MyApp::Application.routes.draw do
9
+ root 'posts#index'
10
+ resources :posts
11
+
12
+ # ...
13
+
14
+ # TheComments routes
15
+ concern :user_comments, TheComments::UserRoutes.new
16
+ concern :admin_comments, TheComments::AdminRoutes.new
17
+ resources :comments, concerns: [:user_comments, :admin_comments]
18
+ end
19
+ ```
20
+
21
+ And after that you can see routes:
22
+
23
+ ```ruby
24
+ rake routes | grep comments
25
+ ```
26
+
27
+ ```ruby
28
+ comments / TheComments::Engine
29
+ to_spam_comment POST /comments/:id/to_spam(.:format) comments#to_spam
30
+ to_draft_comment POST /comments/:id/to_draft(.:format) comments#to_draft
31
+ to_published_comment POST /comments/:id/to_published(.:format) comments#to_published
32
+ to_deleted_comment DELETE /comments/:id/to_deleted(.:format) comments#to_deleted
33
+ manage_comments GET /comments/manage(.:format) comments#manage
34
+ my_draft_comments GET /comments/my_draft(.:format) comments#my_draft
35
+ my_published_comments GET /comments/my_published(.:format) comments#my_published
36
+ my_comments_comments GET /comments/my_comments(.:format) comments#my_comments
37
+ total_draft_comments GET /comments/total_draft(.:format) comments#total_draft
38
+ total_published_comments GET /comments/total_published(.:format) comments#total_published
39
+ total_deleted_comments GET /comments/total_deleted(.:format) comments#total_deleted
40
+ total_spam_comments GET /comments/total_spam(.:format) comments#total_spam
41
+ draft_comments GET /comments/draft(.:format) comments#draft
42
+ published_comments GET /comments/published(.:format) comments#published
43
+ deleted_comments GET /comments/deleted(.:format) comments#deleted
44
+ spam_comments GET /comments/spam(.:format) comments#spam
45
+ comments GET /comments(.:format) comments#index
46
+ POST /comments(.:format) comments#create
47
+ new_comment GET /comments/new(.:format) comments#new
48
+ edit_comment GET /comments/:id/edit(.:format) comments#edit
49
+ comment GET /comments/:id(.:format) comments#show
50
+ PATCH /comments/:id(.:format) comments#update
51
+ PUT /comments/:id(.:format) comments#update
52
+ DELETE /comments/:id(.:format) comments#destroy
53
+ ```
54
+
55
+ And now you can use url helpers with 2 ways:
56
+
57
+ ### Way 1. Url Helpers
58
+
59
+ ```ruby
60
+ = link_to 'link', comments_path
61
+ = link_to 'link', manage_comments_path
62
+ = link_to 'link', new_comment_path
63
+
64
+ = link_to 'link', comment_path(@comment)
65
+ = link_to 'link', to_spam_comment_path(@comment)
66
+ ```
67
+
68
+ ### Way 2. Array notation
69
+
70
+ ```ruby
71
+ = link_to 'link', [:index, :comments]
72
+ = link_to 'link', [:manage, :comments]
73
+ = link_to 'link', [:draft, :comments]
74
+
75
+ = link_to 'link', [@comment]
76
+ = link_to 'link', [:to_spam, @comment]
77
+ ```
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/docs/user_api.md ADDED
@@ -0,0 +1,75 @@
1
+ &larr; &nbsp; [documentation](documentation.md)
2
+
3
+ ### User API
4
+
5
+ **When User is not commentable model**
6
+
7
+ ```ruby
8
+ class User < ActiveRecord::Base
9
+ include TheCommentsUser
10
+
11
+ has_many :posts # commentable model
12
+ has_many :products # commentable model
13
+ end
14
+ ```
15
+
16
+ :warning: &nbsp; Please, read this: [What is ComComs?](what_is_comcoms.md)
17
+
18
+
19
+ We can use following methods
20
+
21
+ ```ruby
22
+ @user = User.first
23
+
24
+ @user.comcoms #=> all comments for posts and products, where user is owner
25
+
26
+ # cache counters
27
+ @user.draft_comcoms_count # => 1
28
+ @user.published_comcoms_count # => 5
29
+ @user.deleted_comcoms_count # => 3
30
+ @user.spam_comcoms_count # => 2
31
+
32
+ # equal values, but with request to database
33
+ @user.comcoms.with_state([:draft]).count # => 1
34
+ @user.comcoms.with_state([:published]).count # => 5
35
+ @user.comcoms.with_state([:deleted]).count # => 3
36
+ @user.comcoms.where(spam: true).count # => 2
37
+
38
+ # draft and published comments
39
+ # written by this user
40
+ @user.my_comments # => ActiveRecord::Relation
41
+
42
+ # cache counters for comments
43
+ # written by this user
44
+ # there is no cache counter for deleted state!
45
+ @user.my_draft_comments_count # => 3
46
+ @user.my_published_comments_count # => 7
47
+
48
+ # equal values, but with request to database
49
+ @user.my_draft_comments.count # => 3
50
+ @user.my_published_comments.count # => 7
51
+ @user.my_deleted_comments.count # => 1
52
+
53
+ # helper methods to get comments
54
+ # written by this user
55
+ @user.my_draft_comments # => ActiveRecord::Relation
56
+ @user.my_published_comments # => ActiveRecord::Relation
57
+ @user.my_deleted_comments # => ActiveRecord::Relation
58
+
59
+ # recalculate cache counters
60
+ @user.recalculate_my_comments_counter!
61
+ ```
62
+
63
+ **When User is commentable model**
64
+
65
+ ```ruby
66
+ class User < ActiveRecord::Base
67
+ include TheCommentsUser
68
+ include TheCommentsCommentable
69
+
70
+ has_many :posts # commentable model
71
+ has_many :products # commentable model
72
+ end
73
+ ```
74
+
75
+ you should to use following instruction [Commentable API](commentable_api.md)
@@ -0,0 +1,63 @@
1
+ &larr; &nbsp; [documentation](documentation.md)
2
+
3
+ ### What is ComComs?
4
+
5
+ :warning: &nbsp; **comcoms** - is main method to get all comments related with user's commentable models.
6
+
7
+ :warning: &nbsp; **comments** - is main method to get comments related with any commentable model.
8
+
9
+ **ComComs** - **com**ments of **com**mentable models
10
+
11
+ ComComs are all incoming comments for all models, where this user is owner.
12
+
13
+ For example, some user **has_many :posts**, and **has_many :products** - all comments for all user's posts and all user's products called as **comcoms**.
14
+
15
+ #### Why we need ComComs?
16
+
17
+ User model can be commentable too. For example to build user's "public wall" (like tweets list for current user).
18
+
19
+ And we should to separate **comments** attached to user model (tweets) and comments attached to any another user's model.
20
+
21
+ That is why User model in-fact has following relationship declarations:
22
+
23
+ ```ruby
24
+ class User < ActiveRecord::Base
25
+ has_many :comcoms, class_name: :Comment, foreign_key: :holder_id
26
+
27
+ # and if User model is commentable model
28
+ # has_many :comments, as: :commentable
29
+
30
+ has_many :posts
31
+ has_many :products
32
+ end
33
+ ```
34
+
35
+ in real application it should be described like this:
36
+
37
+ ```ruby
38
+ class User < ActiveRecord::Base
39
+ include TheCommentsUser
40
+ include TheCommentsCommentable
41
+
42
+ has_many :posts
43
+ has_many :products
44
+ end
45
+ ```
46
+
47
+ But in most popular situation User model should not be commentable, and you should use only **comcoms** method to get all comments related with this user:
48
+
49
+ ```ruby
50
+ class User < ActiveRecord::Base
51
+ include TheCommentsUser
52
+
53
+ has_many :posts
54
+ has_many :products
55
+ end
56
+ ```
57
+
58
+ and later in your application
59
+
60
+ ```ruby
61
+ @user = User.find params[:id]
62
+ @user.comcoms.count # => 42
63
+ ```