stateology 0.1.6 → 0.1.8
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/README.markdown +3 -29
- data/lib/stateology.rb +5 -1
- metadata +1 -1
data/README.markdown
CHANGED
@@ -4,11 +4,13 @@ Stateology
|
|
4
4
|
*Clean and fast Object state transitions in Ruby using the Mixology C extension.*
|
5
5
|
|
6
6
|
Supports:
|
7
|
+
|
7
8
|
* Dynamic switching between states (mixing and unmixing modules)
|
8
|
-
* Clean DSL-style syntax
|
9
9
|
* Optional state\_entry() and state\_exit() hooks for each state (automatically called upon state entry and exit)
|
10
10
|
* support for subclassing of classes that include Stateology (see below)
|
11
11
|
* support for nested states, i.e states defined within other states
|
12
|
+
* Clean DSL-style syntax
|
13
|
+
* *NO MAGIC!* Stateology does not use any behind-the-scenes method aliasing nor does it make use of any hooks.
|
12
14
|
|
13
15
|
Use as in the following:
|
14
16
|
|
@@ -42,34 +44,10 @@ Use as in the following:
|
|
42
44
|
puts "exiting Angry state"
|
43
45
|
end
|
44
46
|
}
|
45
|
-
|
46
|
-
# methods declared outside a 'state' are not part of any state
|
47
|
-
|
48
|
-
def state_entry
|
49
|
-
puts "entering Default state"
|
50
|
-
end
|
51
|
-
|
52
|
-
def do_something
|
53
|
-
puts "stares at the ceiling"
|
54
|
-
end
|
55
|
-
|
56
|
-
def state_exit
|
57
|
-
puts "exiting Default state"
|
58
|
-
end
|
59
|
-
|
60
|
-
# if we want the state_entry to run on instantiation
|
61
|
-
# we must call it from the initialize method
|
62
|
-
def initialize
|
63
|
-
state_entry
|
64
|
-
end
|
65
|
-
|
66
47
|
end
|
67
48
|
|
68
49
|
s = Sample.new
|
69
50
|
|
70
|
-
# in no state
|
71
|
-
s.do_something #=> "stares at the ceiling"
|
72
|
-
|
73
51
|
# now switch to Happy state
|
74
52
|
s.state :Happy
|
75
53
|
s.do_something #=> "Pets a puppy"
|
@@ -78,10 +56,6 @@ Use as in the following:
|
|
78
56
|
s.state :Angry
|
79
57
|
s.do_something #=> "Kicks a puppy"
|
80
58
|
|
81
|
-
# now switch back to no state
|
82
|
-
s.state nil
|
83
|
-
s.do_something #=> "stares at the ceiling"
|
84
|
-
|
85
59
|
UPDATE:
|
86
60
|
|
87
61
|
* made it so subclasses can inherit states from their superclasses e.g
|
data/lib/stateology.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# stateology.rb
|
2
|
+
# (C) John Mair 2008
|
3
|
+
# This program is distributed under the terms of the MIT License
|
4
|
+
|
1
5
|
begin
|
2
6
|
require 'rubygems'
|
3
7
|
rescue LoadError
|
@@ -7,7 +11,7 @@ end
|
|
7
11
|
require 'mixology'
|
8
12
|
|
9
13
|
module Stateology
|
10
|
-
VERSION = "0.1.
|
14
|
+
VERSION = "0.1.8"
|
11
15
|
|
12
16
|
# alternative to 'nil'
|
13
17
|
Default = nil
|