Created
June 22, 2016 06:31
-
-
Save stravid/a88bbdbf0a1043b24eeb065a957d9776 to your computer and use it in GitHub Desktop.
This file contains 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 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