summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2019-12-20 21:58:25 -0800
committerTim Smith <tsmith84@gmail.com>2019-12-20 21:59:03 -0800
commit60261bd2993c5625bc095ea52a9c91651d745617 (patch)
tree4cc11225724e1f6fccf160e3d21ffe4e30a68c3f /lib
parentc812ebaa631ad00d9d7e136fbe545e18d2589ef8 (diff)
downloadwmi-lite-60261bd2993c5625bc095ea52a9c91651d745617.tar.gz
Apply Chefstyle
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/wmi-lite.rb3
-rw-r--r--lib/wmi-lite/wmi.rb16
-rw-r--r--lib/wmi-lite/wmi_exception.rb5
3 files changed, 11 insertions, 13 deletions
diff --git a/lib/wmi-lite.rb b/lib/wmi-lite.rb
index 8c94317..44375b3 100644
--- a/lib/wmi-lite.rb
+++ b/lib/wmi-lite.rb
@@ -16,5 +16,4 @@
# limitations under the License.
#
-require 'wmi-lite/wmi'
-
+require "wmi-lite/wmi"
diff --git a/lib/wmi-lite/wmi.rb b/lib/wmi-lite/wmi.rb
index 9f7c07c..2f54825 100644
--- a/lib/wmi-lite/wmi.rb
+++ b/lib/wmi-lite/wmi.rb
@@ -16,14 +16,14 @@
# limitations under the License.
#
-require 'win32ole' if RUBY_PLATFORM =~ /mswin|mingw32|windows/
-require 'wmi-lite/wmi_instance'
-require 'wmi-lite/wmi_exception'
+require "win32ole" if RUBY_PLATFORM =~ /mswin|mingw32|windows/
+require "wmi-lite/wmi_instance"
+require "wmi-lite/wmi_exception"
module WmiLite
class Wmi
def initialize(namespace = nil)
- @namespace = namespace.nil? ? 'root/cimv2' : namespace
+ @namespace = namespace.nil? ? "root/cimv2" : namespace
@connection = nil
end
@@ -38,7 +38,7 @@ module WmiLite
def first_of(wmi_class)
query_result = start_query("select * from #{wmi_class}", wmi_class)
first_result = nil
- query_result.each do | record |
+ query_result.each do |record|
first_result = record
break
end
@@ -52,7 +52,7 @@ module WmiLite
result_set = []
- results.each do | result |
+ results.each do |result|
result_set.push(wmi_result_to_snapshot(result))
end
@@ -80,10 +80,10 @@ module WmiLite
def connect_to_namespace
if @connection.nil?
- namespace = @namespace.nil? ? 'root/cimv2' : @namespace
+ namespace = @namespace.nil? ? "root/cimv2" : @namespace
locator = WIN32OLE.new("WbemScripting.SWbemLocator")
begin
- @connection = locator.ConnectServer('.', namespace)
+ @connection = locator.ConnectServer(".", namespace)
rescue WIN32OLERuntimeError => native_exception
raise WmiException.new(native_exception, :ConnectServer, @namespace)
end
diff --git a/lib/wmi-lite/wmi_exception.rb b/lib/wmi-lite/wmi_exception.rb
index 4ea3a41..7d97011 100644
--- a/lib/wmi-lite/wmi_exception.rb
+++ b/lib/wmi-lite/wmi_exception.rb
@@ -17,7 +17,7 @@
#
module WmiLite
- class WmiException < Exception
+ class WmiException < RuntimeError
def initialize(exception, wmi_method_context, namespace, query = nil, class_name = nil)
error_message = exception.message
error_code = translate_error_code(error_message)
@@ -40,7 +40,7 @@ module WmiLite
# Parse the error to get the error status code
error_code_match = error_message.match(/[^\:]+\:\s*([0-9A-Fa-f]{1,8}).*/)
error_code = error_code_match.captures.first if error_code_match
- error_code ? error_code : ''
+ error_code ? error_code : ""
end
def translate_wmi_connect_error_message(native_message, error_code, namespace)
@@ -74,4 +74,3 @@ module WmiLite
end
end
end
-