<commit_before># DelegateCached

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'delegate_cached'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install delegate_cached

## Usage

First, add a column to the delegating ActiveRecord modelto cache the delegated
value. If using the `prefix: true` options, be sure to use the
`to` prefix in the column name. For example, as below, the column names required would be
`hiker_name` for the first `delegate_cached` definition, and `name` for the
second.

Second, add your `delegate_cached` definition. Note - you may only use
`delegate_cached` on `belongs_to` and `has_one` associations.

```ruby
class ThruHike < ApplicationRecord
  belongs_to :hiker, inverse_of: :thru_hikes
  belongs_to :trail, inverse_of: :thru_hikes

  delegate_cached :name, to: :hiker, prefix: true # hiker_name column required on thru_hikes table
  delegate_cached :name, to: :trail # name column required on thru_hikes tables
end
```

Third, use your models as you typically would with `delegate` When an instance
of the delegated-to model is saved, a callback will update your delegate_cached
value.

## Options

`update_when_nil: true` False by default. When set to true and the referenced
attribute is called, if the existing cached value is nil, it will attempt to
update the attribute value with the delegated value.

`skip_callback: true` False by default. When set to true, the `after_save`
callback on the delegated-to model will not set.


## Development<commit_msg>README.md corrections and gem badge addition<commit_after># DelegateCached

[![Gem Version](https://badge.fury.io/rb/delegate_cached.svg)](https://badge.fury.io/rb/delegate_cached)

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'delegate_cached'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install delegate_cached

## Usage

First, add a column to the delegating ActiveRecord model. If using the
`prefix: true` options, be sure to use the `to` prefix in the column name. 
For example, as below, the column names required would be `hiker_name` for the
first `delegate_cached` definition, and `name` for the second.

Second, add your `delegate_cached` definition. Note - you may only use
`delegate_cached` on `belongs_to` and `has_one` associations.

```ruby
class ThruHike < ApplicationRecord
  belongs_to :hiker, inverse_of: :thru_hikes
  belongs_to :trail, inverse_of: :thru_hikes

  delegate_cached :name, to: :hiker, prefix: true # hiker_name column required on thru_hikes table
  delegate_cached :name, to: :trail # name column required on thru_hikes tables
end
```

Third, use your models as you typically would with `delegate` When an instance
of the delegated-to model is saved, a callback will update your delegate_cached
value.

## Options

`update_when_nil: true` False by default. When set to true and the referenced
attribute is called, if the existing cached value is nil, it will attempt to
update the attribute value with the delegated value.

`skip_callback: true` False by default. When set to true, the `after_save`
callback on the delegated-to model will not set.


## Development
{'fraction_non_alphanumeric': 0.07383177570093458, 'fraction_numerical': 0.0, 'mean_word_length': 4.796028880866426, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2156221', 'n_tokens_mistral': 963, 'n_tokens_neox': 930, 'n_words': 420}