Skip to content

Conversation

@fnordfish
Copy link

@fnordfish fnordfish commented Aug 28, 2019

This allows to have more control on how the context works. For example which attributes are required, it's default values or validation.

Here's a short sample for illustration:

class MyInteractor
  include Interactor

  self.context_class = Class.new do
    include Context::Mixin

    attr_reader :foo
    attr_accessor :my_export

    def initialize(foo: nil)
      @foo = foo
    end
  end

  def call
    if context.foo
      context.my_export = "Got: " + context.foo.to_s
    else
      context.fail!(my_export: "Error")
    end
  end
end

puts MyInteractor.call(foo: "Hi").my_export # "Got: Hi"
puts MyInteractor.call.my_export # "Error"
MyInteractor.call(unexpected: "information") # ArgumentError (unknown keyword: unexpected)

This PR probably lacks quite some documentation etc. I just wanted to get your input if this is something you'd consider. (Obviously I'm happy to put more work into this if you do)

@fnordfish fnordfish changed the base branch from master to v4 September 2, 2019 16:07
@fnordfish fnordfish changed the base branch from v4 to master September 2, 2019 16:10
@fnordfish
Copy link
Author

Closing in favor of the v4 version in #174

@fnordfish fnordfish closed this Sep 2, 2019
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.

1 participant