<commit_before># ActionMailer Callbacks

[![Build Status](https://secure.travis-ci.org/spaghetticode/actionmailer-callbacks.png)](http://travis-ci.org/spaghetticode/actionmailer-callbacks)

This gem adds *before_create* and *around_create* to ActionMailer::Base to make it
work similarly to ActionController before/around filters and ActiveRecord::Base
callbacks:

```ruby
  before_create  :log_params, except: :test_email
  around_create  :benchmark,  only:   :test_email
```

*except* and *only* options are optional and has same functionality as in
ActionController.


## Requirements

The master branch now works only with Actionmailer 3.x, if you need to add
callbacks to older versions please refer to the 0.x release.


## Installation

Add the gem to the Gemfile:

```ruby
  gem 'actionmailer-callbacks'
```

And then run ```bundle```


## Notes

If you need something like before/after deliver callbacks ActionMailer 3.x comes
ready for that: you can use an *observer* or an *instrumentation* for that.

*around_create* wraps the mail method execution (and all before_create callbacks).
You can use them for rescuing from errors or for benchmarking, for example.
There can be only one *around_create* method for each email method, if you
register more than one only the first will be executed.


## Example<commit_msg>update readme with relish link<commit_after># ActionMailer Callbacks

[![Build Status](https://secure.travis-ci.org/spaghetticode/actionmailer-callbacks.png)](http://travis-ci.org/spaghetticode/actionmailer-callbacks)

This gem adds *before_create* and *around_create* to ActionMailer::Base to make it
work similarly to ActionController before/around filters and ActiveRecord::Base
callbacks:

```ruby
  before_create  :log_params, except: :test_email
  around_create  :benchmark,  only:   :test_email
```

*except* and *only* options are optional and has same functionality as in
ActionController.


## Requirements

The master branch now works only with Actionmailer 3.x, if you need to add
callbacks to older versions please refer to the 0.x release.


## Installation

Add the gem to the Gemfile:

```ruby
  gem 'actionmailer-callbacks'
```

And then run ```bundle```


## Documentation

You can find some more documentation on the workings of the gem on relish:
https://www.relishapp.com/spaghetticode/actionmailer-callbacks/docs


## Notes

If you need something like before/after deliver callbacks ActionMailer 3.x comes
ready for that: you can use an *observer* or an *instrumentation* for that.

*around_create* wraps the mail method execution (and all before_create callbacks).
You can use them for rescuing from errors or for benchmarking, for example.
There can be only one *around_create* method for each email method, if you
register more than one only the first will be executed.


## Example
{'fraction_non_alphanumeric': 0.07974594213126324, 'fraction_numerical': 0.002117148906139732, 'mean_word_length': 4.993657505285412, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, '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': '2383334', 'n_tokens_mistral': 851, 'n_tokens_neox': 815, 'n_words': 335}