serradura / u-case

Represent use cases in a simple and powerful way while writing modular, expressive and sequentially logical code.
https://rubygems.org/gems/u-case
MIT License
527 stars 33 forks source link

Refactors #then to allow passing symbols as well #121

Closed tiagofsilva closed 3 years ago

tiagofsilva commented 3 years ago

Implements the enhancement mentioned in #118

Allows #then method to also receive symbols and strings with the name of the methods. Ex:

normalize_params
    .then(:sanitize)
    .then(:validate)
    .then(:persist)

The advantage of having the option to pass symbols/strings as arguments to #then is that it makes it more straighforward for the user to call subsequent methods on the result object chain. Thus the responsibility to convert the symbol into a method object (by using metaprogramming method or an use case alias like apply) is now on the use case class, instead of the client. At the same time, it is still allowed to pass method objects directly, just as procs, as it was allowed previously, so it doesn't break the api. As #| (pipe) is basically #then with some small modifications, then it also allows symbols and strings with this PR.

serradura commented 3 years ago

@tiagofsilva thank you very much for your contribution! If be possible, I would like to talk with you. What is the best channel for us to chat? This is the link to my Telegram account: https://t.me/serradura.