Module: Tchae::PI

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

Instance Method Summary collapse

Instance Method Details

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



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/tchae/core.rb', line 361

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

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



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/tchae/core.rb', line 377

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

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



346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/tchae/core.rb', line 346

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

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



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/tchae/core.rb', line 324

def create_validated_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_method(methodname, wrapper, &proclmbda)
  when ::Tchae::Handling::RETURN_RESULT_OR_ERROR
    create_result_or_error_method(methodname, wrapper, &proclmbda)
  else # RAISE
    create_valid_or_raise_method(methodname, wrapper, &proclmbda)
  end
end