acts_as_commentable2 7.2.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1025e16458f3cbd4cf626aa47ac5bc333d91d171af2bc7927cede9a77a4b6635
4
+ data.tar.gz: 35b6beb57cdbce25fe90c5224c5c107cd81290e34ca21269b51b6ce071a44611
5
+ SHA512:
6
+ metadata.gz: 673c8bd078e3446afe30687c0215f6d4bde83966b0a8c39538c1677977cc8de26c941b5c7bb6e54d88d4639a0ca6e3ecfd5df8d97134815c378a709ec5e6c5fc
7
+ data.tar.gz: 2a432e27973ec295786736f4049ad4352b7f07ff4e943652e584b04d46e4212830d4ff2b5eb6a5237e3523f2bcfcf6979b2bf7d233ef6dcb31b0aba5eec202fa
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 Cosmin Radoi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,90 @@
1
+ = Acts As Commentable
2
+
3
+ A maintained fork of the original acts_as_commentable gem.
4
+
5
+ Provides a single Comment model that can be attached to any model(s) within your app. It creates
6
+ a Comment model and handles the plumbing between that model and any models that you declare to be
7
+ commentable models.
8
+
9
+
10
+ == Installation :
11
+
12
+ Add the following line to your Gemfile
13
+
14
+ gem 'acts_as_commentable', git: 'git@github.com:fatfreecrm/acts_as_commentable.git'
15
+
16
+ Choose the appropriate tag for your rails version.
17
+
18
+ == Generator
19
+
20
+
21
+ === Rails 3+
22
+
23
+ rails g comment
24
+
25
+ Then migrate your database to add the comments model:
26
+
27
+ rake db:migrate
28
+
29
+ == Usage
30
+
31
+ Make the desired ActiveRecord model act as commentable:
32
+
33
+ class Post < ActiveRecord::Base
34
+ acts_as_commentable
35
+ end
36
+
37
+ Add a comment to a model instance by adding the following to the controller:
38
+
39
+ commentable = Post.create
40
+ comment = commentable.comments.create
41
+ comment.title = "First comment."
42
+ comment.comment = "This is the first comment."
43
+ comment.save
44
+
45
+
46
+ Fetch comments for the commentable model by adding the following to the view:
47
+
48
+ commentable = Post.find(1)
49
+ comments = commentable.comments.recent.limit(10).all
50
+
51
+ You can also add different types of comments to a model:
52
+
53
+ class Todo < ActiveRecord::Base
54
+ acts_as_commentable :public, :private
55
+ end
56
+
57
+ *Note:* This feature is only available from version 4.0 and above
58
+
59
+ To fetch the different types of comments for this model:
60
+
61
+ public_comments = Todo.find(1).public_comments
62
+ private_comments = Todo.find(1).private_comments
63
+
64
+
65
+ By default, `acts_as_commentable` will assume you are using a `Comment` model.
66
+ To change this, or change any other join options, pass in an options hash:
67
+
68
+ class Todo < ActiveRecord::Base
69
+ acts_as_commentable class_name: 'MyComment'
70
+ end
71
+
72
+ This also works in conjunction with comment types:
73
+
74
+ class Todo < ActiveRecord::Base
75
+ acts_as_commentable :public, :private, { class_name: 'MyComment' }
76
+ end
77
+
78
+
79
+ == Credits
80
+
81
+ Xelipe - This plugin is heavily influenced by Acts As Taggable.
82
+
83
+ == Contributors
84
+
85
+ Jack Dempsey, Chris Eppstein, Jim Ray, Matthew Van Horn, Ole Riesenberg, ZhangJinzhu, maddox, monocle, mrzor, Michael Bensoussan
86
+
87
+ == More
88
+
89
+ http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
90
+ http://www.juixe.com/projects/acts_as_commentable
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
data/install.rb ADDED
@@ -0,0 +1,2 @@
1
+ puts 'To create the comment model please run:'
2
+ puts 'script/generate comment'
@@ -0,0 +1,2 @@
1
+ require 'commentable_methods'
2
+ require 'comment_methods'
@@ -0,0 +1,44 @@
1
+ module ActsAsCommentable
2
+ # including this module into your Comment model will give you finders and named scopes
3
+ # useful for working with Comments.
4
+ # The named scopes are:
5
+ # in_order: Returns comments in the order they were created (created_at ASC).
6
+ # recent: Returns comments by how recently they were created (created_at DESC).
7
+ # limit(N): Return no more than N comments.
8
+ module Comment
9
+ def self.included(comment_model)
10
+ # If you have already extended the comment model, stop
11
+ return if comment_model.method_defined?(:in_order)
12
+
13
+ comment_model.extend Finders
14
+ comment_model.scope :in_order, -> { order('created_at ASC') }
15
+ comment_model.scope :recent, -> { reorder('created_at DESC') }
16
+ end
17
+
18
+ def is_comment_type?(type)
19
+ type.to_s == role.singularize.to_s
20
+ end
21
+
22
+ module Finders
23
+ # Helper class method to lookup all comments assigned
24
+ # to all commentable types for a given user.
25
+ def find_comments_by_user(user, role = 'comments')
26
+ where(['user_id = ? and role = ?', user.id, role]).order('created_at DESC')
27
+ end
28
+
29
+ # Helper class method to look up all comments for
30
+ # commentable class name and commentable id.
31
+ def find_comments_for_commentable(commentable_str, commentable_id, role = 'comments')
32
+ where(['commentable_type = ? and commentable_id = ? and role = ?', commentable_str, commentable_id,
33
+ role]).order('created_at DESC')
34
+ end
35
+
36
+ # Helper class method to look up a commentable object
37
+ # given the commentable class name and id
38
+ def find_commentable(commentable_str, commentable_id)
39
+ model = commentable_str.constantize
40
+ model.respond_to?(:find_comments_for) ? model.find(commentable_id) : nil
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,88 @@
1
+ require 'active_record'
2
+
3
+ # ActsAsCommentable
4
+ module Juixe
5
+ module Acts # :nodoc:
6
+ module Commentable # :nodoc:
7
+ def self.included(base)
8
+ base.extend ClassMethods
9
+ end
10
+
11
+ module HelperMethods
12
+ private
13
+
14
+ def define_role_based_inflection(role)
15
+ return if method_defined?(:"#{role}_comments")
16
+
17
+ has_many :"#{role}_comments",
18
+ -> { where(role: role.to_s) },
19
+ **has_many_options(role)
20
+ end
21
+
22
+ def has_many_options(role)
23
+ { class_name: 'Comment',
24
+ as: :commentable,
25
+ dependent: :destroy,
26
+ before_add: proc { |_x, c| c.role = role.to_s } }
27
+ end
28
+ end
29
+
30
+ module ClassMethods
31
+ include HelperMethods
32
+
33
+ def acts_as_commentable(*args)
34
+ # Detect if we already loaded
35
+ return if method_defined?(:comment_types)
36
+
37
+ options = args.to_a.flatten.compact.partition { |opt| opt.is_a? Hash }
38
+ comment_roles = options.last.blank? ? nil : options.last.flatten.compact.map(&:to_sym)
39
+
40
+ join_options = options.first.blank? ? [{}] : options.first
41
+ throw 'Only one set of options can be supplied for the join' if join_options.length > 1
42
+ join_options = join_options.first
43
+
44
+ class_attribute :comment_types
45
+ self.comment_types = (comment_roles.blank? ? [:comments] : comment_roles)
46
+
47
+ if comment_roles.blank?
48
+ has_many :comments, as: :commentable, dependent: :destroy, **join_options
49
+ else
50
+ comment_roles.each do |role|
51
+ define_role_based_inflection(role)
52
+ end
53
+ has_many :all_comments, as: :commentable, dependent: :destroy, class_name: 'Comment', **join_options
54
+ end
55
+
56
+ comment_types.each do |role|
57
+ method_name = (role == :comments ? 'comments' : "#{role}_comments").to_s
58
+
59
+ class_eval %{
60
+ def self.find_#{method_name}_for(obj)
61
+ commentable = self.base_class.name
62
+ Comment.find_comments_for_commentable(commentable, obj.id, "#{role}")
63
+ end
64
+
65
+ def self.find_#{method_name}_by_user(user)
66
+ commentable = self.base_class.name
67
+ Comment.where([
68
+ "user_id = ? and commentable_type = ? and role = ?", user.id, commentable, "#{role}"
69
+ ]).order("created_at DESC")
70
+ end
71
+
72
+ def #{method_name}_ordered_by_submitted
73
+ Comment.find_comments_for_commentable(self.class.name, id, "#{role}").order("created_at")
74
+ end
75
+
76
+ def add_#{method_name.singularize}(comment)
77
+ comment.role = "#{role}"
78
+ #{method_name} << comment
79
+ end
80
+ }, __FILE__, __LINE__ - 21
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ ActiveRecord::Base.include Juixe::Acts::Commentable
@@ -0,0 +1,6 @@
1
+ Description:
2
+ Copies comment.rb to app/models/.
3
+ Copies create_comment.rb to db/migrate
4
+
5
+ Examples:
6
+ `rails generate comment`
@@ -0,0 +1,18 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class CommentGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ def self.source_root
7
+ @source_root ||= File.expand_path('templates', __dir__)
8
+ end
9
+
10
+ def self.next_migration_number(_path)
11
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
12
+ end
13
+
14
+ def create_model_file
15
+ template 'comment.rb', 'app/models/comment.rb'
16
+ migration_template 'create_comments.rb', 'db/migrate/create_comments.rb'
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ class Comment < ActiveRecord::Base
2
+ unless method_defined?(:commentable)
3
+ include ActsAsCommentable::Comment
4
+
5
+ belongs_to :commentable, polymorphic: true
6
+
7
+ default_scope -> { order('created_at ASC') }
8
+
9
+ # NOTE: install the acts_as_votable plugin if you
10
+ # want user to vote on the quality of comments.
11
+ # acts_as_votable
12
+
13
+ # NOTE: Comments belong to a user
14
+ belongs_to :user
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ class CreateComments < ActiveRecord::Migration['6.0']
2
+ def self.up
3
+ create_table :comments do |t|
4
+ t.string :title, limit: 50, default: ''
5
+ t.text :comment
6
+ t.references :commentable, polymorphic: true
7
+ t.references :user
8
+ t.string :role, default: 'comments'
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :comments, :commentable_type
13
+ add_index :comments, :commentable_id
14
+ add_index :comments, :user_id unless index_exists?(:comments, :user_id)
15
+ end
16
+
17
+ def self.down
18
+ drop_table :comments
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_commentable2
3
+ version: !ruby/object:Gem::Version
4
+ version: 7.2.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein
8
+ autorequire: acts_as_commentable
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 7.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 7.2.0
27
+ description: Plugin/gem that provides comment functionality
28
+ email: daniel.oconnor@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ - MIT-LICENSE
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.rdoc
37
+ - init.rb
38
+ - install.rb
39
+ - lib/acts_as_commentable.rb
40
+ - lib/comment_methods.rb
41
+ - lib/commentable_methods.rb
42
+ - lib/generators/comment/USAGE
43
+ - lib/generators/comment/comment_generator.rb
44
+ - lib/generators/comment/templates/comment.rb
45
+ - lib/generators/comment/templates/create_comments.rb
46
+ homepage: http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ rubygems_mfa_required: 'true'
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 3.1.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.6.2
66
+ specification_version: 4
67
+ summary: Plugin/gem that provides comment functionality
68
+ test_files: []