win32olerot 0.0.1-x86-mswin32 → 0.0.2-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
@@ -109,7 +109,7 @@ public:
109
109
  }
110
110
  }
111
111
 
112
- VALUE isRunning(VALUE aMoniker)
112
+ VALUE isRunning(VALUE aMoniker, VALUE aInvalidMonikersArentRunning)
113
113
  {
114
114
  VALUE result = Qfalse;
115
115
 
@@ -131,10 +131,14 @@ public:
131
131
  hr = MkParseDisplayName(pBindCtx, pBuf, &ignored, &pMoniker);
132
132
  ::SysFreeString(pBuf);
133
133
 
134
- if(FAILED(hr)) {
134
+ if (FAILED(hr))
135
+ {
136
+ if (RTEST(aInvalidMonikersArentRunning))
137
+ return result;
138
+
135
139
  VALUE message = hr.message();
136
140
  rb_raise(eWIN32OLE_RUNTIME_ERROR,
137
- "Failed to parse display name of moniker '%s': %s",
141
+ "Failed to parse display name of moniker '%s': %s",
138
142
  StringValuePtr(aMoniker),
139
143
  StringValuePtr(message));
140
144
  }
@@ -228,11 +232,30 @@ static VALUE rot_allocate(VALUE klass)
228
232
  return Data_Wrap_Struct(klass, rot_mark, rot_free, table);
229
233
  }
230
234
 
231
- static VALUE rot_isRunning(VALUE rot, VALUE v)
235
+ static VALUE rot_isRunning(VALUE rot, VALUE vArray)
232
236
  {
237
+ VALUE moniker = rb_ary_shift(vArray);
238
+ if (NIL_P(moniker))
239
+ {
240
+ rb_raise(rb_eArgError, "Missing required parameter 'moniker_name'");
241
+ }
242
+
243
+ VALUE exceptionsDontError = Qtrue;
244
+
245
+ VALUE options = rb_ary_shift(vArray);
246
+ if (!NIL_P(options))
247
+ {
248
+ VALUE optValue = rb_funcall(options, rb_intern("fetch"),
249
+ 2, ID2SYM(rb_intern("raise_exception")), Qnil);
250
+ if (RTEST(optValue))
251
+ {
252
+ exceptionsDontError = Qfalse;
253
+ }
254
+ }
255
+
233
256
  WIN32OLE_RunningObjectTable* pRot;
234
257
  Data_Get_Struct(rot, WIN32OLE_RunningObjectTable, pRot);
235
- return pRot->isRunning(v);
258
+ return pRot->isRunning(moniker, exceptionsDontError);
236
259
  }
237
260
 
238
261
  static VALUE rot_each_display_name(VALUE rot)
@@ -258,7 +281,7 @@ Init_win32olerot()
258
281
 
259
282
  cWIN32OLE_ROT = rb_define_class_under(cWIN32OLE, "RunningObjectTable", rb_cObject);
260
283
  rb_define_alloc_func(cWIN32OLE_ROT, rot_allocate);
261
- rb_define_method(cWIN32OLE_ROT, "is_running?", RUBY_METHOD_FUNC(rot_isRunning), 1);
284
+ rb_define_method(cWIN32OLE_ROT, "is_running?", RUBY_METHOD_FUNC(rot_isRunning), -2);
262
285
  rb_define_method(cWIN32OLE_ROT, "each_display_name", RUBY_METHOD_FUNC(rot_each_display_name), 0);
263
286
  rb_define_alias(cWIN32OLE_ROT, "each", "each_display_name");
264
287
  }
data/lib/win32olerot.so CHANGED
Binary file
data/tests/tc_basic.rb CHANGED
@@ -24,6 +24,18 @@ class TC_Create < Test::Unit::TestCase
24
24
  assert @rot.is_running?(x)
25
25
  end
26
26
  end
27
-
27
+
28
+ def test_invalid_monikers_arent_running
29
+ assert_nothing_thrown do
30
+ assert !@rot.is_running?("blah_garbage_data_here")
31
+ assert !@rot.is_running?("blah_garbage_data_here", :raise_exception => false)
32
+ end
33
+ end
34
+
35
+ def test_invalid_monikers_exception_with_raise_exception_option
36
+ assert_raises(WIN32OLERuntimeError) { !@rot.is_running?("blah_garbage_data_here", :raise_exception => true) }
37
+ end
38
+
39
+
28
40
  end
29
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32olerot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: x86-mswin32
6
6
  authors:
7
7
  - G Whiteley