Module: TTY::Option::ParamPermitted
- Defined in:
- lib/tty/option/param_permitted.rb
Class Method Summary collapse
-
.[] ⇒ Object
Convert parameter value to another type.
-
.call(param, value) ⇒ Object
Convert parameter value to another type.
Class Method Details
.[] ⇒ Object
Convert parameter value to another type
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tty/option/param_permitted.rb', line 30 def call(param, value) return Result.success(value) if !param.permit? || value.nil? unpermitted = Array(value) - Array(param.permit) if unpermitted.empty? Result.success(value) else Result.failure(unpermitted.map do |val| UnpermittedArgument.new(param, val) end) end end |
.call(param, value) ⇒ Object
Convert parameter value to another type
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tty/option/param_permitted.rb', line 15 def call(param, value) return Result.success(value) if !param.permit? || value.nil? unpermitted = Array(value) - Array(param.permit) if unpermitted.empty? Result.success(value) else Result.failure(unpermitted.map do |val| UnpermittedArgument.new(param, val) end) end end |