Skip to content

Instantly share code, notes, and snippets.

@stravid stravid/example.rb
Created Jun 22, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.