Skip to content

Instantly share code, notes, and snippets.

@manojmj92
Last active August 4, 2018 08:10
Show Gist options
  • Save manojmj92/b2da053dcba9c4ec43b211ed00ed2681 to your computer and use it in GitHub Desktop.
Save manojmj92/b2da053dcba9c4ec43b211ed00ed2681 to your computer and use it in GitHub Desktop.
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