collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

Expects and promises #159

Open cabello opened 6 years ago

cabello commented 6 years ago

Hi 👋

I recently found this gem https://github.com/adomokos/light-service and one thing I liked was the fact that you can specify what's expected from the context and what will be set on the context.

class LooksUpTaxPercentageAction
  extend LightService::Action
  expects :order
  promises :tax_percentage

I've been doing delegate calls to mimic the expects functionality, I have nothing for the promises.

Is that something you would welcome a PR for?

natebird commented 6 years ago

I think this would be a worthwhile addition. I've just added comments at the top of the class about what's required input and what is expected output. Defining it might clean up some of the boilerplate code I create like this:

    if context.location.blank? || context.calibration.blank?
      Rails.logger.info 'AddCalibrationLocation [ SKIPPED - MISSING INFO ]'
      return false
    end
dikond commented 6 years ago

Hey, take a look at Hanami::Interactor - it's simpler than collectiveidea's interactor (no Organizaer, callbacks, rollback) but thanks to its API you can clearly see the input and the output :)

gee-forr commented 5 years ago

You could also try this out: https://github.com/michaelherold/interactor-contracts

It takes what light-service does, and quite a bit further.