Last active
August 4, 2018 08:10
-
-
Save manojmj92/b2da053dcba9c4ec43b211ed00ed2681 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module InteractorValidations | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def requires(*attributes) | |
before do | |
attributes.each do |attribute| | |
raise ArgumentError.new("Required attribute #{attribute} is missing") if context.public_send(attribute).nil? | |
end | |
end | |
end | |
end | |
end | |
class MyInteractor | |
include Interactor | |
include InteractorValidations | |
requires :email, :name | |
# or | |
# requires :email | |
# requires :name | |
def call | |
# ... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment