edoors-ruby 0.0.6
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/.gitignore +2 -0
- data/.travis.yml +7 -0
- data/Changelog +23 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +661 -0
- data/README.md +18 -0
- data/Rakefile +6 -0
- data/bin/edoors.rb +71 -0
- data/edoors-ruby.gemspec +28 -0
- data/examples/hello_world.json +38 -0
- data/examples/hello_world.rb +76 -0
- data/lib/edoors.rb +51 -0
- data/lib/edoors/board.rb +69 -0
- data/lib/edoors/door.rb +95 -0
- data/lib/edoors/iota.rb +67 -0
- data/lib/edoors/link.rb +70 -0
- data/lib/edoors/particle.rb +235 -0
- data/lib/edoors/room.rb +190 -0
- data/lib/edoors/spin.rb +168 -0
- data/lib/version.rb +28 -0
- data/spec/board_spec.rb +92 -0
- data/spec/door_spec.rb +95 -0
- data/spec/link_spec.rb +38 -0
- data/spec/particle_spec.rb +266 -0
- data/spec/room_spec.rb +315 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/spin_spec.rb +132 -0
- data/spec/spot_spec.rb +26 -0
- data/test/test_iotas.rb +168 -0
- metadata +136 -0
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# edoors-ruby
|
2
|
+
by Jérémy Zurcher
|
3
|
+
http://asynk.ch
|
4
|
+
|
5
|
+
## DESCRIPTION:
|
6
|
+
|
7
|
+
* a ruby rewrite of [evenja](http://www.revena.com/evenja) C++ application framework concept
|
8
|
+
|
9
|
+
## FEATURES/PROBLEMS:
|
10
|
+
[](http://travis-ci.org/jeremyz/edoors-ruby)
|
11
|
+
|
12
|
+
## SYNOPSIS:
|
13
|
+
|
14
|
+
* experimental material, we'll see where it leads
|
15
|
+
|
16
|
+
## LICENSE:
|
17
|
+
|
18
|
+
[AGPL](http://www.gnu.org/licenses/agpl-3.0.html)
|
data/Rakefile
ADDED
data/bin/edoors.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# Copyright 2012 Jérémy Zurcher <jeremy@asynk.ch>
|
5
|
+
#
|
6
|
+
# This file is part of edoors-ruby.
|
7
|
+
#
|
8
|
+
# edoors-ruby is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU Affero General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# edoors-ruby is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU Affero General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Affero General Public License
|
19
|
+
# along with edoors-ruby. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
require 'edoors'
|
22
|
+
require 'optparse'
|
23
|
+
|
24
|
+
@options = { :require=>[] }
|
25
|
+
|
26
|
+
@parser ||= OptionParser.new do |opts|
|
27
|
+
opts.banner = "Usage: #{$0.split('/').last} [options] config"
|
28
|
+
|
29
|
+
opts.on_tail("-r", "--require", "Print this message") { puts opts; exit 0 }
|
30
|
+
opts.on_tail("-h", "--help", "Print this message") { puts opts; exit 0 }
|
31
|
+
opts.on_tail("-v", "--version", "Print version info then exit") { puts "edoors-ruby #{Edoors::VERSION}"; exit 0 }
|
32
|
+
opts.on_tail("-l", "--license", "Print license info then exit") { puts DATA.read; exit 0 }
|
33
|
+
opts.on_tail("-r", "--require FILE", "require the library") { |file| @options[:require] << file }
|
34
|
+
end
|
35
|
+
|
36
|
+
@parser.parse!(ARGV)
|
37
|
+
|
38
|
+
config_path = ARGV.shift
|
39
|
+
if config_path.nil?
|
40
|
+
puts "no config file provided, what the hell should I do ?"
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
if not File.exists? config_path
|
44
|
+
puts "#{config_path} does not exists."
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
@options[:require].each do |file|
|
49
|
+
load file
|
50
|
+
end
|
51
|
+
|
52
|
+
dom0 = Edoors::Spin.resume! config_path
|
53
|
+
dom0.spin!
|
54
|
+
|
55
|
+
__END__
|
56
|
+
|
57
|
+
Copyright 2012 Jérémy Zurcher <jeremy@asynk.ch>
|
58
|
+
|
59
|
+
edoors-ruby is free software: you can redistribute it and/or modify
|
60
|
+
it under the terms of the GNU Affero General Public License as published by
|
61
|
+
the Free Software Foundation, either version 3 of the License, or
|
62
|
+
(at your option) any later version.
|
63
|
+
|
64
|
+
edoors-ruby is distributed in the hope that it will be useful,
|
65
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
66
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
67
|
+
GNU Affero General Public License for more details.
|
68
|
+
|
69
|
+
You should have received a copy of the GNU Affero General Public License
|
70
|
+
along with edoors-ruby. If not, see <http://www.gnu.org/licenses/>.
|
71
|
+
|
data/edoors-ruby.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
$:.push File.expand_path("../lib", __FILE__)
|
5
|
+
require 'version'
|
6
|
+
#
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "edoors-ruby"
|
9
|
+
s.version = Edoors::VERSION
|
10
|
+
s.authors = ["Jérémy Zurcher"]
|
11
|
+
s.email = ["jeremy@asynk.ch"]
|
12
|
+
s.homepage = "http://github.com/jeremyz/edoors-ruby"
|
13
|
+
s.summary = %q{ruby rewrite of C++ application framework evenja (http://www.revena.com/evenja)}
|
14
|
+
s.description = %q{Evenja propose a data centric paradigm. A traditional programm composed of many functions
|
15
|
+
is decomposed into small autonomous modifications applied on the data implemented in different instances of Door base class.
|
16
|
+
Routing between these doors is handled through links or user application destinations.}
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_runtime_dependency "json"
|
24
|
+
s.add_development_dependency "rspec", ["~> 2.6"]
|
25
|
+
s.add_development_dependency "rake"
|
26
|
+
end
|
27
|
+
#
|
28
|
+
# EOF
|
@@ -0,0 +1,38 @@
|
|
1
|
+
{
|
2
|
+
"kls": "Edoors::Spin",
|
3
|
+
"timestamp": "2012-06-10 23:17:15 +0200",
|
4
|
+
"name": "dom0",
|
5
|
+
"hibernation": false,
|
6
|
+
"inner_room": {
|
7
|
+
"iotas": {
|
8
|
+
"input": {
|
9
|
+
"kls": "InputDoor",
|
10
|
+
"name": "input"
|
11
|
+
},
|
12
|
+
"output": {
|
13
|
+
"kls": "OutputDoor",
|
14
|
+
"name": "output"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
"links": {
|
18
|
+
"input": [
|
19
|
+
{
|
20
|
+
"kls": "Edoors::Link",
|
21
|
+
"src": "input",
|
22
|
+
"dsts": "output",
|
23
|
+
"fields": null,
|
24
|
+
"cond_fields": null,
|
25
|
+
"cond_value": null
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
29
|
+
},
|
30
|
+
"sys_fifo": [
|
31
|
+
|
32
|
+
],
|
33
|
+
"app_fifo": [
|
34
|
+
|
35
|
+
],
|
36
|
+
"debug_errors": false,
|
37
|
+
"debug_routing": false
|
38
|
+
}
|
@@ -0,0 +1,76 @@
|
|
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/hello_world.rb
|
8
|
+
#
|
9
|
+
# or load the system from a JSON specification ( created with dom0.hibernate! )
|
10
|
+
# $ ruby -Ilib bin/edoors.rb -r examples/hello_world.rb examples/hello_world.json
|
11
|
+
#
|
12
|
+
require 'edoors'
|
13
|
+
#
|
14
|
+
class InputDoor < Edoors::Door
|
15
|
+
#
|
16
|
+
# see Iota class for the different methods to override
|
17
|
+
def start!
|
18
|
+
# stimulate myself on system boot up
|
19
|
+
# if an action is set, but no destination is, it will be self.
|
20
|
+
# see Door#_send
|
21
|
+
send_p require_p(Edoors::Particle), Edoors::ACT_GET
|
22
|
+
end
|
23
|
+
#
|
24
|
+
def receive_p p
|
25
|
+
if p.action==Edoors::ACT_GET
|
26
|
+
# if desired (not necessary here), call reset! to clear particle's data,
|
27
|
+
# meaning merge particle, payload, destinations
|
28
|
+
# see Particle#reset!
|
29
|
+
p.reset!
|
30
|
+
# manipulate the particle's payload
|
31
|
+
p.set_data 'txt', "hello world"
|
32
|
+
# will follow the non conditional link.
|
33
|
+
# see Room#_send and Room#_try_links
|
34
|
+
send_p p
|
35
|
+
else
|
36
|
+
# we can release it or let the Door do it.
|
37
|
+
# see Door#process_p
|
38
|
+
release_p p
|
39
|
+
end
|
40
|
+
end
|
41
|
+
#
|
42
|
+
end
|
43
|
+
#
|
44
|
+
class OutputDoor < Edoors::Door
|
45
|
+
#
|
46
|
+
def receive_p p
|
47
|
+
if p.action!=Edoors::ACT_ERROR
|
48
|
+
puts p.get_data('txt')
|
49
|
+
end
|
50
|
+
# let the door release the particle
|
51
|
+
# see Door#process_p
|
52
|
+
end
|
53
|
+
#
|
54
|
+
end
|
55
|
+
#
|
56
|
+
if $0 == __FILE__
|
57
|
+
#
|
58
|
+
# This will schedule the particles and act as the top level Room
|
59
|
+
dom0 = Edoors::Spin.new 'dom0'
|
60
|
+
# This will feed a receive particle with data and send it back
|
61
|
+
input = InputDoor.new 'input', dom0
|
62
|
+
# This will output the receive data and let the system recycle the particle
|
63
|
+
output = OutputDoor.new 'output', dom0
|
64
|
+
# This will be the unconditinal link leading from 'input' to 'output'
|
65
|
+
dom0.add_link Edoors::Link.new('input', 'output', nil, nil, nil)
|
66
|
+
#
|
67
|
+
# schedule the spinning particles untill the system cools down
|
68
|
+
dom0.spin!
|
69
|
+
#
|
70
|
+
# you can save the system state after it's run,
|
71
|
+
# but to be able to use it to bootstrap, the hibernation attribute must be set to false
|
72
|
+
# otherwise start! method is not called
|
73
|
+
# dom0.hibernate! 'hello_world.json'
|
74
|
+
end
|
75
|
+
#
|
76
|
+
# EOF
|
data/lib/edoors.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# Copyright 2012 Jérémy Zurcher <jeremy@asynk.ch>
|
5
|
+
#
|
6
|
+
# This file is part of edoors-ruby.
|
7
|
+
#
|
8
|
+
# edoors-ruby is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU Affero General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# edoors-ruby is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU Affero General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Affero General Public License
|
19
|
+
# along with edoors-ruby. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
require 'version'
|
22
|
+
#
|
23
|
+
module Edoors
|
24
|
+
#
|
25
|
+
PATH_SEP = '/'.freeze
|
26
|
+
LINK_SEP = ','.freeze
|
27
|
+
ACT_SEP = '?'.freeze
|
28
|
+
#
|
29
|
+
ACT_GET = 'get'.freeze
|
30
|
+
ACT_ERROR = 'error'.freeze
|
31
|
+
#
|
32
|
+
SYS_ACT_HIBERNATE = 'hibernate'.freeze
|
33
|
+
SYS_ACT_ADD_LINK = 'sys_add_link'.freeze
|
34
|
+
#
|
35
|
+
FIELD_ERROR_MSG = 'edoors_error'.freeze
|
36
|
+
FIELD_HIBERNATE_PATH= 'hibernate_path'.freeze
|
37
|
+
#
|
38
|
+
class Exception < ::Exception; end
|
39
|
+
#
|
40
|
+
end
|
41
|
+
#
|
42
|
+
require 'json'
|
43
|
+
require 'edoors/particle'
|
44
|
+
require 'edoors/iota'
|
45
|
+
require 'edoors/room'
|
46
|
+
require 'edoors/spin'
|
47
|
+
require 'edoors/door'
|
48
|
+
require 'edoors/board'
|
49
|
+
require 'edoors/link'
|
50
|
+
#
|
51
|
+
# EOF
|
data/lib/edoors/board.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# Copyright 2012 Jérémy Zurcher <jeremy@asynk.ch>
|
5
|
+
#
|
6
|
+
# This file is part of edoors-ruby.
|
7
|
+
#
|
8
|
+
# edoors-ruby is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU Affero General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# edoors-ruby is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU Affero General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Affero General Public License
|
19
|
+
# along with edoors-ruby. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
#
|
22
|
+
module Edoors
|
23
|
+
#
|
24
|
+
ACT_FOLLOW = 'follow'.freeze
|
25
|
+
#
|
26
|
+
class Board < Door
|
27
|
+
#
|
28
|
+
def initialize n, p
|
29
|
+
super n, p
|
30
|
+
@postponed = {}
|
31
|
+
end
|
32
|
+
#
|
33
|
+
def to_json *a
|
34
|
+
{
|
35
|
+
'kls' => self.class.name,
|
36
|
+
'name' => @name,
|
37
|
+
'postponed' => @postponed
|
38
|
+
}.merge(hibernate!).to_json *a
|
39
|
+
end
|
40
|
+
#
|
41
|
+
def self.json_create o
|
42
|
+
raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name
|
43
|
+
board = self.new o['name'], o['parent']
|
44
|
+
o['postponed'].each do |link_value,particle|
|
45
|
+
board.process_p Edoors::Particle.json_create(particle.merge!('spin'=>board.spin))
|
46
|
+
end
|
47
|
+
board.resume! o
|
48
|
+
board
|
49
|
+
end
|
50
|
+
#
|
51
|
+
def process_p p
|
52
|
+
@viewer.receive_p p if @viewer
|
53
|
+
if p.action!=Edoors::ACT_ERROR
|
54
|
+
p2 = @postponed[p.link_value] ||= p
|
55
|
+
return if p2==p
|
56
|
+
@postponed.delete p.link_value
|
57
|
+
p,p2 = p2,p if p.action==Edoors::ACT_FOLLOW
|
58
|
+
p.merge! p2
|
59
|
+
end
|
60
|
+
@saved = p
|
61
|
+
receive_p p
|
62
|
+
_garbage if not @saved.nil?
|
63
|
+
end
|
64
|
+
#
|
65
|
+
end
|
66
|
+
#
|
67
|
+
end
|
68
|
+
#
|
69
|
+
# EOF
|
data/lib/edoors/door.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# Copyright 2012 Jérémy Zurcher <jeremy@asynk.ch>
|
5
|
+
#
|
6
|
+
# This file is part of edoors-ruby.
|
7
|
+
#
|
8
|
+
# edoors-ruby is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU Affero General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# edoors-ruby is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU Affero General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Affero General Public License
|
19
|
+
# along with edoors-ruby. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
#
|
22
|
+
module Edoors
|
23
|
+
#
|
24
|
+
class Door < Iota
|
25
|
+
#
|
26
|
+
def initialize n, p
|
27
|
+
super n, p
|
28
|
+
@saved = nil
|
29
|
+
end
|
30
|
+
#
|
31
|
+
def to_json *a
|
32
|
+
{
|
33
|
+
'kls' => self.class.name,
|
34
|
+
'name' => @name
|
35
|
+
}.merge(hibernate!).to_json *a
|
36
|
+
end
|
37
|
+
#
|
38
|
+
def self.json_create o
|
39
|
+
raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name
|
40
|
+
door = self.new o['name'], o['parent']
|
41
|
+
door.resume! o
|
42
|
+
door
|
43
|
+
end
|
44
|
+
#
|
45
|
+
def require_p p_kls
|
46
|
+
@spin.require_p p_kls
|
47
|
+
end
|
48
|
+
#
|
49
|
+
def release_p p
|
50
|
+
@saved=nil if @saved==p # particle is released, all is good
|
51
|
+
@spin.release_p p
|
52
|
+
end
|
53
|
+
#
|
54
|
+
def _garbage
|
55
|
+
puts " ! #{path} didn't give back #{@saved}" if @spin.debug_errors
|
56
|
+
puts "\t#{@saved.data Edoors::FIELD_ERROR_MSG}" if @saved.action==Edoors::ACT_ERROR
|
57
|
+
@spin.release_p @saved
|
58
|
+
@saved = nil
|
59
|
+
end
|
60
|
+
private :_garbage
|
61
|
+
#
|
62
|
+
def process_p p
|
63
|
+
@viewer.receive_p p if @viewer
|
64
|
+
@saved = p
|
65
|
+
receive_p p
|
66
|
+
_garbage if not @saved.nil?
|
67
|
+
end
|
68
|
+
#
|
69
|
+
def process_sys_p p
|
70
|
+
# nothing todo with it now
|
71
|
+
@spin.release_p p
|
72
|
+
end
|
73
|
+
#
|
74
|
+
def _send sys, p, a=nil, d=nil
|
75
|
+
p.init! self
|
76
|
+
p.set_dst! a, d||self if a
|
77
|
+
@saved=nil if @saved==p # particle is sent back the data, all is good
|
78
|
+
# daddy will know what to do
|
79
|
+
sys ? @parent.send_sys_p(p) : @parent.send_p(p)
|
80
|
+
end
|
81
|
+
private :_send
|
82
|
+
#
|
83
|
+
def send_p p, a=nil, d=nil
|
84
|
+
_send false, p, a, d
|
85
|
+
end
|
86
|
+
#
|
87
|
+
def send_sys_p p, a=nil, d=nil
|
88
|
+
_send true, p, a, d
|
89
|
+
end
|
90
|
+
#
|
91
|
+
end
|
92
|
+
#
|
93
|
+
end
|
94
|
+
#
|
95
|
+
# EOF
|