<commit_before>Active Record Tweaks
===========

Active Record is great, but could be better. Here are some tweaks for it.

[![Build Status](http://img.shields.io/travis/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://travis-ci.org/PikachuEXE/active_record_tweaks)
[![Gem Version](http://img.shields.io/gem/v/active_record_tweaks.svg?style=flat-square)](http://badge.fury.io/rb/active_record_tweaks)
[![Dependency Status](http://img.shields.io/gemnasium/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://gemnasium.com/PikachuEXE/active_record_tweaks)
[![Coverage Status](http://img.shields.io/coveralls/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://coveralls.io/r/PikachuEXE/active_record_tweaks)
[![Code Climate](http://img.shields.io/codeclimate/github/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://codeclimate.com/github/PikachuEXE/active_record_tweaks)

Install
=======

```ruby
gem 'active_record_tweaks'
```

Usage
=====

Either include it in specific record or just `ActiveRecord::Base`
```ruby
class SomeRecord
  include ActiveRecordTweaks
end 

# or

# In a initialzer
ActiveRecord::Base.send(:include, ActiveRecordTweaks)
```


### `#cache_key_without_timestamp`
Nothing special, just like `record.cache_key`  
But it has no timestamp so you can use it for scoped cache key  
e.g. When caching with Cookie, which you want to control the expiry time independent of record update time  
Usage:
```ruby
  # Just like using #cache_key
  record.cache_key_without_timestamp
```


### `#cache_key_from_attributes`
Nothing special, just like `record.cache_key` in rails 4.1  
But it does not check against columns  
e.g. When you have some virtual timestamp attribute method (cached or not)  
Just make sure you throw some name to it or it will raise error  
Alias: `#cache_key_from_attribute`  <commit_msg>~ Update README formatting [ci skip]<commit_after># Active Record Tweaks

Active Record is great, but could be better. Here are some tweaks for it.


## Status

[![Build Status](http://img.shields.io/travis/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://travis-ci.org/PikachuEXE/active_record_tweaks)
[![Gem Version](http://img.shields.io/gem/v/active_record_tweaks.svg?style=flat-square)](http://badge.fury.io/rb/active_record_tweaks)
[![Dependency Status](http://img.shields.io/gemnasium/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://gemnasium.com/PikachuEXE/active_record_tweaks)
[![Coverage Status](http://img.shields.io/coveralls/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://coveralls.io/r/PikachuEXE/active_record_tweaks)
[![Code Climate](http://img.shields.io/codeclimate/github/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://codeclimate.com/github/PikachuEXE/active_record_tweaks)


## Installation

```ruby
gem 'active_record_tweaks'
```


## Usage

Either include it in specific record or just `ActiveRecord::Base`
```ruby
class SomeRecord
  include ActiveRecordTweaks
end 

# or

# In a initialzer
ActiveRecord::Base.send(:include, ActiveRecordTweaks)
```


### `#cache_key_without_timestamp`
Nothing special, just like `record.cache_key`  
But it has no timestamp so you can use it for scoped cache key  
e.g. When caching with Cookie, which you want to control the expiry time independent of record update time  
Usage:
```ruby
  # Just like using #cache_key
  record.cache_key_without_timestamp
```


### `#cache_key_from_attributes`
Nothing special, just like `record.cache_key` in rails 4.1  
But it does not check against columns  
e.g. When you have some virtual timestamp attribute method (cached or not)  
Just make sure you throw some name to it or it will raise error  
Alias: `#cache_key_from_attribute`  
{'fraction_non_alphanumeric': 0.1226815050344462, 'fraction_numerical': 0.0010598834128245894, 'mean_word_length': 5.765232974910394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, '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': '5023902', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1285, 'n_words': 291}