<commit_before>[![Build Status](https://secure.travis-ci.org/dleung/status_for.png)](http://travis-ci.org/dleung/status_for)
 
# Status For

This module allows you to define a particular status, such as 'deleted', 'unread', 'viewed', etc, to an object, like a message, for a subject like a user.  For example, you can set message.mark_as_read_for(current_user), which marks the message as read, and you can call Message.read_for(current_user) which queries the database to find the messages that has been marked as 'read' for this user.  The query is not instantiated, so you can chain additional methods like .search and .paginate.

### Prerequisites
This module uses postgresql as the database.  It also needs the intarray extension to run.  You'll need to include postgresql in your Gemfile like gem 'pg'.

##Usage
This is an example where you want messages statuses "read" and "deleted" for a user.
#### Step 1: Include the gem
``` ruby
# In Gemfile
gem 'status_for'
###
```

#### Step 2: Models
``` ruby
# In your object, 'initialize_status_for' and include a class you want the subject to be.  
# model/messages.rb
initialize_status_for User
```

#### Step 3:  Migration Definition
``` ruby
# For each of the status you want, include a status_for integer column.
# db/migrate/add_status_to_message.rb

create_table :messages, :force => true
add_column :messages, :deleted_for, "integer[]"
add_column :messages, :read_for, "integer[]"

# You also need to create the intarray extension if you haven't before.
execute "CREATE EXTENSION IF NOT EXISTS intarray"
```

#### Step 4:  Use it!<commit_msg>added defaults in readme for columns<commit_after>[![Build Status](https://secure.travis-ci.org/dleung/status_for.png)](http://travis-ci.org/dleung/status_for)
 
# Status For

This module allows you to define a particular status, such as 'deleted', 'unread', 'viewed', etc, to an object, like a message, for a subject like a user.  For example, you can set message.mark_as_read_for(current_user), which marks the message as read, and you can call Message.read_for(current_user) which queries the database to find the messages that has been marked as 'read' for this user.  The query is not instantiated, so you can chain additional methods like .search and .paginate.

### Prerequisites
This module uses postgresql as the database.  It also needs the intarray extension to run.  You'll need to include postgresql in your Gemfile like gem 'pg'.

##Usage
This is an example where you want messages statuses "read" and "deleted" for a user.
#### Step 1: Include the gem
``` ruby
# In Gemfile
gem 'status_for'
###
```

#### Step 2: Models
``` ruby
# In your object, 'initialize_status_for' and include a class you want the subject to be.  
# model/messages.rb
initialize_status_for User
```

#### Step 3:  Migration Definition
``` ruby
# For each of the status you want, include a status_for integer column.
# db/migrate/add_status_to_message.rb

create_table :messages, :force => true
add_column :messages, :deleted_for, "integer[]", default: "{}"
add_column :messages, :read_for, "integer[]", default: "{}"

# You also need to create the intarray extension if you haven't before.
execute "CREATE EXTENSION IF NOT EXISTS intarray"
```

#### Step 4:  Use it!
{'fraction_non_alphanumeric': 0.10261136712749616, 'fraction_numerical': 0.002457757296466974, 'mean_word_length': 4.773049645390071, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1284555', 'n_tokens_mistral': 997, 'n_tokens_neox': 956, 'n_words': 420}