edoors-ruby 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changelog +17 -1
- data/Gemfile.lock +1 -1
- data/examples/board.json +52 -0
- data/examples/board.rb +133 -0
- data/examples/data.json +8 -0
- data/examples/hello_world.json +4 -5
- data/examples/hello_world.rb +2 -2
- data/examples/links.json +96 -0
- data/examples/links.rb +121 -0
- data/lib/edoors.rb +9 -9
- data/lib/edoors/board.rb +40 -1
- data/lib/edoors/door.rb +62 -5
- data/lib/edoors/iota.rb +23 -5
- data/lib/edoors/link.rb +42 -22
- data/lib/edoors/particle.rb +207 -52
- data/lib/edoors/room.rb +92 -16
- data/lib/edoors/spin.rb +93 -6
- data/lib/version.rb +1 -1
- data/spec/board_spec.rb +39 -8
- data/spec/door_spec.rb +3 -3
- data/spec/{spot_spec.rb → iota_spec.rb} +20 -0
- data/spec/link_spec.rb +10 -13
- data/spec/particle_spec.rb +61 -21
- data/spec/room_spec.rb +28 -10
- data/spec/spin_spec.rb +15 -5
- data/test/test_iotas.rb +5 -6
- metadata +17 -26
data/Changelog
CHANGED
@@ -1,4 +1,16 @@
|
|
1
|
-
2012-
|
1
|
+
2012-06-28 Jérémy Zurcher <jeremy@asynk.ch>
|
2
|
+
* release : 0.0.7
|
3
|
+
* yard documentation completed
|
4
|
+
* add link and board JSON ready examples
|
5
|
+
* link_value is an Hash -> fix possible bugs
|
6
|
+
* use ruby Array instead of comma separated Strings (destinations,keys)
|
7
|
+
* implement SYS_ACT_ADD_ROOM system action
|
8
|
+
* implement ACT_PASS_THROUGH application action
|
9
|
+
* add Particle #merged_length, #each_merged
|
10
|
+
* add Board #keep!, flush!
|
11
|
+
|
12
|
+
2012-06-13 Jérémy Zurcher <jeremy@asynk.ch>
|
13
|
+
* release : 0.0.6 (edoors)
|
2
14
|
* add bin
|
3
15
|
* add examples
|
4
16
|
* project rename, iotas -> edoors-ruby
|
@@ -7,6 +19,10 @@
|
|
7
19
|
* enhance direct routing through Door#send_p destination parameter
|
8
20
|
* enhance Particle#init! and Particle#reset! action and usage
|
9
21
|
|
22
|
+
2012-06-13 Jérémy Zurcher <jeremy@asynk.ch>
|
23
|
+
* release : 0.0.5 (iotas)
|
24
|
+
* for project name change notification
|
25
|
+
|
10
26
|
2012-06-02 Jérémy Zurcher <jeremy@asynk.ch>
|
11
27
|
* release : 0.0.4
|
12
28
|
* simplify routing algorithm
|
data/Gemfile.lock
CHANGED
data/examples/board.json
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"kls": "Edoors::Spin",
|
3
|
+
"timestamp": "2012-06-28 14:37:21 +0200",
|
4
|
+
"name": "dom0",
|
5
|
+
"hibernation": false,
|
6
|
+
"inner_room": {
|
7
|
+
"iotas": {
|
8
|
+
"input": {
|
9
|
+
"kls": "FileReader",
|
10
|
+
"name": "input",
|
11
|
+
"filepath": "./examples/data.json"
|
12
|
+
},
|
13
|
+
"filter": {
|
14
|
+
"kls": "Filter",
|
15
|
+
"name": "filter"
|
16
|
+
},
|
17
|
+
"stats": {
|
18
|
+
"kls": "Stats",
|
19
|
+
"name": "stats",
|
20
|
+
"postponed": {
|
21
|
+
}
|
22
|
+
},
|
23
|
+
"output": {
|
24
|
+
"kls": "OutputDoor",
|
25
|
+
"name": "output"
|
26
|
+
}
|
27
|
+
},
|
28
|
+
"links": {
|
29
|
+
"input": [
|
30
|
+
{
|
31
|
+
"kls": "Edoors::Link",
|
32
|
+
"src": "input",
|
33
|
+
"dsts": [
|
34
|
+
"filter",
|
35
|
+
"stats?follow",
|
36
|
+
"output"
|
37
|
+
],
|
38
|
+
"keys": "filter_value",
|
39
|
+
"value": null
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}
|
43
|
+
},
|
44
|
+
"sys_fifo": [
|
45
|
+
|
46
|
+
],
|
47
|
+
"app_fifo": [
|
48
|
+
|
49
|
+
],
|
50
|
+
"debug_garbage": false,
|
51
|
+
"debug_routing": false
|
52
|
+
}
|
data/examples/board.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# from the project top directory :
|
5
|
+
#
|
6
|
+
# run this script which builds the example system and spin it untill it's empty:
|
7
|
+
# $ ruby -Ilib examples/links.rb
|
8
|
+
#
|
9
|
+
# or load the system from a JSON specification ( created with dom0.hibernate! )
|
10
|
+
# $ ruby -Ilib bin/edoors.rb -r examples/board.rb examples/board.json
|
11
|
+
#
|
12
|
+
#
|
13
|
+
require 'edoors'
|
14
|
+
#
|
15
|
+
class FileReader < Edoors::Door
|
16
|
+
#
|
17
|
+
def initialize n, p, path=nil
|
18
|
+
super n, p
|
19
|
+
@filepath = path unless path.nil?
|
20
|
+
end
|
21
|
+
#
|
22
|
+
def hibernate!
|
23
|
+
{'filepath'=>@filepath}
|
24
|
+
end
|
25
|
+
#
|
26
|
+
def resume! o
|
27
|
+
@filepath = o['filepath']
|
28
|
+
end
|
29
|
+
#
|
30
|
+
def start!
|
31
|
+
@file = File.open(@filepath,'r')
|
32
|
+
# stimulate myself on system boot up
|
33
|
+
send_p require_p(Edoors::Particle), Edoors::ACT_GET
|
34
|
+
end
|
35
|
+
#
|
36
|
+
def receive_p p
|
37
|
+
if p.action==Edoors::ACT_GET
|
38
|
+
# stop everything if EOF reached
|
39
|
+
if @file.eof?
|
40
|
+
p.reset!
|
41
|
+
send_p p, Edoors::ACT_PASS_THROUGH, 'stats'
|
42
|
+
else
|
43
|
+
p.set_data 'person', JSON.load(@file.readline)
|
44
|
+
# will follow the non conditional link.
|
45
|
+
# see Room#_send and Room#_try_links
|
46
|
+
send_p p
|
47
|
+
# stimulate myself
|
48
|
+
send_p require_p(Edoors::Particle), Edoors::ACT_GET
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
#
|
53
|
+
end
|
54
|
+
#
|
55
|
+
class Filter < Edoors::Door
|
56
|
+
#
|
57
|
+
def receive_p p
|
58
|
+
if p.action!=Edoors::ACT_ERROR
|
59
|
+
# apply the filter
|
60
|
+
h = {
|
61
|
+
:old => (p['person']['age']>=18),
|
62
|
+
:female => (p['person']['sex']=='f')
|
63
|
+
}
|
64
|
+
# puts "input : "+h.inspect
|
65
|
+
# store the result into one single attribute
|
66
|
+
p['filter_value']= h
|
67
|
+
# will follow the conditional link.
|
68
|
+
# see Room#_send and Room#_try_links
|
69
|
+
send_p p
|
70
|
+
end
|
71
|
+
end
|
72
|
+
#
|
73
|
+
end
|
74
|
+
#
|
75
|
+
class Stats < Edoors::Board
|
76
|
+
#
|
77
|
+
def receive_p p
|
78
|
+
return if p.action==Edoors::ACT_ERROR
|
79
|
+
if p.action==Edoors::ACT_PASS_THROUGH
|
80
|
+
# use this signal to flush all stored data
|
81
|
+
flush!
|
82
|
+
else
|
83
|
+
# restore the Particle into myself
|
84
|
+
# send_p p, self.path
|
85
|
+
keep! p
|
86
|
+
end
|
87
|
+
end
|
88
|
+
#
|
89
|
+
end
|
90
|
+
#
|
91
|
+
class OutputDoor < Edoors::Door
|
92
|
+
#
|
93
|
+
#
|
94
|
+
def receive_p p
|
95
|
+
return if p.action==Edoors::ACT_ERROR
|
96
|
+
f = p['filter_value']
|
97
|
+
puts "Team #{f[:old] ? 'mature' : 'tean'} #{f[:female] ? 'women' : 'men'} #{} (#{p.merged_length+1})"
|
98
|
+
d = p.get_data('person')
|
99
|
+
puts " #{d['name']} is #{d['age']} years old"
|
100
|
+
p.each_merged do |o|
|
101
|
+
d = o.get_data('person')
|
102
|
+
puts " #{d['name']} is #{d['age']} years old"
|
103
|
+
end
|
104
|
+
puts
|
105
|
+
end
|
106
|
+
#
|
107
|
+
end
|
108
|
+
#
|
109
|
+
if $0 == __FILE__
|
110
|
+
# basic setup, see hello_world.rb
|
111
|
+
dom0 = Edoors::Spin.new 'dom0'
|
112
|
+
#
|
113
|
+
FileReader.new 'input', dom0, './examples/data.json'
|
114
|
+
# the filter to be applied to each particle
|
115
|
+
Filter.new 'filter', dom0
|
116
|
+
# the statistics board
|
117
|
+
Stats.new 'stats', dom0
|
118
|
+
# different outptu doors
|
119
|
+
OutputDoor.new 'output', dom0
|
120
|
+
# default link directing everything from input into age_filter
|
121
|
+
dom0.add_link Edoors::Link.new('input', ['filter','stats?follow','output'], 'filter_value')
|
122
|
+
#
|
123
|
+
# schedule the spinning particles untill the system cools down
|
124
|
+
dom0.spin!
|
125
|
+
#
|
126
|
+
# you can save the system state after it's run,
|
127
|
+
# but to be able to use it to bootstrap, the hibernation attribute must be set to false
|
128
|
+
# otherwise start! method is not called
|
129
|
+
# dom0.hibernate! 'board.json'
|
130
|
+
#
|
131
|
+
end
|
132
|
+
#
|
133
|
+
# EOF
|
data/examples/data.json
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
{"name":"Jérémy","age":34,"sex":"m"}
|
2
|
+
{"name":"Corina","age":30,"sex":"f"}
|
3
|
+
{"name":"Róisín","age":3,"sex":"f"}
|
4
|
+
{"name":"Shaunagh","age":1,"sex":"f"}
|
5
|
+
{"name":"Alain","age":60,"sex":"m"}
|
6
|
+
{"name":"Ghislaine","age":57,"sex":"f"}
|
7
|
+
{"name":"Elise","age":33,"sex":"f"}
|
8
|
+
{"name":"Tifaine","age":27,"sex":"f"}
|
data/examples/hello_world.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"kls": "Edoors::Spin",
|
3
|
-
"timestamp": "2012-06-
|
3
|
+
"timestamp": "2012-06-24 22:50:00 +0200",
|
4
4
|
"name": "dom0",
|
5
5
|
"hibernation": false,
|
6
6
|
"inner_room": {
|
@@ -20,9 +20,8 @@
|
|
20
20
|
"kls": "Edoors::Link",
|
21
21
|
"src": "input",
|
22
22
|
"dsts": "output",
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"cond_value": null
|
23
|
+
"keys": null,
|
24
|
+
"value": null
|
26
25
|
}
|
27
26
|
]
|
28
27
|
}
|
@@ -33,6 +32,6 @@
|
|
33
32
|
"app_fifo": [
|
34
33
|
|
35
34
|
],
|
36
|
-
"
|
35
|
+
"debug_garbage": false,
|
37
36
|
"debug_routing": false
|
38
37
|
}
|
data/examples/hello_world.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# $ ruby -Ilib examples/hello_world.rb
|
8
8
|
#
|
9
9
|
# or load the system from a JSON specification ( created with dom0.hibernate! )
|
10
|
-
# $ ruby -Ilib
|
10
|
+
# $ ruby -Ilib -r ./examples/hello_world.rb bin/edoors.rb examples/hello_world.json
|
11
11
|
#
|
12
12
|
require 'edoors'
|
13
13
|
#
|
@@ -62,7 +62,7 @@ if $0 == __FILE__
|
|
62
62
|
# This will output the receive data and let the system recycle the particle
|
63
63
|
output = OutputDoor.new 'output', dom0
|
64
64
|
# This will be the unconditinal link leading from 'input' to 'output'
|
65
|
-
dom0.add_link Edoors::Link.new('input', 'output', nil, nil
|
65
|
+
dom0.add_link Edoors::Link.new('input', 'output', nil, nil)
|
66
66
|
#
|
67
67
|
# schedule the spinning particles untill the system cools down
|
68
68
|
dom0.spin!
|
data/examples/links.json
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
{
|
2
|
+
"kls": "Edoors::Spin",
|
3
|
+
"timestamp": "2012-06-28 14:43:36 +0200",
|
4
|
+
"name": "dom0",
|
5
|
+
"hibernation": false,
|
6
|
+
"inner_room": {
|
7
|
+
"iotas": {
|
8
|
+
"input": {
|
9
|
+
"kls": "FileReader",
|
10
|
+
"name": "input",
|
11
|
+
"filepath": "./examples/data.json"
|
12
|
+
},
|
13
|
+
"age_filter": {
|
14
|
+
"kls": "Filter",
|
15
|
+
"name": "age_filter"
|
16
|
+
},
|
17
|
+
"output_f": {
|
18
|
+
"kls": "OutputDoor",
|
19
|
+
"name": "output_f",
|
20
|
+
"title": "woman"
|
21
|
+
},
|
22
|
+
"output_m": {
|
23
|
+
"kls": "OutputDoor",
|
24
|
+
"name": "output_m",
|
25
|
+
"title": "man"
|
26
|
+
},
|
27
|
+
"output_child": {
|
28
|
+
"kls": "OutputDoor",
|
29
|
+
"name": "output_child",
|
30
|
+
"title": "child"
|
31
|
+
},
|
32
|
+
"output_parent": {
|
33
|
+
"kls": "OutputDoor",
|
34
|
+
"name": "output_parent",
|
35
|
+
"title": "parent"
|
36
|
+
}
|
37
|
+
},
|
38
|
+
"links": {
|
39
|
+
"input": [
|
40
|
+
{
|
41
|
+
"kls": "Edoors::Link",
|
42
|
+
"src": "input",
|
43
|
+
"dsts": "age_filter",
|
44
|
+
"keys": null,
|
45
|
+
"value": null
|
46
|
+
}
|
47
|
+
],
|
48
|
+
"age_filter": [
|
49
|
+
{
|
50
|
+
"kls": "Edoors::Link",
|
51
|
+
"src": "age_filter",
|
52
|
+
"dsts": "output_f",
|
53
|
+
"keys": null,
|
54
|
+
"value": {
|
55
|
+
"sex": "f"
|
56
|
+
}
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"kls": "Edoors::Link",
|
60
|
+
"src": "age_filter",
|
61
|
+
"dsts": "output_m",
|
62
|
+
"keys": null,
|
63
|
+
"value": {
|
64
|
+
"sex": "m"
|
65
|
+
}
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"kls": "Edoors::Link",
|
69
|
+
"src": "age_filter",
|
70
|
+
"dsts": "output_child",
|
71
|
+
"keys": null,
|
72
|
+
"value": {
|
73
|
+
"old": false
|
74
|
+
}
|
75
|
+
},
|
76
|
+
{
|
77
|
+
"kls": "Edoors::Link",
|
78
|
+
"src": "age_filter",
|
79
|
+
"dsts": "output_parent",
|
80
|
+
"keys": null,
|
81
|
+
"value": {
|
82
|
+
"old": true
|
83
|
+
}
|
84
|
+
}
|
85
|
+
]
|
86
|
+
}
|
87
|
+
},
|
88
|
+
"sys_fifo": [
|
89
|
+
|
90
|
+
],
|
91
|
+
"app_fifo": [
|
92
|
+
|
93
|
+
],
|
94
|
+
"debug_garbage": false,
|
95
|
+
"debug_routing": false
|
96
|
+
}
|
data/examples/links.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# from the project top directory :
|
5
|
+
#
|
6
|
+
# run this script which builds the example system and spin it untill it's empty:
|
7
|
+
# $ ruby -Ilib examples/links.rb
|
8
|
+
#
|
9
|
+
# or load the system from a JSON specification ( created with dom0.hibernate! )
|
10
|
+
# $ ruby -Ilib -r ./examples/links.rb bin/edoors.rb examples/links.json
|
11
|
+
#
|
12
|
+
#
|
13
|
+
require 'edoors'
|
14
|
+
#
|
15
|
+
class FileReader < Edoors::Door
|
16
|
+
#
|
17
|
+
def initialize n, p, path=nil
|
18
|
+
super n, p
|
19
|
+
@filepath = path
|
20
|
+
end
|
21
|
+
#
|
22
|
+
def hibernate!
|
23
|
+
{'filepath'=>@filepath}
|
24
|
+
end
|
25
|
+
#
|
26
|
+
def resume! o
|
27
|
+
@filepath = o['filepath']
|
28
|
+
end
|
29
|
+
#
|
30
|
+
def start!
|
31
|
+
@file = File.open(@filepath,'r')
|
32
|
+
# stimulate myself on system boot up
|
33
|
+
send_p require_p(Edoors::Particle), Edoors::ACT_GET
|
34
|
+
end
|
35
|
+
#
|
36
|
+
def receive_p p
|
37
|
+
if p.action==Edoors::ACT_GET
|
38
|
+
# stop everything if EOF reached
|
39
|
+
return if @file.eof?
|
40
|
+
p.set_data 'person', JSON.load(@file.readline)
|
41
|
+
# will follow the non conditional link.
|
42
|
+
# see Room#_send and Room#_try_links
|
43
|
+
send_p p
|
44
|
+
# stimulate myself
|
45
|
+
send_p require_p(Edoors::Particle), Edoors::ACT_GET
|
46
|
+
end
|
47
|
+
end
|
48
|
+
#
|
49
|
+
end
|
50
|
+
#
|
51
|
+
class Filter < Edoors::Door
|
52
|
+
#
|
53
|
+
def receive_p p
|
54
|
+
if p.action!=Edoors::ACT_ERROR
|
55
|
+
# apply the filter
|
56
|
+
p['old'] = (p['person']['age']>=18)
|
57
|
+
p['sex'] = p['person']['sex']
|
58
|
+
# will follow the conditional link.
|
59
|
+
# see Room#_send and Room#_try_links
|
60
|
+
send_p p
|
61
|
+
end
|
62
|
+
end
|
63
|
+
#
|
64
|
+
end
|
65
|
+
#
|
66
|
+
class OutputDoor < Edoors::Door
|
67
|
+
#
|
68
|
+
def initialize n, p, t=nil
|
69
|
+
super n, p
|
70
|
+
@title = t
|
71
|
+
end
|
72
|
+
#
|
73
|
+
def hibernate!
|
74
|
+
{'title'=>@title}
|
75
|
+
end
|
76
|
+
#
|
77
|
+
def resume! o
|
78
|
+
@title = o['title']
|
79
|
+
end
|
80
|
+
#
|
81
|
+
def receive_p p
|
82
|
+
if p.action!=Edoors::ACT_ERROR
|
83
|
+
p = p.get_data('person')
|
84
|
+
puts "#{p['name']} is a #{p['age']} year(s) old #{@title}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
#
|
88
|
+
end
|
89
|
+
#
|
90
|
+
if $0 == __FILE__
|
91
|
+
# basic setup, see hello_world.rb
|
92
|
+
dom0 = Edoors::Spin.new 'dom0'
|
93
|
+
#
|
94
|
+
FileReader.new 'input', dom0, './examples/data.json'
|
95
|
+
# the filter to be applied to each particle
|
96
|
+
Filter.new 'age_filter', dom0
|
97
|
+
# different output doors
|
98
|
+
OutputDoor.new 'output_f', dom0, 'woman'
|
99
|
+
OutputDoor.new 'output_m', dom0, 'man'
|
100
|
+
OutputDoor.new 'output_child', dom0, 'child'
|
101
|
+
OutputDoor.new 'output_parent', dom0, 'parent'
|
102
|
+
# default link directing everything from input into age_filter
|
103
|
+
dom0.add_link Edoors::Link.new('input', 'age_filter')
|
104
|
+
# different links directing to different outputs depending on 'sex' key
|
105
|
+
dom0.add_link Edoors::Link.new('age_filter', 'output_f', nil, {'sex'=>'f'})
|
106
|
+
dom0.add_link Edoors::Link.new('age_filter', 'output_m', nil, {'sex'=>'m'})
|
107
|
+
# different links directing to different outputs depending on 'old' key
|
108
|
+
dom0.add_link Edoors::Link.new('age_filter', 'output_child', nil, {'old'=>false})
|
109
|
+
dom0.add_link Edoors::Link.new('age_filter', 'output_parent', nil, {'old'=>true})
|
110
|
+
#
|
111
|
+
# schedule the spinning particles untill the system cools down
|
112
|
+
dom0.spin!
|
113
|
+
#
|
114
|
+
# you can save the system state after it's run,
|
115
|
+
# but to be able to use it to bootstrap, the hibernation attribute must be set to false
|
116
|
+
# otherwise start! method is not called
|
117
|
+
dom0.hibernate! 'links.json'
|
118
|
+
#
|
119
|
+
end
|
120
|
+
#
|
121
|
+
# EOF
|