Class: Caricature::ClrInterfaceIsolator

Inherits:
Isolator show all
Defined in:
lib/caricature/clr/isolator.rb

Overview

An Isolator for CLR interfaces. this implements all the methods that are defined on the interface.

Instance Attribute Summary

Attributes inherited from Isolator

#descriptor, #isolation, #subject

Instance Method Summary collapse

Methods inherited from Isolator

#build_isolation, #class_name, for, #initialize_isolation

Constructor Details

#initialize(context) ⇒ ClrInterfaceIsolator

Implementation of the template method that creates an isolator for an interface defined in a CLR language.



80
81
82
83
84
85
# File 'lib/caricature/clr/isolator.rb', line 80

def initialize(context)
  super
  sklass = context.subject
  @descriptor = ClrInterfaceDescriptor.new sklass
  build_isolation sklass
end

Instance Method Details

#create_isolation_for(subj) ⇒ Object

builds the actual isolator for the CLR interface



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/caricature/clr/isolator.rb', line 93

def create_isolation_for(subj)
  proxy_members = @descriptor.instance_members

  klass = Object.const_set(class_name(subj), Class.new)
  klass.class_eval do

    include subj
    include Interception

    proxy_members.each do |mem|
      nm = mem.name.to_s.to_sym
      define_method nm do |*args|
        b = nil
        b = Proc.new { yield } if block_given?
        isolation_context.send_message(nm, mem.return_type, *args, &b)
      end
    end

  end

  klass
end

#initialize_messengerObject

initializes the messaging strategy for the isolator



88
89
90
# File 'lib/caricature/clr/isolator.rb', line 88

def initialize_messenger
  @context.messenger = ClrInterfaceMessenger.new @context.expectations
end