I''ve been working on a library called ruby-wmi, that is basically just an abstraction layer around wmi. I''m a windows sys admin, and I use wmi scripts a lot at work. My code looks like this: disks = WMI::Win32_LogicalDisk.find(:all, :conditions => {:drivetype => 5}) It''s supposed to mimic the active_record interface, and it works pretty well. My next thought was to do something like this: disks = Win32::LogicalDisk.find(:all, :conditions => {:drivetype => 5}) Which I liked a lot, but then I realized that I might be stepping on a namespace that was already in use. That''s why I''m posting here. Should I not do this? Is it a bad idea? Thanks, Gordon
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Gordon Thiesfeld > Sent: Monday, July 30, 2007 3:33 PM > To: win32utils-devel at rubyforge.org > Subject: [Win32utils-devel] Win32 namespace > > > I''ve been working on a library called ruby-wmi, that is > basically just an abstraction layer around wmi. I''m a > windows sys admin, and I use wmi scripts a lot at work. > > My code looks like this: > > disks = WMI::Win32_LogicalDisk.find(:all, :conditions => > {:drivetype => 5}) > > It''s supposed to mimic the active_record interface, and it > works pretty well.Hey, I like that.> My next thought was to do something like this: > > disks = Win32::LogicalDisk.find(:all, :conditions => > {:drivetype => 5}) > > Which I liked a lot, but then I realized that I might be stepping on a > namespace that was already in use. That''s why I''m posting here. > Should I not do this? Is it a bad idea?How about this: Win32::WMI::LogicalDisk.find(:all, :conditions => {:drivetype => 5}) And, if you ''include Win32'', it boils down to: WMI::LogicalDisk.find(:all, :conditions => {:drivetype => 5}) I think this approach makes sense, i.e. WMI is part of Win32, and LogicalDisk is part of WMI. Mind you, I certainly don''t own the Win32 namespace so you can do as you wish, but I think this is the best approach, as it puts your code effectively under the "Win32::WMI" namespace, which should eliminate any potential namespace conflicts. What do you think? Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.
> Hey, I like that.Thanks. All of my code is in svn on rubyforge if you''re interested. http://rubyforge.org/projects/ruby-wmi/> I think this approach makes sense, i.e. WMI is part of Win32, and > LogicalDisk is part of WMI. > > Mind you, I certainly don''t own the Win32 namespace so you can do as you > wish, but I think this is the best approach, as it puts your code > effectively under the "Win32::WMI" namespace, which should eliminate any > potential namespace conflicts. > > What do you think?I think this is a good idea, but it won''t work the way I''ve written it. I''m using const_missing to create WMI classes as needed. Win32_LogicalDisk is a WMI class, and it doesn''t exist in ruby until you invoke #find on it. It would have to be: Win32::WMI::Win32_LogicalDisk And that doesn''t look right to me. So, I think I''ll stick with WMI::class_name. It''s only a few extra bytes, after all. Thanks for your time, Gordon
On 7/30/07, Gordon Thiesfeld <gthiesfeld at gmail.com> wrote:> > Hey, I like that. > > Thanks. All of my code is in svn on rubyforge if you''re interested. > > http://rubyforge.org/projects/ruby-wmi/ > > > I think this approach makes sense, i.e. WMI is part of Win32, and > > LogicalDisk is part of WMI. > > > > Mind you, I certainly don''t own the Win32 namespace so you can do as you > > wish, but I think this is the best approach, as it puts your code > > effectively under the "Win32::WMI" namespace, which should eliminate any > > potential namespace conflicts. > > > > What do you think? > > I think this is a good idea, but it won''t work the way I''ve written > it. I''m using const_missing to create WMI classes as needed. > Win32_LogicalDisk is a WMI class, and it doesn''t exist in ruby until > you invoke #find on it. It would have to be: > > Win32::WMI::Win32_LogicalDiskI would think you could recreate the class on the fly or something. I''ll take a look at what you''ve got checked into SCM later this week if I get the chance. BTW, any ideas for a release date? Regards, Dan
On 9/4/07, Daniel Berger <djberg96 at gmail.com> wrote:> I would think you could recreate the class on the fly or something. > I''ll take a look at what you''ve got checked into SCM later this week > if I get the chance. >Thanks.> BTW, any ideas for a release date?I could probably try to release it later this week. I''m still toying with just making this a subclass of ActiveRecord. I''m already just cutting and pasting methods from there, so it seems like the smart thing to do. But, there are a lot of methods I''ll never need or want (save, create, etc.), so I''m thinking I may just use undef_method to get rid of them. Thanks again, Gordon