module Tchae::PISingleton

Public Instance Methods

create_result_or_error_singleton_method(methodname, wrapper= Tchae::NilWrapper, &proc) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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