<commit_before># OutcomeResolver

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'outcome_resolver'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install outcome_resolver

## Usage

The purpose of this gem is to provide an outcome handling API to clients of service objects than have more associated outcome states that success or failure A jobletter subscription service for example might have many outcomes depending on the user status, session and success or failure of the subscription. In this case on might use the outcome resolver API as follows:

```ruby

service = JobletterSubscriptionService.new(session)
service.subscribe(params[:email])

service.resolve_outcome do |outcome|
  outcome
  .when :email_missing do
    flash[:alert] = "Bitte gib deine Email-Adresse an."
  end
  .when :email_invalid do
    flash[:alert] = "Diese Email-Adresse ist nicht gültig."
  end


end

```
Inside the service declare all expected outcomes via the `outcomes` class macro which expects one or more symbols. When the service actions are performed flags corresponding to the specified outcomes have to be set. This is done by simply passing a boolean value to a method of the same name as the outcome declared in the outcomes argument list.

```ruby

class JobletterSubscriptionService

  include OutcomeResolver

  outcomes :email_missing, :email_invalid

  def subscribe(email)
    email_missing false
    validate_email(email)
    #perform rest of subscription logic
  end<commit_msg>eidt readme<commit_after># OutcomeResolver

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'outcome_resolver'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install outcome_resolver

## Usage

The purpose of this gem is to provide an outcome handling API to clients of service objects than have more associated outcome states that success or failure A jobletter subscription service for example might have many outcomes depending on the user status, session and success or failure of the subscription. In this case on might use the outcome resolver API as follows:

```ruby

service = JobletterSubscriptionService.new(session)
service.subscribe(params[:email])

service.resolve_outcome do |outcome|
  outcome
  .when :email_missing do
    flash[:alert] = "Bitte gib deine Email-Adresse an."
  end
  .when :email_invalid do
    flash[:alert] = "Diese Email-Adresse ist nicht gültig."
  end
  .when :user_signed_in do |email_confirmed|
    if email_confirmed
      flash[:alert] = "Howdy, bitte bestaetige noch deine Email-Adresse."
    end
  end

end

```
Inside the service declare all expected outcomes via the `outcomes` class macro which expects one or more symbols. When the service actions are performed flags corresponding to the specified outcomes have to be set. This is done by simply passing a boolean value to a method of the same name as the outcome declared in the outcomes argument list. These methods can take an optional number of arguments that is passed to the block in the `when` clause.

```ruby

class JobletterSubscriptionService

  include OutcomeResolver

  outcomes :email_missing, :email_invalid

  def subscribe(email)
    email_missing false
    validate_email(email)
    #perform rest of subscription logic
  end
{'fraction_non_alphanumeric': 0.05235294117647059, 'fraction_numerical': 0.0, 'mean_word_length': 4.364353312302839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6283425', 'n_tokens_mistral': 903, 'n_tokens_neox': 873, 'n_words': 434}