Class: P2::Base

Inherits:
Object
  • Object
show all
Includes:
P2, WIN32OLE::VARIANT
Defined in:
lib/p2ruby/base.rb

Overview

This is P2 Base class that defines common functionality. All Ruby P2 classes serve as transparent proxy for OLE objects in P2ClientGate library.

Constant Summary

Constants included from WIN32OLE::VARIANT

WIN32OLE::VARIANT::VT_ARRAY, WIN32OLE::VARIANT::VT_BOOL, WIN32OLE::VARIANT::VT_BSTR, WIN32OLE::VARIANT::VT_BYREF, WIN32OLE::VARIANT::VT_CY, WIN32OLE::VARIANT::VT_DATE, WIN32OLE::VARIANT::VT_DISPATCH, WIN32OLE::VARIANT::VT_EMPTY, WIN32OLE::VARIANT::VT_ERROR, WIN32OLE::VARIANT::VT_I1, WIN32OLE::VARIANT::VT_I2, WIN32OLE::VARIANT::VT_I4, WIN32OLE::VARIANT::VT_I8, WIN32OLE::VARIANT::VT_INT, WIN32OLE::VARIANT::VT_NULL, WIN32OLE::VARIANT::VT_PTR, WIN32OLE::VARIANT::VT_R4, WIN32OLE::VARIANT::VT_R8, WIN32OLE::VARIANT::VT_UI1, WIN32OLE::VARIANT::VT_UI2, WIN32OLE::VARIANT::VT_UI4, WIN32OLE::VARIANT::VT_UI8, WIN32OLE::VARIANT::VT_UINT, WIN32OLE::VARIANT::VT_UNKNOWN, WIN32OLE::VARIANT::VT_USERDEFINED, WIN32OLE::VARIANT::VT_VARIANT

Constants included from P2

VERSION, VERSION_FILE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:

  • _self (P2::Base)

    the object that the method was called on



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/p2ruby/base.rb', line 12

def initialize opts = {}
  @opts = opts.dup

  # OLE object may be provided directly (Message)
  @ole = @opts[:ole]
  @ole ||= WIN32OLE.new clsid # (@opts[:lib] || Library.default).find name

  # Yields self to given block before setting properties (for initialization, etc...)
  yield self if block_given?

  @opts.each do |key, val|
    # OLE object set properties may be given as options
    setter = "#{key.to_s.camel_case}="
    send(setter, val) if respond_to? setter

    # OLE object NAMED properties may be given as options (Message#Field)
    prop = key.to_s.camel_case
    if respond_to?(prop) && val.is_a?(Hash)
      val.each do |k, v|
        property = send prop
        property[k.to_s] = v
      end
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object

All unknown methods are routed to composed OLE object



40
41
42
# File 'lib/p2ruby/base.rb', line 40

def method_missing *args
  @ole.send *args
end

Instance Attribute Details

#lastargsObject (readonly)

Returns the value of attribute lastargs.



10
11
12
# File 'lib/p2ruby/base.rb', line 10

def lastargs
  @lastargs
end

#oleObject (readonly)

Returns the value of attribute ole.



10
11
12
# File 'lib/p2ruby/base.rb', line 10

def ole
  @ole
end

#optsObject (readonly)

Returns the value of attribute opts.



10
11
12
# File 'lib/p2ruby/base.rb', line 10

def opts
  @opts
end

Instance Method Details

#clsidObject



51
52
53
# File 'lib/p2ruby/base.rb', line 51

def clsid
  self.class::CLSID
end

#keep_lastargs(return_value) ⇒ Object

Keeps [OUT] args sent by reference into OLE method s



46
47
48
49
# File 'lib/p2ruby/base.rb', line 46

def keep_lastargs(return_value)
  @lastargs = WIN32OLE::ARGV
  return_value
end

#progidObject



55
56
57
# File 'lib/p2ruby/base.rb', line 55

def progid
  self.class::PROGID
end