Module: Puppet::Util::Windows::COM::Interface

Defined in:
lib/puppet/util/windows/com.rb

Overview

code modified from Unknownr project github.com/rpeev/Unknownr licensed under MIT

Class Method Summary collapse

Class Method Details

.[](*args) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/puppet/util/windows/com.rb', line 69

def self.[](*args)
  spec, iid, *ifaces = args.reverse

  spec.each { |_name, signature| signature[0].unshift(:pointer) }

  Class.new(FFI::Struct) do
    const_set(:IID, iid)

    vtable = Class.new(FFI::Struct) do
      vtable_hash = (ifaces.map { |iface| iface::VTBL::SPEC.to_a } << spec.to_a).flatten(1).to_h
      const_set(:SPEC, vtable_hash)

      layout(
        *self::SPEC.map { |name, signature| [name, callback(*signature)] }.flatten
      )
    end

    const_set(:VTBL, vtable)

    layout \
      :lpVtbl, :pointer
  end
end