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 #1

Closed
wants to merge 27 commits into from

Conversation

taylorthurlow
Copy link
Owner

This is a port of the PR here: collectiveidea#135

hedgesky and others added 27 commits July 12, 2020 15:14
This also adds a little bit of organization to the .rubocop.yml
configuration file. I also moved some specific rule exceptions out of
.rubocop.yml into the code itself.
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.
@taylorthurlow
Copy link
Owner Author

Wrong source branch...

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