Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.

Name: patterns/p18.rb 
1:
#!/usr/bin/env ruby
2:
require 'rubygems'
3:
require 'pp'
4:
require 'term/ansicolor'
5:
require File.expand_path(File.dirname(__FILE__) + '/../lib/remar')
6:
 
7:
m = REMAR.new
8:
rs = m.ruleset
9:
 
10:
rs.value :endpoint, 'http://b', :a
11:
rs.value :endpoint, 'http://y', :b
12:
 
13:
rs.event :before, :instance, :position, :endpoint
14:
rs.event :after, :instance, :position, :endpoint
15:
 
16:
rs.context :sync, :active => false
17:
 
18:
rs.call :skip
19:
 
20:
rs.call :continue
21:
 
22:
rs.rule rs.event.before{endpoint == :a} do
23:
  context.sync.active = true
24:
  continue event.instance, event.position
25:
end  
26:
 
27:
rs.rule rs.event.after{endpoint == :a} do
28:
  context.sync.active = false
29:
  continue event.instance, event.position
30:
end
31:
 
32:
rs.rule rs.event.before{endpoint == :b}, rs.context.sync{active == true} do
33:
  continue event.instance, event.position
34:
end  
35:
 
36:
rs.rule rs.event.after{endpoint == :b}, rs.context.sync{active == false} do
37:
  skip event.instance, event.position
38:
end  
39:
 
40:
m.default do |call,test|
41:
  print Term::ANSIColor::bold(Term::ANSIColor::red("  #{call} "))
42:
  p test
43:
end  
44:
m.before_push do |evt_name,evt_data,context|
45:
  puts Term::ANSIColor::bold("Pushing #{evt_name} #{evt_data.inspect}")
46:
end
47:
m.after_push do |context|
48:
  puts "  After:\n" + context.pretty_inspect.gsub(/^/,'    |')
49:
end
50:
 
51:
puts Term::ANSIColor::bold("Initial context:")
52:
puts m.context.pretty_inspect.gsub(/^/,'    |')
53:
 
54:
m.push :before, :position => :p, :endpoint => 'http://y', :instance => 'http://localhost:9188/2'
55:
 
56:
m.push :before, :position => :p, :endpoint => 'http://b', :instance => 'http://localhost:9188/1'
57:
m.push :before, :position => :p, :endpoint => 'http://y', :instance => 'http://localhost:9188/3'
58:
m.push :after,  :position => :p, :endpoint => 'http://b', :instance => 'http://localhost:9188/1'
59:
 
60:
m.push :before, :position => :p, :endpoint => 'http://y', :instance => 'http://localhost:9188/4'