traq_has_comments 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +2 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/db/migrate/commentable_migration.rb +20 -0
- data/lib/generators/traq_has_comments/install_generator.rb +20 -0
- data/lib/traq_has_comments.rb +14 -0
- data/lib/traq_has_comments/author.rb +26 -0
- data/lib/traq_has_comments/comment.rb +25 -0
- data/lib/traq_has_comments/commentable.rb +38 -0
- data/lib/traq_has_comments/owner.rb +26 -0
- data/lib/traq_has_comments/version.rb +4 -0
- data/spec/author_spec.rb +7 -0
- data/spec/comment_spec.rb +9 -0
- data/spec/commentable_spec.rb +7 -0
- data/spec/owner_spec.rb +7 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/support/account.rb +5 -0
- data/spec/support/database_cleaner.rb +23 -0
- data/spec/support/post.rb +5 -0
- data/spec/support/user.rb +5 -0
- data/traq_has_comments.gemspec +30 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0bcf9e646dee3d24e2ed4009447fc779f923f090
|
4
|
+
data.tar.gz: 3926f0ef4ca6076e2efb1b7299eff0b133f98009
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 891ab329cebc6ee0624d96581d3789d5d8166c94715c2778ea4cd7f72c09c5fc78258c9c5881e02b8fbf909a84049d77824cdd45ef2a3fbfcb42d886d90a067c
|
7
|
+
data.tar.gz: 0983257ec631b7a780df474b437ba7ff6a75739caf6fee2c56b2e2e5a86152fbc6dac4b8b11d9b44d39fd9aeaaddd1d3f021378c7b55931365b65c7889b9a8c0
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
# TraqHasComments
|
3
|
+
|
4
|
+
Add commenting functionality to any application model.
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'traq_has_comments'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install traq_has_comments
|
20
|
+
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Add the comments migration:
|
25
|
+
|
26
|
+
$ rails generate traq_has_comments:install
|
27
|
+
|
28
|
+
Then run:
|
29
|
+
|
30
|
+
$ rake db:migrate
|
31
|
+
|
32
|
+
Add to each commentable model:
|
33
|
+
|
34
|
+
has_comments
|
35
|
+
|
36
|
+
Add to each commenter model:
|
37
|
+
|
38
|
+
authors_comments
|
39
|
+
|
40
|
+
Add to the comment owner (e.g., account) model:
|
41
|
+
|
42
|
+
owns_comments
|
43
|
+
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( https://github.com/[my-github-username]/traq_has_comments/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
class CommentableMigration < ActiveRecord::Migration
|
3
|
+
|
4
|
+
def change
|
5
|
+
create_table :comments do |t|
|
6
|
+
t.string :title
|
7
|
+
t.text :body
|
8
|
+
t.integer :commentable_id, default: 0
|
9
|
+
t.string :commentable_type
|
10
|
+
t.integer :user_id, default: 0, null: false
|
11
|
+
t.integer :account_id, default: 0, null: false
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :comments, [:commentable_id, :commentable_type]
|
17
|
+
add_index :comments, :user_id
|
18
|
+
add_index :comments, :account_id
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module TraqHasComments
|
5
|
+
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
|
10
|
+
source_root File.expand_path('../../../../db/migrate', __FILE__)
|
11
|
+
|
12
|
+
def create_migrations
|
13
|
+
migration_template 'commentable_migration.rb', 'db/migrate/commentable_migration.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.next_migration_number(path)
|
17
|
+
@migration_number = Time.now.utc.strftime('%Y%m%d%H%M%S').to_i.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require 'traq_has_comments/version'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
module TraqHasComments
|
6
|
+
require 'traq_has_comments/comment'
|
7
|
+
require 'traq_has_comments/commentable'
|
8
|
+
require 'traq_has_comments/author'
|
9
|
+
require 'traq_has_comments/owner'
|
10
|
+
|
11
|
+
ActiveRecord::Base.extend Commentable
|
12
|
+
ActiveRecord::Base.extend Author
|
13
|
+
ActiveRecord::Base.extend Owner
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
module TraqHasComments
|
3
|
+
|
4
|
+
module Author
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def authors_comments
|
9
|
+
|
10
|
+
has_many :comments, class_name: 'TraqHasComments::Comment'
|
11
|
+
|
12
|
+
extend ClassMethods
|
13
|
+
extend SingletonMethods
|
14
|
+
include InstanceMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
end
|
19
|
+
|
20
|
+
module SingletonMethods
|
21
|
+
end
|
22
|
+
|
23
|
+
module InstanceMethods
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module TraqHasComments
|
3
|
+
|
4
|
+
class Comment < ::ActiveRecord::Base
|
5
|
+
|
6
|
+
belongs_to :commentable, polymorphic: true
|
7
|
+
belongs_to :author, foreign_key: 'user_id', class_name: 'User'
|
8
|
+
belongs_to :owner, foreign_key: 'account_id', class_name: 'Account'
|
9
|
+
|
10
|
+
validates :body, presence: true
|
11
|
+
validates :author, presence: true
|
12
|
+
validates :owner, presence: true
|
13
|
+
|
14
|
+
# TODO: Define methods to check commenting permissions. Consider how to implement admin defined permissions through settings.
|
15
|
+
|
16
|
+
# def can_create_comment?(user)
|
17
|
+
# end
|
18
|
+
|
19
|
+
# def can_update_comment?(user)
|
20
|
+
# end
|
21
|
+
|
22
|
+
# def can_delete_comment?(user)
|
23
|
+
# end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
module TraqHasComments
|
3
|
+
|
4
|
+
module Commentable
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def has_comments
|
9
|
+
|
10
|
+
has_many :comments, as: :commentable, class_name: 'TraqHasComments::Comment'
|
11
|
+
|
12
|
+
extend ClassMethods
|
13
|
+
extend SingletonMethods
|
14
|
+
include InstanceMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
end
|
19
|
+
|
20
|
+
module SingletonMethods
|
21
|
+
|
22
|
+
def find_comments_for_commentable(account, obj)
|
23
|
+
HasComments::Comment.where(account_id: account.id).where(commentable_id: obj.id, commentable_type: obj.class.base_class).order('created_at DESC')
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_comments_by_user(account, user)
|
27
|
+
HasComments::Comment.where(account_id: account.id).where(user_id: user.id).order('created_at DESC')
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_commentable(obj)
|
31
|
+
obj.class.base_class.find(obj.id)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module InstanceMethods
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
module TraqHasComments
|
3
|
+
|
4
|
+
module Owner
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def owns_comments
|
9
|
+
|
10
|
+
has_many :comments, class_name: 'TraqHasComments::Comment'
|
11
|
+
|
12
|
+
extend ClassMethods
|
13
|
+
extend SingletonMethods
|
14
|
+
include InstanceMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
end
|
19
|
+
|
20
|
+
module SingletonMethods
|
21
|
+
end
|
22
|
+
|
23
|
+
module InstanceMethods
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/author_spec.rb
ADDED
data/spec/owner_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
require 'traq_has_comments'
|
3
|
+
require 'support/database_cleaner'
|
4
|
+
require 'support/post'
|
5
|
+
require 'support/user'
|
6
|
+
require 'support/account'
|
7
|
+
require 'database_cleaner'
|
8
|
+
require 'shoulda/matchers'
|
9
|
+
|
10
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define do
|
13
|
+
self.verbose = false
|
14
|
+
|
15
|
+
create_table :accounts, force: true do |t|
|
16
|
+
t.string :name
|
17
|
+
end
|
18
|
+
|
19
|
+
create_table :users, force: true do |t|
|
20
|
+
t.string :name
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table :posts, force: true do |t|
|
24
|
+
t.string :title
|
25
|
+
t.text :body
|
26
|
+
t.integer :user_id
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table :comments, force: true do |t|
|
30
|
+
t.string :body
|
31
|
+
t.string :commentable_type
|
32
|
+
t.integer :commentable_id
|
33
|
+
t.integer :user_id
|
34
|
+
t.integer :account_id
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
RSpec.configure do |config|
|
3
|
+
|
4
|
+
config.before(:suite) do
|
5
|
+
DatabaseCleaner.clean_with(:truncation)
|
6
|
+
end
|
7
|
+
|
8
|
+
config.before(:each) do
|
9
|
+
DatabaseCleaner.strategy = :transaction
|
10
|
+
end
|
11
|
+
|
12
|
+
config.before(:each, :js => true) do
|
13
|
+
DatabaseCleaner.strategy = :truncation
|
14
|
+
end
|
15
|
+
|
16
|
+
config.before(:each) do
|
17
|
+
DatabaseCleaner.start
|
18
|
+
end
|
19
|
+
|
20
|
+
config.after(:each) do
|
21
|
+
DatabaseCleaner.clean
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'traq_has_comments/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'traq_has_comments'
|
9
|
+
spec.version = TraqHasComments::VERSION
|
10
|
+
spec.authors = ['Michael P. Martin']
|
11
|
+
spec.email = ['mmartin@levsrin.com']
|
12
|
+
spec.summary = 'Add polymorphic comments.'
|
13
|
+
spec.description = 'Add commenting functionality to any application model.'
|
14
|
+
spec.homepage = ''
|
15
|
+
spec.license = ''
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'sqlite3'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'shoulda-matchers'
|
27
|
+
spec.add_development_dependency 'database_cleaner'
|
28
|
+
|
29
|
+
spec.add_runtime_dependency 'activerecord'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: traq_has_comments
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.12
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael P. Martin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: shoulda-matchers
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: database_cleaner
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Add commenting functionality to any application model.
|
112
|
+
email:
|
113
|
+
- mmartin@levsrin.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- db/migrate/commentable_migration.rb
|
124
|
+
- lib/generators/traq_has_comments/install_generator.rb
|
125
|
+
- lib/traq_has_comments.rb
|
126
|
+
- lib/traq_has_comments/author.rb
|
127
|
+
- lib/traq_has_comments/comment.rb
|
128
|
+
- lib/traq_has_comments/commentable.rb
|
129
|
+
- lib/traq_has_comments/owner.rb
|
130
|
+
- lib/traq_has_comments/version.rb
|
131
|
+
- spec/author_spec.rb
|
132
|
+
- spec/comment_spec.rb
|
133
|
+
- spec/commentable_spec.rb
|
134
|
+
- spec/owner_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
- spec/support/account.rb
|
137
|
+
- spec/support/database_cleaner.rb
|
138
|
+
- spec/support/post.rb
|
139
|
+
- spec/support/user.rb
|
140
|
+
- traq_has_comments.gemspec
|
141
|
+
homepage: ''
|
142
|
+
licenses:
|
143
|
+
- ''
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.4.1
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: Add polymorphic comments.
|
165
|
+
test_files:
|
166
|
+
- spec/author_spec.rb
|
167
|
+
- spec/comment_spec.rb
|
168
|
+
- spec/commentable_spec.rb
|
169
|
+
- spec/owner_spec.rb
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
- spec/support/account.rb
|
172
|
+
- spec/support/database_cleaner.rb
|
173
|
+
- spec/support/post.rb
|
174
|
+
- spec/support/user.rb
|