commentable_on 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 977c9733dc850169abece4df1029b7d41777b97138b2a2abbd9df4224118e81c
4
+ data.tar.gz: b0cbcf3f8ede3685d03dc4bf706bace452cbe8c95ee1ff58e141b66d4c451875
5
+ SHA512:
6
+ metadata.gz: 2c1c4b801b7a65535a9e8595c15d94745d0cad32506264ba33647c5515d98b5bdee4fa81bea0c73861eaeeb6ca0b41f620b6facd26f2b8a033da36965c3a099e
7
+ data.tar.gz: 60dea80bd2cf24badd245fe637d3345837a26d7a9b7c8e0caadfbc9188a8396be82fd41ac9f51b6d32cf5a8a3a5d550df2aab5d23137d2e12467b9dd5d74c979
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # IDE generated files
14
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require:
2
+ - standard
3
+ - rubocop-rspec
4
+ - rubocop-rake
5
+
6
+ inherit_gem:
7
+ standard: config/base.yml
8
+
9
+ AllCops:
10
+ NewCops: enable
11
+ Exclude:
12
+ - public/**/*
13
+ - vendor/**/*
14
+ - config/**/*
15
+ - db/schema.rb
16
+ TargetRubyVersion: 2.7.4
17
+
18
+ RSpec:
19
+ Enabled: true # enable rubocop-rspec cops
20
+ RSpec/DescribeClass:
21
+ Enabled: false # ignore missing comments on classes
22
+ Bundler/DuplicatedGem:
23
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at thesamuelralak@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in commentable_on.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.6"
8
+ gem "sqlite3", "~> 1.5"
9
+ gem "factory_bot", "~> 6.2"
10
+ gem "activerecord", "~> 7.0", require: false
11
+ gem "rubocop", "= 1.35.1", require: false
12
+ gem "standard", "~> 1.16", ">= 1.16.1", require: false
13
+ gem "rubocop-rspec", require: false
14
+ gem "rubocop-rake", "~> 0.6.0", require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ commentable_on (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activemodel (7.0.4)
10
+ activesupport (= 7.0.4)
11
+ activerecord (7.0.4)
12
+ activemodel (= 7.0.4)
13
+ activesupport (= 7.0.4)
14
+ activesupport (7.0.4)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ ast (2.4.2)
20
+ concurrent-ruby (1.1.10)
21
+ diff-lcs (1.5.0)
22
+ factory_bot (6.2.1)
23
+ activesupport (>= 5.0.0)
24
+ i18n (1.12.0)
25
+ concurrent-ruby (~> 1.0)
26
+ json (2.6.2)
27
+ mini_portile2 (2.8.0)
28
+ minitest (5.16.3)
29
+ parallel (1.22.1)
30
+ parser (3.1.2.1)
31
+ ast (~> 2.4.1)
32
+ rainbow (3.1.1)
33
+ rake (12.3.3)
34
+ regexp_parser (2.6.0)
35
+ rexml (3.2.5)
36
+ rspec (3.12.0)
37
+ rspec-core (~> 3.12.0)
38
+ rspec-expectations (~> 3.12.0)
39
+ rspec-mocks (~> 3.12.0)
40
+ rspec-core (3.12.0)
41
+ rspec-support (~> 3.12.0)
42
+ rspec-expectations (3.12.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-mocks (3.12.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.12.0)
48
+ rspec-support (3.12.0)
49
+ rubocop (1.35.1)
50
+ json (~> 2.3)
51
+ parallel (~> 1.10)
52
+ parser (>= 3.1.2.1)
53
+ rainbow (>= 2.2.2, < 4.0)
54
+ regexp_parser (>= 1.8, < 3.0)
55
+ rexml (>= 3.2.5, < 4.0)
56
+ rubocop-ast (>= 1.20.1, < 2.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (>= 1.4.0, < 3.0)
59
+ rubocop-ast (1.23.0)
60
+ parser (>= 3.1.1.0)
61
+ rubocop-performance (1.14.3)
62
+ rubocop (>= 1.7.0, < 2.0)
63
+ rubocop-ast (>= 0.4.0)
64
+ rubocop-rake (0.6.0)
65
+ rubocop (~> 1.0)
66
+ rubocop-rspec (2.15.0)
67
+ rubocop (~> 1.33)
68
+ ruby-progressbar (1.11.0)
69
+ sqlite3 (1.5.3)
70
+ mini_portile2 (~> 2.8.0)
71
+ standard (1.16.1)
72
+ rubocop (= 1.35.1)
73
+ rubocop-performance (= 1.14.3)
74
+ tzinfo (2.0.5)
75
+ concurrent-ruby (~> 1.0)
76
+ unicode-display_width (2.3.0)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ activerecord (~> 7.0)
83
+ commentable_on!
84
+ factory_bot (~> 6.2)
85
+ rake (~> 12.0)
86
+ rspec (~> 3.6)
87
+ rubocop (= 1.35.1)
88
+ rubocop-rake (~> 0.6.0)
89
+ rubocop-rspec
90
+ sqlite3 (~> 1.5)
91
+ standard (~> 1.16, >= 1.16.1)
92
+
93
+ BUNDLED WITH
94
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Samuel Ralak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # _**Under active development**_
2
+
3
+ # Commentable On Steroids
4
+
5
+ Adds comments functionality to Rails/ActiveRecord modules
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'commentable_on'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install commentable_on
22
+
23
+ ## Database migrations
24
+
25
+ Generate migration and run migrations
26
+
27
+ ```shell
28
+ rails generate commentable_on:migration
29
+ rails db:migrate
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Make model commentable
35
+
36
+ ```ruby
37
+ class Post < ActiveRecord::Base
38
+ acts_as_commentable
39
+ end
40
+ ```
41
+
42
+ Add a comment to model instance:
43
+ ```ruby
44
+ @post = Post.find(params[:post_id])
45
+ @post.add_comment(commenter: current_user, body: "Awesome")
46
+ ```
47
+
48
+ The commenter, add `acts_as_commenter` to commenter models for reserve functionality
49
+ ```ruby
50
+ class User < ActiveRecord::Base
51
+ acts_as_commenter
52
+ end
53
+ ```
54
+
55
+ Add comment as a commenter
56
+ ```ruby
57
+ @post = Post.find(params[:post_id])
58
+ current_user.comment(commentable: @post, body: "awesome")
59
+ ```
60
+
61
+ ## Development
62
+
63
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+
65
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/commentable_on. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/commentable_on/blob/master/CODE_OF_CONDUCT.md).
70
+
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
75
+
76
+ ## Code of Conduct
77
+
78
+ Everyone interacting in the CommentableOn project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/commentable_on/blob/master/CODE_OF_CONDUCT.md).
79
+
80
+ ## TO DO
81
+
82
+ - [ ] Add comment threading
83
+ - [ ] Add migration generators
84
+ - [ ] Automate gem release
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "commentable_on"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require_relative "lib/commentable_on/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "commentable_on"
5
+ spec.version = CommentableOn::VERSION
6
+ spec.authors = ["Samuel Ralak"]
7
+ spec.email = ["thesamuelralak@gmail.com"]
8
+
9
+ spec.summary = "Provides comment functionality with replies"
10
+ spec.description = "Placeholder description text explaining how commentable on steroids will save the world in 5 words or less"
11
+ spec.homepage = "https://github.com/samuelralak/commentable-on"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/samuelralak/commentable-on"
19
+ spec.metadata["changelog_uri"] = "https://github.com/samuelralak/commentable-on"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,13 @@
1
+ module CommentableOn
2
+ class Comment < ::ActiveRecord::Base
3
+ if defined?(ProtectedAttributes)
4
+ attr_accessible :commentable_id, :commentable_type, :commenter_id, :commenter_type, :commentable, :commenter, :body
5
+ end
6
+
7
+ belongs_to :commentable, polymorphic: true
8
+ belongs_to :commenter, polymorphic: true
9
+
10
+ validates_presence_of :commentable_id
11
+ validates_presence_of :commenter_id
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module CommentableOn
2
+ module Commentable
3
+ def self.included(base)
4
+ base.class_eval do
5
+ has_many :comments, class_name: "CommentableOn::Comment", as: :commentable, dependent: :delete_all do
6
+ def commenters
7
+ includes(:commenter).map(&:commenter)
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ def add_comment(commenter:, body:)
14
+ comment = CommentableOn::Comment.new(commentable: self, commenter: commenter, body: body)
15
+ comment.save
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module CommentableOn
2
+ module Commenter
3
+ def self.included(base)
4
+ base.class_eval do
5
+ has_many :comments, class_name: "CommentableOn::Comment", as: :commenter, dependent: :nullify do
6
+ def commentables
7
+ includes(:commentable).map(&:commentable)
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ def comment(commentable:, body:)
14
+ commentable.add_comment args.merge(commenter: self, body: body)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module CommentableOn
2
+ module Extenders
3
+ module Commentable
4
+ def commentable?
5
+ false
6
+ end
7
+
8
+ def acts_as_commentable(*_args)
9
+ include CommentableOn::Commentable
10
+
11
+ class_eval do
12
+ def self.commentable?
13
+ true
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module CommentableOn
2
+ module Extenders
3
+ module Commenter
4
+ def commenter?
5
+ false
6
+ end
7
+
8
+ def acts_as_commenter(*_args)
9
+ include CommentableOn::Commenter
10
+
11
+ class_eval do
12
+ def self.commenter?
13
+ true
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module CommentableOn
2
+ module Extenders
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :Commentable
6
+ autoload :Commenter
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module CommentableOn
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ require "active_record"
2
+ require "active_support/inflector"
3
+ require "active_support/dependencies/autoload"
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
+ module CommentableOn
8
+ extend ActiveSupport::Autoload
9
+ class Error < StandardError; end
10
+
11
+ autoload :Commentable
12
+ autoload :Comment
13
+ autoload :Commenter
14
+ autoload :Extenders
15
+
16
+ if defined?(ActiveRecord::Base)
17
+ ActiveRecord::Base.extend CommentableOn::Extenders::Commentable
18
+ ActiveRecord::Base.extend CommentableOn::Extenders::Commenter
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commentable_on
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Ralak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Placeholder description text explaining how commentable on steroids will
14
+ save the world in 5 words or less
15
+ email:
16
+ - thesamuelralak@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".travis.yml"
25
+ - CODE_OF_CONDUCT.md
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - bin/console
32
+ - bin/setup
33
+ - commentable_on.gemspec
34
+ - lib/commentable_on.rb
35
+ - lib/commentable_on/comment.rb
36
+ - lib/commentable_on/commentable.rb
37
+ - lib/commentable_on/commenter.rb
38
+ - lib/commentable_on/extenders.rb
39
+ - lib/commentable_on/extenders/commentable.rb
40
+ - lib/commentable_on/extenders/commenter.rb
41
+ - lib/commentable_on/version.rb
42
+ homepage: https://github.com/samuelralak/commentable-on
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ homepage_uri: https://github.com/samuelralak/commentable-on
47
+ source_code_uri: https://github.com/samuelralak/commentable-on
48
+ changelog_uri: https://github.com/samuelralak/commentable-on
49
+ post_install_message:
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: 2.3.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.1.6
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Provides comment functionality with replies
68
+ test_files: []