Skip to content

Instantly share code, notes, and snippets.

@stravid
Created June 22, 2016 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stravid/a88bbdbf0a1043b24eeb065a957d9776 to your computer and use it in GitHub Desktop.
Save stravid/a88bbdbf0a1043b24eeb065a957d9776 to your computer and use it in GitHub Desktop.
module BaseCommand
module ClassMethods
def schema(&block)
@schema = Dry::Validation.Form(&block)
end
def build(data)
result = schema.call(data)
if result.success?
new(result.output)
else
result.errors
end
end
end
def self.included(base)
base.extend(ClassMethods)
end
attr_reader :data
def initialize(data)
@data = data
end
end
class CreateNoteCommand
include BaseCommand
schema do
key(:author_name).required
key(:text).required
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment