Class: Overture::Interactor
- Inherits:
-
Object
- Object
- Overture::Interactor
- Includes:
- Interactor
- Defined in:
- lib/overture/interactor.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.required(*input) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/overture/interactor.rb', line 11 def required(*input) before do opts = input.last.is_a?(Hash) ? input.pop : {} allow_empty = opts[:allow_empty] input.each do |attr| value = context.public_send(attr) empty = value.respond_to?(:empty?) ? value.empty? : false valid = !value.nil? && (allow_empty ? true : !empty) fail!("#{attr} is required") unless valid end end end |
Instance Method Details
#fail!(message) ⇒ Object
26 27 28 |
# File 'lib/overture/interactor.rb', line 26 def fail!() context.fail!(error: ) end |