Module: Gate::Command::ClassMethods
- Defined in:
- lib/gate/command.rb
Instance Method Summary collapse
-
#schema(&block) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#with(input) ⇒ Object
rubocop:enable Metrics/MethodLength.
Instance Method Details
#schema(&block) ⇒ Object
rubocop:disable Metrics/MethodLength
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gate/command.rb', line 39 def schema(&block) if block_given? raise SchemaAlreadyRegistered if instance_variable_defined?(:@schema) @schema = Dry::Validation.Params(&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
rubocop:enable Metrics/MethodLength
55 56 57 58 59 |
# File 'lib/gate/command.rb', line 55 def with(input) result = schema.call(input) raise InvalidCommand, result.(full: true) if result.failure? new result.output end |