acts_as_commentable2 7.1.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: cba4e2158759d8b64431532ea6549f553098890ee51d31d10c6395699c34d3b4
4
+ data.tar.gz: b0422fd7970df076c0fdf8435c3f0eb331945d17b915261ba5db31a751df894f
5
+ SHA512:
6
+ metadata.gz: b6a93a595c46937d7f3fd1dc3fd8e50e857bdcd34382eb0ae3c034dd64c589b0bcdbd8eae3e2545648c18fef4f77947245f5925aa32374f6578ed91a1c7a108f
7
+ data.tar.gz: e7dd1cc9f91a6ed2b4031f4be45a7b5d50941443f98df5e73dda31def652051f426592e1bc2a4b7336c492e4d00eeb0100e2f28cd7eb768444719dc5eec48fe6
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,89 @@
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
+
17
+ == Generator
18
+
19
+
20
+ === Rails 3+
21
+
22
+ rails g comment
23
+
24
+ Then migrate your database to add the comments model:
25
+
26
+ rake db:migrate
27
+
28
+ == Usage
29
+
30
+ Make the desired ActiveRecord model act as commentable:
31
+
32
+ class Post < ActiveRecord::Base
33
+ acts_as_commentable
34
+ end
35
+
36
+ Add a comment to a model instance by adding the following to the controller:
37
+
38
+ commentable = Post.create
39
+ comment = commentable.comments.create
40
+ comment.title = "First comment."
41
+ comment.comment = "This is the first comment."
42
+ comment.save
43
+
44
+
45
+ Fetch comments for the commentable model by adding the following to the view:
46
+
47
+ commentable = Post.find(1)
48
+ comments = commentable.comments.recent.limit(10).all
49
+
50
+ You can also add different types of comments to a model:
51
+
52
+ class Todo < ActiveRecord::Base
53
+ acts_as_commentable :public, :private
54
+ end
55
+
56
+ *Note:* This feature is only available from version 4.0 and above
57
+
58
+ To fetch the different types of comments for this model:
59
+
60
+ public_comments = Todo.find(1).public_comments
61
+ private_comments = Todo.find(1).private_comments
62
+
63
+
64
+ By default, `acts_as_commentable` will assume you are using a `Comment` model.
65
+ To change this, or change any other join options, pass in an options hash:
66
+
67
+ class Todo < ActiveRecord::Base
68
+ acts_as_commentable class_name: 'MyComment'
69
+ end
70
+
71
+ This also works in conjunction with comment types:
72
+
73
+ class Todo < ActiveRecord::Base
74
+ acts_as_commentable :public, :private, { class_name: 'MyComment' }
75
+ end
76
+
77
+
78
+ == Credits
79
+
80
+ Xelipe - This plugin is heavily influenced by Acts As Taggable.
81
+
82
+ == Contributors
83
+
84
+ Jack Dempsey, Chris Eppstein, Jim Ray, Matthew Van Horn, Ole Riesenberg, ZhangJinzhu, maddox, monocle, mrzor, Michael Bensoussan
85
+
86
+ == More
87
+
88
+ http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
89
+ 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,43 @@
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, role]).order('created_at DESC')
33
+ end
34
+
35
+ # Helper class method to look up a commentable object
36
+ # given the commentable class name and id
37
+ def find_commentable(commentable_str, commentable_id)
38
+ model = commentable_str.constantize
39
+ model.respond_to?(:find_comments_for) ? model.find(commentable_id) : nil
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,86 @@
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".to_sym)
16
+
17
+ has_many "#{role}_comments".to_sym,
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
+ comment_roles.each do |role|
49
+ define_role_based_inflection(role)
50
+ end
51
+ has_many :all_comments, **{ as: :commentable, dependent: :destroy, class_name: 'Comment' }.merge(join_options)
52
+ else
53
+ has_many :comments, **{ as: :commentable, dependent: :destroy }.merge(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(["user_id = ? and commentable_type = ? and role = ?", user.id, commentable, "#{role}"]).order("created_at DESC")
68
+ end
69
+
70
+ def #{method_name}_ordered_by_submitted
71
+ Comment.find_comments_for_commentable(self.class.name, id, "#{role}").order("created_at")
72
+ end
73
+
74
+ def add_#{method_name.singularize}(comment)
75
+ comment.role = "#{role}"
76
+ #{method_name} << comment
77
+ end
78
+ }
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ ActiveRecord::Base.send(: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
+ @_acts_as_commentable_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,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_commentable2
3
+ version: !ruby/object:Gem::Version
4
+ version: 7.1.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.1.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.1.0
27
+ description: Plugin/gem that provides comment functionality
28
+ email: unknown@juixe.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
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.6.2
65
+ specification_version: 3
66
+ summary: Plugin/gem that provides comment functionality
67
+ test_files: []