Class: LibConfig::Group

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

#append(name, target) ⇒ Object



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'ext/rlibconfig.c', line 455

static VALUE rbConfigGroup_append(VALUE self, VALUE name, VALUE target)
{
  Check_Type(name, T_STRING);
  Check_Type(target, T_OBJECT);
  
  config_setting_t* setting = NULL;
  if(rb_iv_get(self, "@setting") != Qnil)
    Data_Get_Struct(rb_iv_get(self, "@setting"), config_setting_t, setting);
  
  if(rb_ary_includes(aConfigSettings, rb_obj_class(target)) == Qtrue) {
    if(rb_reg_match(rSettingNameRegexp, name) == Qnil)
      rb_raise(eSettingNameError, "setting name `%s' contains invalid characters", RSTRING_PTR(name));
    if(setting) {
      if(!rconfig_do_append(setting, target, name))
        rb_raise(eSettingNameError, "setting `%s' already exists", RSTRING_PTR(name));
    } else if(rb_hash_aref(rb_iv_get(self, "@hash"), name) != Qnil) {
      rb_raise(eSettingNameError, "setting `%s' already exists", RSTRING_PTR(name));
    }
    rb_ary_push(rb_iv_get(self, "@list"), target);
    rb_hash_aset(rb_iv_get(self, "@hash"), name, target);
  } else {
    rb_raise(rb_eTypeError, "wrong argument type %s (expected Config::BaseSetting)", rb_obj_classname(target));
  }
  
  return target;
}