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

Add Interactor Requirements #113

Closed

Conversation

yjukaku
Copy link

@yjukaku yjukaku commented Jul 19, 2016

This adds a very, very simple contract DSL on top of Interactors. I know that #112 and #82 both exist, however I believe that neither of them have gained traction/have been merged because they are either too complex, try to do too much, or break backwards compatibility.

This PR simply adds the class method context_requires, which can be used like so:

class SendEmail
  include Interactor
  context_requires :email
  # or like this:
  # context_requires :email, :user_id
  # or like this, with strictly typed params
  # context_requires :email, user_id: String
  # context_requires email: String, user_id: Integer, some_options: Hash
  def call
    UserMailer.welcome_email(context.email).deliver
  end  
end

Since this is a developer tool (not for users to see), this raises a new exception, Interactor::RequirementsNotMet if eg. email is nil or not specified when the interactor is called with one of the following messages:

SendEmail.call
# => InteractorRequirements::RequirementsNotMet: Context requires email, but it wasn't specified
SendEmail.call(email: nil)
# => InteractorRequirements::RequirementsNotMet: Context requires email, but it was nil

or with type requirements:

SendEmail.call(email: "[email protected]", user_id: 1.5)
# => InteractorRequirements::RequirementsNotMet: Context requires account_id to be a String, but it was a Float.

Credit to @mingan for the code that this is based on.

Addresses #92 , #109

@yjukaku yjukaku mentioned this pull request Jul 19, 2016
@yjukaku
Copy link
Author

yjukaku commented Jul 20, 2016

It looks like the CI build is failing because of a dependency issue that is also in master, btw 🙊

@yjukaku
Copy link
Author

yjukaku commented Jul 26, 2016

@laserlemon @jonstokes I see that you had a lengthy discussion about a similar proposal, befor eit was spinned off into troupe. Any thoughts on this PR?

@samtgarson
Copy link

Any news or opinions on this? I would love this light handed approach, it keeps the gem as un-opinionated and simple as it currently is, which is a plus in my book.

@mingan
Copy link

mingan commented Sep 5, 2016

In any case, the Travis issue can be traced back to codeclimate-test-reporter and the solution is described in their readme:

gem "simplecov", "~> 0.11.2"

@laserlemon
Copy link
Collaborator

Closing in favor of #123.

@laserlemon laserlemon closed this Mar 22, 2017
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.

4 participants