Module: ReservedNames::Win32::API::Net::StructHelpers

Included in:
USER_INFO_3, USE_INFO_2
Defined in:
lib/chef/win32/api/net.rb

Instance Method Summary collapse

Instance Method Details

#as_rubyObject



86
87
88
89
90
91
# File 'lib/chef/win32/api/net.rb', line 86

def as_ruby
  members.inject({}) do |memo, key|
    memo[key] = get(key)
    memo
  end
end

#get(key) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/chef/win32/api/net.rb', line 69

def get(key)
  if respond_to? key
    send(key)
  else
    val = self[key]
    if val.is_a? FFI::Pointer
      if val.null?
        nil
      else
        val.read_wstring
      end
    else
      val
    end
  end
end

#set(key, val) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/chef/win32/api/net.rb', line 55

def set(key, val)
  val = if val.is_a? String
          encoded = if val.encoding == Encoding::UTF_16LE
                      val
                    else
                      val.to_wstring
                    end
          FFI::MemoryPointer.from_string(encoded)
        else
          val
        end
  self[key] = val
end