Class: Caricature::ClrInterfaceIsolator
- 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
-
#create_isolation_for(subj) ⇒ Object
builds the actual
isolatorfor the CLR interface. -
#initialize(context) ⇒ ClrInterfaceIsolator
constructor
Implementation of the template method that creates an isolator for an interface defined in a CLR language.
-
#initialize_messenger ⇒ Object
initializes the messaging strategy for the isolator.
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.
201 202 203 204 205 206 |
# File 'lib/caricature/clr/isolator.rb', line 201 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
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/caricature/clr/isolator.rb', line 214 def create_isolation_for(subj) proxy_members = @descriptor.instance_members events = @descriptor.events 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.(nm, mem.return_type, *args, &b) end end end evts = events.collect do |evt| %w(add remove).inject("") do |res, nm| res << <<-end_event_definition def #{"self." unless evt.instance_member?}#{nm}_#{evt.event_name}(block) isolation_context.#{nm}_event_subscription('#{evt.event_name}', :#{evt.instance_member? ? "instance" : "class"}, block) end end_event_definition end end.join("\n") klass.class_eval evts klass end |
#initialize_messenger ⇒ Object
initializes the messaging strategy for the isolator
209 210 211 |
# File 'lib/caricature/clr/isolator.rb', line 209 def initialize_messenger @context.messenger = ClrInterfaceMessenger.new @context.expectations end |