Class: LibConfig::Array

Inherits:
Aggregate show all
Defined in:
ext/rlibconfig.c

Instance Method Summary collapse

Methods inherited from Aggregate

#[], #delete, #get, #initialize, #size

Methods inherited from BaseSetting

#index, #initialize, #line, #name, #parent, #root?

Constructor Details

This class inherits a constructor from LibConfig::Aggregate

Instance Method Details

#<<(target) ⇒ Object



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'ext/rlibconfig.c', line 425

static VALUE rbConfigAggregate_append(VALUE self, VALUE target)
{
  config_setting_t* setting = NULL;
  if(rb_iv_get(self, "@setting") != Qnil)
    Data_Get_Struct(rb_iv_get(self, "@setting"), config_setting_t, setting);

  Check_Type(target, T_OBJECT);

  VALUE type = rb_iv_get(self, "@type");
  if(rb_obj_class(self) == cConfigArray) {
    if(type != Qnil && type != rb_obj_class(target))
      rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", rb_obj_classname(target), rb_class2name(type));
    if(type == Qnil && rb_ary_includes(aConfigScalars, rb_obj_class(target)) != Qtrue)
      rb_raise(rb_eTypeError, "invalid setting array type %s", rb_obj_classname(target));
  }

  if(rb_ary_includes(aConfigSettings, rb_obj_class(target)) == Qtrue) {
    if(setting)
      rconfig_do_append(setting, target, Qnil);
    rb_ary_push(rb_iv_get(self, "@list"), target);
  } else {
    rb_raise(rb_eTypeError, "wrong argument type %s (expected Config::BaseSetting)", rb_obj_classname(target));
  }
  
  if(rb_obj_class(self) == cConfigArray && type == Qnil)
    rb_iv_set(self, "@type", rb_obj_class(target));
  
  return target;
}

#append(target) ⇒ Object



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'ext/rlibconfig.c', line 425

static VALUE rbConfigAggregate_append(VALUE self, VALUE target)
{
  config_setting_t* setting = NULL;
  if(rb_iv_get(self, "@setting") != Qnil)
    Data_Get_Struct(rb_iv_get(self, "@setting"), config_setting_t, setting);

  Check_Type(target, T_OBJECT);

  VALUE type = rb_iv_get(self, "@type");
  if(rb_obj_class(self) == cConfigArray) {
    if(type != Qnil && type != rb_obj_class(target))
      rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", rb_obj_classname(target), rb_class2name(type));
    if(type == Qnil && rb_ary_includes(aConfigScalars, rb_obj_class(target)) != Qtrue)
      rb_raise(rb_eTypeError, "invalid setting array type %s", rb_obj_classname(target));
  }

  if(rb_ary_includes(aConfigSettings, rb_obj_class(target)) == Qtrue) {
    if(setting)
      rconfig_do_append(setting, target, Qnil);
    rb_ary_push(rb_iv_get(self, "@list"), target);
  } else {
    rb_raise(rb_eTypeError, "wrong argument type %s (expected Config::BaseSetting)", rb_obj_classname(target));
  }
  
  if(rb_obj_class(self) == cConfigArray && type == Qnil)
    rb_iv_set(self, "@type", rb_obj_class(target));
  
  return target;
}