Module: Tchae::PISingleton

Included in:
Module, Object
Defined in:
lib/tchae/core.rb

Instance Method Summary collapse

Instance Method Details

#create_result_or_error_singleton_method(methodname, wrapper = Tchae::NilWrapper, &proc) ⇒ Object



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/tchae/core.rb', line 436

def create_result_or_error_singleton_method(methodname, 
                                            wrapper= Tchae::NilWrapper, 
                                            &proc)
  if block_given?
    tea_methodsymb = "__tea_#{methodname}".to_sym
    define_singleton_method "__tea_#{methodname}", proc
    define_singleton_method(methodname) do |*params, **kwparms|
      Tchae.do_validation_result_or_error(self, wrapper,
                                          tea_methodsymb, proc,
                                          params, kwparms)
    end
  else
    define_singleton_method(methodname) {}
  end                                          
end

#create_return_wrapper_singleton_method(methodname, wrapper = Tchae::NilWrapper, &proc) ⇒ Object



452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/tchae/core.rb', line 452

def create_return_wrapper_singleton_method(methodname,
                                            wrapper = Tchae::NilWrapper, &proc)
  if block_given?
    tea_methodsymb = "__tea_#{methodname}".to_sym
    define_singleton_method "__tea_#{methodname}", proc
    define_singleton_method(methodname) do |*params, **kwparms|
      Tchae.do_validation_return_wrapper(self, wrapper,
                                    tea_methodsymb, proc,
                                    params, kwparms)
    end
  else
    define_singleton_method(methodname) {}
  end
end

#create_valid_or_raise_singleton_method(methodname, wrapper = Tchae::NilWrapper, &proc) ⇒ Object



421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/tchae/core.rb', line 421

def create_valid_or_raise_singleton_method(methodname,
                                           wrapper = Tchae::NilWrapper, &proc)
  if block_given?
    tea_methodsymb = "__tea_#{methodname}".to_sym
    define_singleton_method "__tea_#{methodname}", proc
    define_singleton_method(methodname) do |*params, **kwparms|
      Tchae.do_validation_raise(self, wrapper,
                                   tea_methodsymb, proc,
                                   params, kwparms)
    end
  else
    define_singleton_method(methodname) {}
  end
end

#create_validated_singleton_method(methodname, wrapper = Tchae::NilWrapper, lambda: nil, &proc) ⇒ Object



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/tchae/core.rb', line 398

def create_validated_singleton_method(methodname,
                                      wrapper = Tchae::NilWrapper,
                                      lambda: nil,
                                      &proc)

  proclmbda = if lambda.nil?
                proc
              else
                raise ArgumentError, 'Please provide a block or the :lambda parameter but not both' if block_given?

                lambda
              end

  case wrapper.handling 
  when ::Tchae::Handling::RETURN_WRAPPER
    create_return_wrapper_singleton_method(methodname, wrapper, &proclmbda)
  when ::Tchae::Handling::RETURN_RESULT_OR_ERROR
    create_result_or_error_singleton_method(methodname, wrapper, &proclmbda)
  else # RAISE
    create_valid_or_raise_singleton_method(methodname, wrapper, &proclmbda)
  end
end