Module: Tchae
- Defined in:
- lib/tchae/core.rb,
lib/tchae/core.rb,
lib/tchae/version.rb
Defined Under Namespace
Modules: Handling, PI, PISingleton Classes: ArgumentTypeError, ArgumentTypeException, ArgumentValueError, ArgumentValueException, Arguments, Error, KeywordArgs, MethodValidator, PositionalArgs, Result, ResultWrapper, ReturnTypeError, ReturnTypeException, Validator, Validator1
Constant Summary collapse
- NilWrapper =
MethodValidator.new.freeze
- VERSION =
'0.0.2'.freeze
Class Method Summary collapse
-
.do_validation_raise(obj, wrapper, tea_methodsymb, proclmbda, params, kwparms) ⇒ Object
wrap method with validation, and on invalid, exit by raising exception.
-
.do_validation_result_or_error(obj, wrapper, tea_methodsymb, proclmbda, params, kwparms) ⇒ Object
wrap method with validation, and on invalid, exit with control flow and retun a error object on success return the valid result.
-
.do_validation_return_wrapper(obj, wrapper, tea_methodsymb, proclmbda, params, kwparms) ⇒ Object
wrap method with validation, and on invalid, exit with control flow and retun a wrapped error object on success return a wrapped return object.
- .Wrapper(handling = ::Tchae::Handling::RAISE) ⇒ Object
Class Method Details
.do_validation_raise(obj, wrapper, tea_methodsymb, proclmbda, params, kwparms) ⇒ Object
wrap method with validation, and on invalid,
exit by raising exception
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/tchae/core.rb', line 74 def self.do_validation_raise(obj, wrapper, tea_methodsymb, proclmbda, params, kwparms) wrapper.args.positional.valid_or_raise_exception(params) wrapper.args.keyword.valid_or_raise_exception(kwparms) unchecked_result = if proclmbda.arity.zero? obj.__send__(tea_methodsymb) elsif kwparms.empty? obj.__send__(tea_methodsymb, *params) elsif params.empty? obj.__send__(tea_methodsymb, **kwparms) else obj.__send__(tea_methodsymb, *params, **kwparms) end wrapper.result.valid_or_raise_exception unchecked_result end |
.do_validation_result_or_error(obj, wrapper, tea_methodsymb, proclmbda, params, kwparms) ⇒ Object
wrap method with validation, and on invalid,
exit with control flow and retun a error object
on success return the valid result
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tchae/core.rb', line 45 def self.do_validation_result_or_error(obj, wrapper, tea_methodsymb, proclmbda, params, kwparms) unless params.empty? if (err = wrapper.args.positional.valid_or_return_error(params)) return err end end unless kwparms.empty? if (err = wrapper.args.keyword.valid_or_return_error(kwparms)) return err end end unchecked_result = if proclmbda.arity.zero? obj.__send__(tea_methodsymb) elsif kwparms.empty? obj.__send__(tea_methodsymb, *params) elsif params.empty? obj.__send__(tea_methodsymb, **kwparms) else obj.__send__(tea_methodsymb, *params, **kwparms) end wrapper.result.valid_or_return_error unchecked_result end |
.do_validation_return_wrapper(obj, wrapper, tea_methodsymb, proclmbda, params, kwparms) ⇒ Object
wrap method with validation, and on invalid,
exit with control flow and retun a wrapped error object
on success return a wrapped return object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tchae/core.rb', line 16 def self.do_validation_return_wrapper(obj, wrapper, tea_methodsymb, proclmbda, params, kwparms) unless params.empty? if (err = wrapper.args.positional.valid_or_return_error(params)) return Return(nil, err) end end unless kwparms.empty? if (err = wrapper.args.keyword.valid_or_return_error(kwparms)) return Return(nil, err) end end unchecked_result = if proclmbda.arity.zero? obj.__send__(tea_methodsymb) elsif kwparms.empty? obj.__send__(tea_methodsymb, *params) elsif params.empty? obj.__send__(tea_methodsymb, **kwparms) else obj.__send__(tea_methodsymb, *params, **kwparms) end wrapper.result.return_wrapper unchecked_result end |