fsm 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,78 @@
1
+ unless defined? $__fsm__
2
+ $__fsm__ = __FILE__
3
+
4
+ module FSM
5
+ #--{{{
6
+ FSM::LIBNAME =
7
+ 'fsm' unless
8
+ defined? FSM::LIBNAME
9
+
10
+ FSM::VERSION =
11
+ '0.0.0' unless
12
+ defined? FSM::VERSION
13
+
14
+ FSM::LIBVER =
15
+ "#{ FSM::LIBNAME }-#{ FSM::VERSION }" unless
16
+ defined? FSM::LIBVER
17
+
18
+ FSM::DIRNAME =
19
+ File::dirname(File::expand_path(__FILE__)) + File::SEPARATOR unless
20
+ defined? FSM::DIRNAME
21
+
22
+ FSM::ROOTDIR =
23
+ File::dirname(FSM::DIRNAME) unless
24
+ defined? FSM::ROOTDIR
25
+
26
+ FSM::LIBDIR =
27
+ File::join(FSM::DIRNAME, FSM::LIBVER) + File::SEPARATOR unless
28
+ defined? FSM::LIBDIR
29
+
30
+ FSM::INCDIR =
31
+ File::dirname(FSM::LIBDIR) + File::SEPARATOR unless
32
+ defined? FSM::INCDIR
33
+
34
+ FSM::DISPLAY_CMD =
35
+ ENV['FSM_DISPLAY_CMD'] || 'display'
36
+
37
+ FSM::DOT_CMD =
38
+ ENV['FSM_DOT_CMD'] || 'dot'
39
+
40
+ require 'tempfile'
41
+ require 'thread'
42
+ require 'sync'
43
+ require 'enumerator'
44
+
45
+ begin
46
+ $:.unshift LIBDIR
47
+ require 'graph/directed_graph'
48
+ ensure
49
+ $:.shift
50
+ end
51
+
52
+ require LIBDIR + 'util'
53
+ require LIBDIR + 'event'
54
+ require LIBDIR + 'fsm'
55
+ require LIBDIR + 'observer'
56
+ require LIBDIR + 'system'
57
+ require LIBDIR + 'dsl'
58
+
59
+ def self.new(*a, &b) FSM.new(*a, &b) end
60
+ def self.system(*a, &b) System.new(*a, &b) end
61
+
62
+ module ::Kernel
63
+ def FSM(*a, &b) ::FSM.new(*a, &b) end
64
+ def FSMSystem(*a, &b) ::FSM::System.new(*a, &b) end
65
+ end
66
+ #--}}}
67
+ end # module FSM
68
+
69
+ class Thread
70
+ def joinable
71
+ @joinable = false unless defined? @joinable
72
+ end
73
+ alias_method 'joinable?', 'joinable'
74
+ def joinable= bool
75
+ @joinable = bool ? true : false
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,81 @@
1
+
2
+ require 'fsm'
3
+ require 'fileutils'
4
+
5
+ stager = FSM.system
6
+ processer = FSM.system
7
+ archiver = FSM.system
8
+
9
+
10
+ stager.configure do
11
+ fsm{
12
+ states %w( empty full )
13
+ transition 'filling', 'empty' => 'full'
14
+ transition 'emptying', 'full' => 'empty'
15
+ }
16
+
17
+ observer{
18
+ on_entry 'empty' do
19
+ transition 'empty', 'filling' do
20
+ 2.times do |n|
21
+ FileUtils.touch "a/#{ n }"
22
+ puts "touch a/#{ n }"
23
+ end
24
+ end
25
+ end
26
+ }
27
+
28
+ start
29
+ end
30
+
31
+ processer.configure do
32
+ fsm{
33
+ states %w( empty processing full )
34
+ transition 'empty' => 'processing'
35
+ transition 'processing' => 'full'
36
+ transition 'full' => 'empty'
37
+ }
38
+
39
+ observer{
40
+ on_entry 'empty' do
41
+ stager.observer.wait_for 'full'
42
+ transition 'empty' do
43
+ Dir["a/*"].each do |path|
44
+ FileUtils.mv path, "b/"
45
+ puts "#{ path } -->> b/"
46
+ end
47
+ end
48
+ stager.transition 'full', 'emptying'
49
+ end
50
+
51
+ on_entry 'processing' do
52
+ transition 'processing' do
53
+ Dir["b/*"].each do |path|
54
+ FileUtils.mv path, "c/"
55
+ puts "#{ path } -->> c/"
56
+ end
57
+ end
58
+ end
59
+ }
60
+
61
+ start
62
+ end
63
+
64
+ archiver.configure do
65
+ fsm{
66
+ states %w( empty full )
67
+ transition 'filling', 'empty' => 'full'
68
+ transition 'emptying', 'full' => 'empty'
69
+ }
70
+
71
+ observer{
72
+ }
73
+
74
+ start
75
+ end
76
+
77
+
78
+ STDIN.gets
79
+
80
+
81
+
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: fsm
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.0
7
+ date: 2006-09-08 00:00:00.000000 -06:00
8
+ summary: fsm
9
+ require_paths:
10
+ - lib
11
+ email: ara.t.howard@noaa.gov
12
+ homepage: http://codeforpeople.com/lib/ruby/fsm/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: fsm
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ authors:
30
+ - Ara T. Howard
31
+ files:
32
+ - sample
33
+ - install.rb
34
+ - gemspec.rb
35
+ - lib
36
+ - instance_exec.rb
37
+ - sample/a.rb
38
+ - lib/fsm-0.0.0
39
+ - lib/fsm.rb
40
+ - lib/fsm-0.0.0.rb
41
+ - lib/fsm-0.0.0/fsm.rb
42
+ - lib/fsm-0.0.0/dsl.rb
43
+ - lib/fsm-0.0.0/graph
44
+ - lib/fsm-0.0.0/event.rb
45
+ - lib/fsm-0.0.0/util.rb
46
+ - lib/fsm-0.0.0/observer.rb
47
+ - lib/fsm-0.0.0/fsm.rb.bak
48
+ - lib/fsm-0.0.0/system.rb
49
+ - lib/fsm-0.0.0/graph/directed_graph.rb
50
+ - lib/fsm-0.0.0/graph/graphviz_dot.rb
51
+ - lib/fsm-0.0.0/graph/base_extensions.rb
52
+ test_files: []
53
+ rdoc_options: []
54
+ extra_rdoc_files: []
55
+ executables: []
56
+ extensions: []
57
+ requirements: []
58
+ dependencies: []