<commit_before># Acts As Featureable

Add a polymorphic resource to your rails app for pulling content to a main/features page.

## Installation

Add this line to your application's Gemfile:

    gem 'acts_as_featureable'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install acts_as_featureable
    
Run the generator

    rails g features

This will create the migration file and an initializer.

Migrate the database

    rake db:migrate

## Configuration

Edit the initializer file to set default settings for feature size and auto title & summary assigning.

## Usage

Add the line acts_as_featurable to the class you want to feature.

    class Topic
        acts_as_featurable
    end

Make sure the class you are making featureable has the methods 'title' and 'summary'

Add a feature to a model. The 'title' and 'summary' will be pulled from the model
unless you specify otherwise and only if the corresponding reader methods exist.

    featureable = Topic.create
    featureable.features.create # will have title and summary of the Topic

or

    featureable = Topic.create
    featureable.features.create(title: 'My New Title', summary 'Short description here')

Get all features by thier position

    Feature.ordered
<commit_msg>expand readme<commit_after># Acts As Featureable

Add a polymorphic resource to your rails app for pulling content to a main/features page.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'acts_as_featureable'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install acts_as_featureable
    
Run the generator:

    $ rails g features

This will create the migration file and an initializer.

Migrate the database:

    $ rake db:migrate

## Configuration

Edit the initializer file to set default settings for feature size and auto title & summary assigning.

## Usage

### Featureable Model

Add the appropriate line to the class you want to feature.

```ruby
class Topic
	acts_as_featurable
end
```

### Creating Features

Add a feature to a model. The 'title' and 'summary' (or whichever methods you add in the initializer file) will be assigned.

```ruby
featureable = Topic.create(title: 'Title', summary: 'Summary')
featureable.features.create
#<Feature title: "Title", summary: "Summary">
```

You can also override them directly.

```ruby
featureable = Topic.create(title: 'Title', summary: 'Summary')
featureable.features.create(title: 'My New Title', summary 'My New Summary')
#<Feature title: "My New Title", summary: "My New Summary">
```

The positioning of the features can be specified

```ruby
featureable = Topic.create
featureable.features.create(position: 3)
#<Feature position: 3>
```

If it is not specified, it will automatically be assigned the next, lowest position

```ruby
featureable = Topic.create
featureable.features.create
#<Feature position: 1>

featureable.features.create
#<Feature position: 2>
```

If you try and assign a position which has already been taken, it will find the next, lowest available position.

```ruby
featureable = Topic.create
featureable.features.create
#<Feature position: 1>

featureable.features.create(position: 1)
#<Feature position: 2>

featureable.features.create(position: 1)
#<Feature position: 3>
```

### Feature scope

Get all features by thier position

```ruby
Feature.ordered
```

{'fraction_non_alphanumeric': 0.07669529167900503, 'fraction_numerical': 0.0026650873556411016, 'mean_word_length': 4.294670846394984, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '2782799', 'n_tokens_mistral': 994, 'n_tokens_neox': 925, 'n_words': 417}