Class: LibConfig::Setting

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

Direct Known Subclasses

Bignum, Boolean, Fixnum, Float, String

Instance Method Summary collapse

Methods inherited from BaseSetting

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

Constructor Details

#initialize(*args) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'ext/rlibconfig.c', line 269

static VALUE rbConfigSetting_initialize(int argc, VALUE* argv, VALUE self)
{
  VALUE value, setting;
  rb_scan_args(argc, argv, "11", &value, &setting);

  rb_call_super(1, &setting);

  rconfig_check_setting_type(self, value);
  rb_iv_set(self, "@value", value);

  if(rb_iv_get(self, "@setting") != Qnil) {
    config_setting_t* c_setting = NULL;
    Data_Get_Struct(rb_iv_get(self, "@setting"), config_setting_t, c_setting);
    rb_iv_set(self, "@format", INT2FIX(config_setting_get_format(c_setting)));
  } else {
    rb_iv_set(self, "@format", cConfigFormatDefault);
  }
  
  return self;
}

Instance Method Details

#formatObject



316
317
318
319
320
321
322
323
324
325
# File 'ext/rlibconfig.c', line 316

static VALUE rbConfigSetting_get_format(VALUE self)
{
  if(rb_iv_get(self, "@setting") != Qnil) {
    config_setting_t* setting;
    Data_Get_Struct(rb_iv_get(self, "@setting"), config_setting_t, setting);
    return INT2FIX(config_setting_get_format(setting));
  } else {
    return rb_iv_get(self, "format");
  }
}

#format=(new_format) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'ext/rlibconfig.c', line 327

static VALUE rbConfigSetting_set_format(VALUE self, VALUE new_format)
{
  if(rb_iv_get(self, "@setting") != Qnil) {
    config_setting_t* setting;
    Data_Get_Struct(rb_iv_get(self, "@setting"), config_setting_t, setting);
    if(!config_setting_set_format(setting, FIX2INT(new_format)))
      rb_raise(eSettingFormatError, "invalid setting format %d", FIX2INT(new_format));
  }

  rb_iv_set(self, "@format", new_format);
  
  return new_format;
}

#valueObject



290
291
292
293
294
295
296
297
298
299
# File 'ext/rlibconfig.c', line 290

static VALUE rbConfigSetting_get_value(VALUE self)
{
  if(rb_iv_get(self, "@setting") != Qnil) {
    config_setting_t* setting;
    Data_Get_Struct(rb_iv_get(self, "@setting"), config_setting_t, setting);
    return rconfig_wrap_value(setting);
  } else {
    return rb_iv_get(self, "@value");
  }
}

#value=(new_value) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'ext/rlibconfig.c', line 301

static VALUE rbConfigSetting_set_value(VALUE self, VALUE new_value)
{
  rconfig_check_setting_type(self, new_value);

  if(rb_iv_get(self, "@setting") != Qnil) {
    config_setting_t* setting;
    Data_Get_Struct(rb_iv_get(self, "@setting"), config_setting_t, setting);
    rconfig_update_setting(setting, new_value);
  }

  rb_iv_set(self, "@value", new_value);
  
  return new_value;
}