Class: Sfcc::Cim::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/sfcc/instance.rb,
ext/sfcc/cim_instance.c

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/sfcc/instance.rb', line 45

def method_missing name, *args
  if args.empty?
    begin
      self.property name
    rescue Sfcc::Cim::ErrorNoSuchProperty
      self.object_path.invoke name
    end
  else
    self.object_path.invoke name, *args
  end
end

Class Method Details

.newObject

call-seq

new()

Creates an instance from in object_path


342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'ext/sfcc/cim_instance.c', line 342

static VALUE new(int argc, VALUE *argv)
{
  CIMCStatus status;
  CIMCInstance *ptr;
  rb_sfcc_object_path *rso;
  VALUE object_path;
  VALUE client = Qnil;

  rb_scan_args(argc, argv, "11", &object_path, &client);
  
  Data_Get_Struct(object_path, rb_sfcc_object_path, rso);
  ptr = cimcEnv->ft->newInstance(cimcEnv, rso->op, &status);
  if (!status.rc)
    return Sfcc_wrap_cim_instance(ptr, client);
  sfcc_rb_raise_if_error(status, "Can't create instance");
  return Qnil;
}

Instance Method Details

#classnameObject


8
9
10
# File 'lib/sfcc/instance.rb', line 8

def classname
  self.object_path.classname
end

#clientClient

returns the client associated with the instance


368
369
370
371
372
373
374
# File 'ext/sfcc/cim_instance.c', line 368

static VALUE client(VALUE self)
{
  rb_sfcc_instance *rsi;

  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  return rsi->client;
}

#do(|name, value|) ⇒ Object

end

enumerates properties yielding the property name and its value


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'ext/sfcc/cim_instance.c', line 53

static VALUE each_property(VALUE self)
{
  CIMCInstance *ptr;
  CIMCStatus status;
  int k=0;
  int num_props=0;
  CIMCString *property_name = NULL;
  CIMCData data;
  rb_sfcc_instance *rsi;
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;

  num_props = ptr->ft->getPropertyCount(ptr, &status);
  if (!status.rc) {
    for (; k < num_props; ++k) {
      data = ptr->ft->getPropertyAt(ptr, k, &property_name, &status);
      if (!status.rc) {
        rb_yield_values(2, (property_name ? rb_str_intern(rb_str_new2(property_name->ft->getCharPtr(property_name, NULL))) : Qnil), sfcc_cimdata_to_value(&data, rsi->client));
      }
      else {
        sfcc_rb_raise_if_error(status, "Can't retrieve property #%d", k);
      }
      if (property_name) property_name->ft->release(property_name);
    }
  }
  else {
    sfcc_rb_raise_if_error(status, "Can't retrieve property count");
  }
  return Qnil;
}

#each_property_qualifier(property_name) ⇒ Object

end

enumerates properties yielding the property qualifier name and its value


288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'ext/sfcc/cim_instance.c', line 288

static VALUE each_property_qualifier(VALUE self, VALUE property_name)
{
  CIMCInstance *ptr;
  CIMCStatus status;
  int k=0;
  int num_props=0;
  rb_sfcc_instance *rsi;
  CIMCString *property_qualifier_name = NULL;
  CIMCData data;
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;

  num_props = ptr->ft->getPropertyQualifierCount(ptr, to_charptr(property_name), &status);
  if (!status.rc) {
    for (; k < num_props; ++k) {
      data = ptr->ft->getPropertyQualifierAt(ptr, to_charptr(property_name), k, &property_qualifier_name, &status);
      if (!status.rc) {
        rb_yield_values(2, (property_qualifier_name ? rb_str_new2(property_qualifier_name->ft->getCharPtr(property_qualifier_name, NULL)) : Qnil), sfcc_cimdata_to_value(&data, rsi->client));
      }
      else {
        sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier #%d", k);
      }
      if (property_qualifier_name) property_qualifier_name->ft->release(property_qualifier_name);
    }
  }
  else {
    sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier count");
  }
  return Qnil;
}

#do(|name, value|) ⇒ Object

end

enumerates properties yielding the qualifier name and its value


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'ext/sfcc/cim_instance.c', line 207

static VALUE each_qualifier(VALUE self)
{
  CIMCInstance *ptr;
  CIMCStatus status;
  int k=0;
  int num_props=0;
  CIMCString *qualifier_name = NULL;
  CIMCData data;
  rb_sfcc_instance *rsi;
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;

  num_props = ptr->ft->getQualifierCount(ptr, &status);
  if (!status.rc) {
    for (; k < num_props; ++k) {
      data = ptr->ft->getQualifierAt(ptr, k, &qualifier_name, &status);
      if (!status.rc) {
        rb_yield_values(2, (qualifier_name ? rb_str_new2(qualifier_name->ft->getCharPtr(qualifier_name, NULL)) : Qnil), sfcc_cimdata_to_value(&data, rsi->client));
      }
      else {
        sfcc_rb_raise_if_error(status, "Can't retrieve qualifier #%d", k);
      }
      if (qualifier_name) qualifier_name->ft->release(qualifier_name);
    }
  }
  else {
    sfcc_rb_raise_if_error(status, "Can't retrieve qualifier count");
  }
  return Qnil;
}

#object_pathObjectPath

Generates an ObjectPath out of the nameSpace, classname and key propeties of this Instance.


126
127
128
129
130
131
132
133
134
135
# File 'ext/sfcc/cim_instance.c', line 126

static VALUE object_path(VALUE self)
{
  CIMCInstance *ptr;
  CIMCObjectPath *op;
  rb_sfcc_instance *rsi;
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;
  op = ptr->ft->getObjectPath(ptr, NULL);
  return Sfcc_wrap_cim_object_path(op, rsi->client);
}

#propertiesObject

properties => Hash

return a hash with all properties


15
16
17
18
19
# File 'lib/sfcc/instance.rb', line 15

def properties
  ret = {}
  each_property { |key, value| ret[key] = value }
  ret
end

#property(name) ⇒ Cim::Data

Gets a named property value, where name is a Symbol or String


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'ext/sfcc/cim_instance.c', line 27

static VALUE property(VALUE self, VALUE name)
{
  CIMCInstance *ptr;
  CIMCStatus status;
  CIMCData data;
  rb_sfcc_instance *rsi;
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;

  data = ptr->ft->getProperty(ptr, to_charptr(name), &status);
  if ( !status.rc )
    return sfcc_cimdata_to_value(&data, rsi->client);
  sfcc_rb_raise_if_error(status, "Can't retrieve property '%s'", to_charptr(name));
  return Qnil;
}

#property_countObject

Gets the number of properties contained in this Instance


90
91
92
93
94
95
96
97
98
# File 'ext/sfcc/cim_instance.c', line 90

static VALUE property_count(VALUE self)
{
  CIMCInstance *ptr;
  rb_sfcc_instance *rsi;
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;

  return UINT2NUM(ptr->ft->getPropertyCount(ptr, NULL));
}

#property_qualifier(property_name, qualifier_name) ⇒ Object

gets a named property qualifier value


260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'ext/sfcc/cim_instance.c', line 260

static VALUE property_qualifier(VALUE self, VALUE property_name, VALUE qualifier_name)
{
  CIMCInstance *ptr;
  CIMCStatus status;
  CIMCData data;
  rb_sfcc_instance *rsi;
  memset(&status, 0, sizeof(CIMCStatus));
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;
  data = ptr->ft->getPropertyQualifier(ptr, to_charptr(property_name),
                                        to_charptr(qualifier_name), &status);
  if ( !status.rc )
    return sfcc_cimdata_to_value(&data, rsi->client);

  sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier '%s'", to_charptr(qualifier_name));
  return Qnil;
}

#property_qualifier_count(property_name) ⇒ Object

Gets the number of qualifiers contained in this property


325
326
327
328
329
330
331
332
333
# File 'ext/sfcc/cim_instance.c', line 325

static VALUE property_qualifier_count(VALUE self, VALUE property_name)
{
  CIMCInstance *ptr;
  rb_sfcc_instance *rsi;
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;

  return UINT2NUM(ptr->ft->getPropertyQualifierCount(ptr, to_charptr(property_name), NULL));
}

#property_qualifiers(property_name) ⇒ Object

property_qualifiers(property_name) => Hash

return a hash with all qualifiers for property_name


33
34
35
36
37
# File 'lib/sfcc/instance.rb', line 33

def property_qualifiers(property_name)
  ret = {}
  each_property_qualifier(property_name) { |key, value| ret[key] = value }
  ret
end

#qualifier(name) ⇒ Object

gets a named qualifier value


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'ext/sfcc/cim_instance.c', line 179

static VALUE qualifier(VALUE self, VALUE name)
{
  CIMCInstance *ptr;
  CIMCStatus status;
  CIMCData data;
  rb_sfcc_instance *rsi;
  memset(&status, 0, sizeof(CIMCStatus));
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;

  data = ptr->ft->getQualifier(ptr, to_charptr(name), &status);
  if ( !status.rc )
    return sfcc_cimdata_to_value(&data, rsi->client);

  sfcc_rb_raise_if_error(status, "Can't retrieve qualifier '%s'", to_charptr(name));
  return Qnil;
}

#qualifier_countObject

Gets the number of qualifiers in this instance


244
245
246
247
248
249
250
251
252
# File 'ext/sfcc/cim_instance.c', line 244

static VALUE qualifier_count(VALUE self)
{
  CIMCInstance *ptr;
  rb_sfcc_instance *rsi;
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;

  return UINT2NUM(ptr->ft->getQualifierCount(ptr, NULL));
}

#qualifiersObject

qualifiers => Hash

return a hash with all qualifiers


24
25
26
27
28
# File 'lib/sfcc/instance.rb', line 24

def qualifiers
  ret = {}
  each_qualifier { |key, value| ret[key] = value }
  ret
end

#set_property(name, value) ⇒ Object

Adds/replaces a names property


106
107
108
109
110
111
112
113
114
115
116
117
# File 'ext/sfcc/cim_instance.c', line 106

static VALUE set_property(VALUE self, VALUE name, VALUE value)
{
  CIMCInstance *ptr;
  CIMCData data;
  rb_sfcc_instance *rsi;
  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;
  data = sfcc_value_to_cimdata(value);
  ptr->ft->setProperty(ptr, to_charptr(name), &data.value, data.type);

  return value;
}

#set_property_filter(property_list, keys) ⇒ Object

Directs CIMC to ignore any setProperty operations for this instance for any properties not in this list.

property_list If not nil, the members of the array define one or more Property names to be accepted by set_property operations.

keys Array of key property names of this instance. This array must be specified.


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'ext/sfcc/cim_instance.c', line 151

static VALUE set_property_filter(VALUE self, VALUE property_list, VALUE keys)
{
  CIMCStatus status;
  CIMCInstance *ptr;
  char **prop_a;
  char **key_a;
  rb_sfcc_instance *rsi;

  Data_Get_Struct(self, rb_sfcc_instance, rsi);
  ptr = rsi->inst;

  prop_a = sfcc_value_array_to_string_array(property_list);
  key_a = sfcc_value_array_to_string_array(keys);

  status = ptr->ft->setPropertyFilter(ptr, prop_a, key_a);
  free(prop_a);
  free(key_a);

  sfcc_rb_raise_if_error(status, "Can't set property filter");
  return self;
}

#to_sObject

returns the string representation of the object path for this instance


41
42
43
# File 'lib/sfcc/instance.rb', line 41

def to_s
  object_path.to_s
end