Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow developers to define #call with arguments for convenience #2

Open
wants to merge 4 commits into
base: modernize
Choose a base branch
from

Conversation

taylorthurlow
Copy link
Owner

Port of collectiveidea#135.

Required because of how outdated the upstream v4 branch is, this is basically the same PR but rebased onto the updated v4 branch.

If the "call" instance method accepts arguments, those arguments will be
automatically assigned from the provided context, matching on name. This
works for both positional and keyword arguments. If an argument is
specified but no matching value is provided in the context, an
ArgumentError is raised.
This also improves performance of the Interactor#arguments_for_call
method by not duplicating the table of data held internally by the
context. As a happy side effect, this adds the
Interactor::Context#include? method which may be helpful for developers.
…by not interacting directly with OpenStruct#modifiable.
There were edge cases that weren't yet covered by the specs that would
fail for combinations of positional and keyword arguments depending on
what's available in the context. For example:

    class MyInteractor
      include Interactor

      def call(a, b: "bears")
        context.output = [a, b]
      end
    end

    MyInteractor.call(b: "beets").output # => [{ b: "beets" }, "bears"]

Plus, this simplifies the interface by giving the developer one choice
rather than multiple competing choices that achieve the same thing.
@corytheboyd-cirrusmd
Copy link

Is this dead? This is by far my biggest issue with the library, and some sort of interface definition would greatly help our team use interactors more cleanly and safely.

@taylorthurlow
Copy link
Owner Author

taylorthurlow commented Jun 28, 2021

@corytheboyd-cirrusmd I stopped working on this PR and the main "modernize" PR for interactor because there is just zero communication from the maintainers. 😞

I have since forked interactor and changed some things, mostly around restricting interactor inputs and outputs to predefined variables. It's not a drop-in replacement though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants