Sha256: f33d966214c132131d903ee0e5a3f5dac613bab0e94d6979bce27f3e20b0109c

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

[gem]: https://rubygems.org/gems/dry-logic
[travis]: https://travis-ci.org/dryrb/dry-logic
[gemnasium]: https://gemnasium.com/dryrb/dry-logic
[codeclimate]: https://codeclimate.com/github/dryrb/dry-logic
[coveralls]: https://coveralls.io/r/dryrb/dry-logic
[inchpages]: http://inch-ci.org/github/dryrb/dry-logic

# dry-logic [![Join the chat at https://gitter.im/dryrb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dryrb/chat)

[![Gem Version](https://badge.fury.io/rb/dry-logic.svg)][gem]
[![Build Status](https://travis-ci.org/dryrb/dry-logic.svg?branch=master)][travis]
[![Dependency Status](https://gemnasium.com/dryrb/dry-logic.svg)][gemnasium]
[![Code Climate](https://codeclimate.com/github/dryrb/dry-logic/badges/gpa.svg)][codeclimate]
[![Test Coverage](https://codeclimate.com/github/dryrb/dry-logic/badges/coverage.svg)][codeclimate]
[![Inline docs](http://inch-ci.org/github/dryrb/dry-logic.svg?branch=master)][inchpages]

Predicate logic and rule composition used by:

* [dry-data](https://github.com/dryrb/dry-data) for constrained types
* [dry-validation](https://github.com/dryrb/dry-validation) for composing validation rules
* your project...?

## Synopsis

``` ruby
require 'dry/logic'
require 'dry/logic/predicates'

include Dry::Logic

user_present = Rule::Key.new(Predicates[:key?], name: :user)

has_min_age = Rule::Key.new(
  Predicates[:key?]) & Rule::Value.new(:age, Predicates[:gt?].curry(18),
  name: :age
)

user_rule = user_present & has_min_age

user_rule.(user: { age: 19 })
# #<Dry::Logic::Result::Value success?=true input=19 rule=#<Dry::Logic::Rule::Value name=:age predicate=#<Dry::Logic::Predicate id=:gt?>>>

user_rule.(user: { age: 18 })
# #<Dry::Logic::Result::Value success?=false input=18 rule=#<Dry::Logic::Rule::Value name=:age predicate=#<Dry::Logic::Predicate id=:gt?>>>
```

## License

See `LICENSE` file.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-logic-0.2.0 README.md