<commit_before># Parole

[![Gem Version](https://badge.fury.io/rb/parole.png)](https://rubygems.org/gems/parole)

Parole adds the ability to comment on ActiveRecord records.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'parole'
```

Then run the task to generate the migration:

```bash
$ rails generate parole:install
```

## Usage

You should now be able to mark models as *commentable*:

```ruby
class Article < ActiveRecord::Base
  acts_as_commentable
end
```

You’re pretty much done after that. You’re now able to do this:

```ruby
user = User.find(1)
article = Article.find(1)

article.comments.create(commenter: user, comment: 'Hello world!')
article.comments.count # => 1
```

You can also provide roles for comments, so you can have multiple type of comments per record.

```ruby
class Article < ActiveRecord::Base
  acts_as_commentable roles: [:photos, :videos]
end

user = User.find(1)
article = Article.find(1)

article.photos_comments.create(commenter: user, comment: 'Hello world!')
article.photos_comments.count # => 1
article.comments.count # => 1
```

### Cache counters

Whenever a comment is created or destroyed, Parole looks into the commentable record and check
if there’s a `<role>_comments_count` column and/or a `comments_count` column. If so, it updates
them so they reflect the total number of comments and the number of comments of this role for
the record.

```ruby
class Article < ActiveRecord::Base
  acts_as_commentable roles: [:photos, :videos]
end

user = User.find(1)
article = Article.find(1)

article.photos_comments.create(commenter: user, comment: 'Hello world!')
article.photos_comments_count # => 1
article.videos_comments_count # => 0
article.comments_count # => 1

article.videos_comments.create(commenter: user, comment: 'Hello world again!')<commit_msg>Add note in cache counter section<commit_after># Parole

[![Gem Version](https://badge.fury.io/rb/parole.png)](https://rubygems.org/gems/parole)

Parole adds the ability to comment on ActiveRecord records.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'parole'
```

Then run the task to generate the migration:

```bash
$ rails generate parole:install
```

## Usage

You should now be able to mark models as *commentable*:

```ruby
class Article < ActiveRecord::Base
  acts_as_commentable
end
```

You’re pretty much done after that. You’re now able to do this:

```ruby
user = User.find(1)
article = Article.find(1)

article.comments.create(commenter: user, comment: 'Hello world!')
article.comments.count # => 1
```

You can also provide roles for comments, so you can have multiple type of comments per record.

```ruby
class Article < ActiveRecord::Base
  acts_as_commentable roles: [:photos, :videos]
end

user = User.find(1)
article = Article.find(1)

article.photos_comments.create(commenter: user, comment: 'Hello world!')
article.photos_comments.count # => 1
article.comments.count # => 1
```

### Cache counters

Whenever a comment is created or destroyed, Parole looks into the commentable record and check
if there’s a `<role>_comments_count` column and/or a `comments_count` column. If so, it updates
them so they reflect the total number of comments and the number of comments of this role for
the record.

So let’s say the `Article` model has the following columns: `photos_comments_count`, `videos_comments_count` and `comments_count`.

```ruby
class Article < ActiveRecord::Base
  acts_as_commentable roles: [:photos, :videos]
end

user = User.find(1)
article = Article.find(1)

article.photos_comments.create(commenter: user, comment: 'Hello world!')
article.photos_comments_count # => 1
article.videos_comments_count # => 0
article.comments_count # => 1

article.videos_comments.create(commenter: user, comment: 'Hello world again!')
{'fraction_non_alphanumeric': 0.11227701993704092, 'fraction_numerical': 0.0062959076600209865, 'mean_word_length': 5.230392156862745, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '273257', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1157, 'n_words': 410}