Class: WMI::Base
- Inherits:
-
Object
- Object
- WMI::Base
- Defined in:
- lib/ruby-wmi/base.rb
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
an alias for find(:all).
-
.find(arg = :all, options = {}) ⇒ Object
WMI::Win32ComputerSystem.find(:all) returns an array of Win32ComputerSystem objects.
-
.find_by_wql(query) ⇒ Object
#find_by_wql currently only works when called through #find it may stay like that too.
-
.first(options = {}) ⇒ Object
an alias for find(:first).
-
.last(options = {}) ⇒ Object
an alias for find(:last).
- .set_connection(options = {}) ⇒ Object
- .set_wmi_class_name(name) ⇒ Object
- .subclass_name ⇒ Object
Class Method Details
.all(options = {}) ⇒ Object
an alias for find(:all)
107 108 109 |
# File 'lib/ruby-wmi/base.rb', line 107 def all(={}) find(:all, ) end |
.find(arg = :all, options = {}) ⇒ Object
WMI::Win32ComputerSystem.find(:all)
returns an array of Win32ComputerSystem objects
WMI::Win32ComputerSystem.find(:first)
returns the first Win32ComputerSystem object
WMI::Win32ComputerSystem.find(:last)
returns the last Win32ComputerSystem object
options:
:conditions
Conditions can either be specified as a string, array, or hash representing the WHERE-part of an SQL statement.
The array form is to be used when the condition input is tainted and requires sanitization. The string form can
be used for statements that don't involve tainted data. The hash form works much like the array form, except
only equality and range is possible. Examples:
Win32ComputerSystem.find(:all, :conditions => {:drivetype => 3} ) # Hash
Win32ComputerSystem.find(:all, :conditions => [:drivetype, 3] ) # Array
Win32ComputerSystem.find(:all, :conditions => 'drivetype = 3' ) # String
:host - computername, defaults to localhost
:class - swebm class , defaults to 'root\\cimv2'
:privileges - see WMI::Privilege for a list of privileges
:user - username (domain\\username)
:password - password
87 88 89 90 91 92 93 94 |
# File 'lib/ruby-wmi/base.rb', line 87 def find(arg=:all, ={}) set_connection case arg when :all; find_all() when :first; find_first() when :last; find_last() end end |
.find_by_wql(query) ⇒ Object
#find_by_wql currently only works when called through #find it may stay like that too. I haven't decided.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruby-wmi/base.rb', line 46 def find_by_wql(query) d = connection.ExecQuery(query) begin d.count # needed to check for errors. Weird, but it works. rescue => error case error.to_s when /Invalid class/i ; raise InvalidClass when /Invalid query/i ; raise InvalidQuery end end d.to_a end |
.first(options = {}) ⇒ Object
an alias for find(:first)
102 103 104 |
# File 'lib/ruby-wmi/base.rb', line 102 def first(={}) find(:first, ) end |
.last(options = {}) ⇒ Object
an alias for find(:last)
97 98 99 |
# File 'lib/ruby-wmi/base.rb', line 97 def last(={}) find(:last, ) end |
.set_connection(options = {}) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/ruby-wmi/base.rb', line 111 def set_connection(={}) @host = [:host] @klass = [:class] || 'root\\cimv2' @user,@password = [:user], [:password] @privileges = [:privileges] end |
.set_wmi_class_name(name) ⇒ Object
118 119 120 |
# File 'lib/ruby-wmi/base.rb', line 118 def set_wmi_class_name(name) @subclass_name = name end |
.subclass_name ⇒ Object
122 123 124 |
# File 'lib/ruby-wmi/base.rb', line 122 def subclass_name @subclass_name ||= self.name.split('::').last end |