https://github.com/davydovanton/hanami-interactor-matcher
This repository is no longer maintain: Simple dry-matcher for hanami interactor
https://github.com/davydovanton/hanami-interactor-matcher
Last synced: 3 months ago
JSON representation
This repository is no longer maintain: Simple dry-matcher for hanami interactor
- Host: GitHub
- URL: https://github.com/davydovanton/hanami-interactor-matcher
- Owner: davydovanton
- License: mit
- Created: 2017-11-16T15:37:22.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-22T18:00:35.000Z (almost 6 years ago)
- Last Synced: 2025-01-21T22:08:53.981Z (5 months ago)
- Language: Ruby
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Hanami::Interactor::Matcher
**This repository is no longer maintain**
Simple dry-matcher class for working with hanami interactor results
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'hanami-interactor-matcher'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install hanami-interactor-matcher
## Usage
For exampe you have simple interactor class:```ruby
class Operation
include Hanami::Interactor
expose :valuedef call(condition: true)
if condition
@value = 'hello'
else
@value = 'error'
fail!
end
end
end
```### Matcher mixin
You can use special mixin `Hanami::Interactor::Matcher::Mixin` which provide `#matcher` method.
It will be useful in actions:```ruby
module Action
class Index
include Hanami::Interactor::Matcher::Mixindef initialize(operation: Operation.new)
@operation = operation
enddef call(params)
result = @operation.call(params)match(result) do |m|
m.success { |v| "Yay: #{v}" }
m.failure { |v| "Boo: #{v}" }
end
end
end
endaction = Action::Index.new
action.call(condition: true) # => 'Yay: hello'
action.call(condition: false) # => 'Boo: error'
```### Call injection
We use simple monkey patching for updating `#call` method:```ruby
Operation.new.call(condition: true) do |m|
m.success { |v| puts "Yay: #{v}" }
m.failure { |v| puts "Boo: #{v}" }
end
# => 'Yay: hello'Operation.new.call(condition: false) do |m|
m.success { |v| puts "Yay: #{v}" }
m.failure { |v| puts "Boo: #{v}" }
end
# => 'Boo: error'
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/davydovanton/hanami-interactor-matcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Hanami::Interactor::Matcher project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/davydovanton/hanami-interactor-matcher/blob/master/CODE_OF_CONDUCT.md).