interactor icon indicating copy to clipboard operation
interactor copied to clipboard

Expects and promises

Open cabello opened this issue 7 years ago • 3 comments

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?

cabello avatar Oct 02 '18 12:10 cabello

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

natebird avatar Oct 02 '18 16:10 natebird

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 :)

dikond avatar Oct 03 '18 21:10 dikond

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

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

gee-forr avatar Aug 04 '19 20:08 gee-forr