<commit_before># Paperclip Attributes

Rails Engine built on top of [Paperclip](https://github.com/thoughtbot/paperclip) gem to add attributes, as columns in your models, related to your attachments.

## Installation

Add to your Gemfile:

```ruby
gem "paperclip_attributes"
```

```bash
bundle install
```

## Usage

To add new attributes, you need to run the following generator:

```
rails g paperclip_attributes Model attachment recipe1 recipe2
```

* `Model`: is the Active Record model containing the attachment you want to add attributes.
* `attachment`: is the paperclip's attachment name on given model.
* `recipes (recipe1 recipe2)`: is a list of recipes to extend the attachment. A recipe represents one or more attributes related to the attachment param. You can see a full list of recipes on the section below.

The generator, will only create migrations to extend your attachments. So, after run it, you need to do:

```
rake db:migrate
```

That's it! the process to extract attributes will be done on `before_save` callback of your `ActiveRecord` model instances, if these models have **modified paperclip attachments.**

## Example

```
rails g paperclip_attributes User avatar dimensions color
```

Then, with an `User` instance, you be able to do something like this:

```ruby
user = User.new
user.avatar = some_file
user.save!

user.avatar_height #=> 200
user.avatar_width #=> 400
user.avatar_dominant_color #=> "#FF9900"

```

## Recipes

### For images:

#### `dimensions`:
<commit_msg>docs(README): add explicit setup explanation<commit_after># Paperclip Attributes

Rails Engine built on top of [Paperclip](https://github.com/thoughtbot/paperclip) gem to add attributes, as columns in your models, related to your attachments.

## Installation

Add to your Gemfile:

```ruby
gem "paperclip_attributes"
```

```bash
bundle install
```

## Usage

To add new attributes, you need to run the following generator:

```
rails g paperclip_attributes Model attachment recipe1 recipe2
```

* `Model`: is the Active Record model containing the attachment you want to add attributes.
* `attachment`: is the paperclip's attachment name on given model.
* `recipes (recipe1 recipe2)`: is a list of recipes to extend the attachment. A recipe represents one or more attributes related to the attachment param. You can see a full list of recipes on the section below.

The generator, will only create migrations to extend your attachments. So, after run it, you need to do:

```
rake db:migrate
```

Then, to enable the functionality in your model, you need to add the recipes to the attachment definition:

```ruby
class MyModel < ActiveRecord::Base
  has_attached_file :attachment, attributes: [:recipe1, :recipe2]
end
```

That's it!

The process to extract attributes will be done on `before_save` callback.

## Example

```
rails g paperclip_attributes User avatar dimensions color
```

In `User` model:

```ruby
class User < ActiveRecord::Base
  has_attached_file :avatar, attributes: [:dimensions, :color]
end
```

Then, with an `User` instance, you'll be able to do something like this:

```ruby
user = User.new
user.avatar = some_file
user.save!

user.avatar_height #=> 200
user.avatar_width #=> 400
user.avatar_dominant_color #=> "#FF9900"

```

## Recipes

### For images:

#### `dimensions`:

{'fraction_non_alphanumeric': 0.09634551495016612, 'fraction_numerical': 0.009060706735125339, 'mean_word_length': 4.903743315508021, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '5572382', 'n_tokens_mistral': 1010, 'n_tokens_neox': 931, 'n_words': 421}