Module: Gate::Command::ClassMethods
- Defined in:
- lib/gate/command.rb
Instance Method Summary collapse
Instance Method Details
#schema(&block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gate/command.rb', line 25 def schema(&block) if block_given? raise SchemaAlreadyRegistered if @schema @schema = Dry::Validation.Form(&block) @schema.rules.keys.each do |name| define_method(name) do result[name] end end else raise SchemaNotDefined unless @schema @schema end end |
#with(input) ⇒ Object
40 41 42 43 44 |
# File 'lib/gate/command.rb', line 40 def with(input) result = schema.(input) raise InvalidCommand, result. if result.failure? new result.output end |