davidlee-state-fu 0.0.1 → 0.0.2

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.textile CHANGED
@@ -146,28 +146,42 @@ exceptionally elegant API.
146
146
 
147
147
  h2. Getting started
148
148
 
149
- First up:
149
+ You can either clone the repository in the usual fashion (eg to
150
+ yourapp/vendor/plugins/state-fu), or use StateFu as a gem.
151
+
152
+ To install as a gem:
150
153
 
151
154
  <pre>
152
155
  <code>
153
- sudo gem install rspec rr activesupport
154
- rake
155
- rake spec:doc # generate specdocs
156
- rake doc # generate rdoc
157
- rake gem # build the gem
158
- rake gem:install # install it
156
+ gem install davidlee-state-fu -s http://gems.github.com
159
157
  </code>
160
158
  </pre>
161
- And have a peek in the specs folder or rdoc for usage / documentation.
162
159
 
163
- Now you can simply:
160
+ To require it in your ruby project:
161
+
162
+ <pre>
164
163
  <code>
165
- require 'state-fu'
164
+ require 'rubygems'
165
+ require 'state-fu'
166
166
  </code>
167
- and
167
+ </pre>
168
+
169
+ To install the dependencies for running specs:
170
+
171
+ <pre>
168
172
  <code>
169
- include StateFu
170
- </code> in any class you wish to make stateful.
173
+ sudo gem install rspec rr activesupport
174
+ rake # run the specs
175
+ rake spec:doc # generate specdocs
176
+ rake doc # generate rdocs
177
+ rake build # build the gem locally
178
+ rake install # install it
179
+ </code>
180
+ </pre>
181
+
182
+ Now you can simply <code>include StateFu</code> in any class you wish to make stateful.
183
+
184
+ The spec folder is currently the best source of documentation.
171
185
 
172
186
  If you have questions, feature request or ideas, please join the "google group":http://groups.google.com/group/state-fu
173
187
 
data/lib/state-fu.rb CHANGED
@@ -87,7 +87,6 @@ module StateFu
87
87
  end
88
88
 
89
89
  if __FILE__ == $0
90
- # run rake stuff (specs / doc )
91
- # load example_machine.rb
92
- # drop into irb
90
+ # drop into irb?
93
91
  end
92
+
@@ -2,7 +2,6 @@ module StateFu
2
2
  class Machine
3
3
  include Helper
4
4
 
5
-
6
5
  # meta-constructor; expects to be called via Klass.machine()
7
6
  def self.for_class(klass, name, options={}, &block)
8
7
  options.symbolize_keys!
@@ -21,12 +20,10 @@ module StateFu
21
20
  ## Instance Methods
22
21
  ##
23
22
 
24
- attr_reader :states, :events, :options, :helpers, :named_procs, :requirement_messages, :name
23
+ attr_reader :states, :events, :options, :helpers, :named_procs, :requirement_messages
25
24
 
26
25
  def initialize( name, options={}, &block )
27
- # TODO - @name isn't actually used anywhere yet except
28
- # in deep_clone - remove it?
29
- @name = name
26
+ # TODO - name isn't actually used anywhere yet - remove from constructor
30
27
  @states = [].extend( StateArray )
31
28
  @events = [].extend( EventArray )
32
29
  @helpers = [].extend( HelperArray )
@@ -35,10 +32,6 @@ module StateFu
35
32
  @options = options
36
33
  end
37
34
 
38
- def deep_clone()
39
- m = Machine.new( name, options.dup )
40
- end
41
-
42
35
  # merge the commands in &block with the existing machine; returns
43
36
  # a lathe for the machine.
44
37
  def apply!( &block )
@@ -151,6 +144,15 @@ module StateFu
151
144
  end
152
145
  end
153
146
 
147
+ def deep_copy()
148
+ # use Marshal as a poor man's x-ray photocopier
149
+ duplify = lambda { |o| Marshal.load Marshal.dump( o ) }
150
+ returning Machine.new( nil, duplify.call( options )) do |m|
151
+ @states.each { |s| m.states() << duplify.call(s) }
152
+ @events.each { |e| m.events() << duplify.call(e) }
153
+ end
154
+ end
155
+
154
156
  def inspect
155
157
  "#<#{self.class} ##{__id__} states=#{state_names.inspect} events=#{event_names.inspect} options=#{options.inspect}>"
156
158
  end
data/spec/helper.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  thisdir = File.expand_path(File.dirname(__FILE__))
3
- $: << thisdir << "#{thisdir}/../lib"
3
+
4
+ # ensure we require state-fu from lib, not gems
5
+ $LOAD_PATH.unshift( "#{thisdir}/../lib" )
6
+ require 'state-fu'
7
+ require 'no_stdout'
4
8
 
5
9
  require 'rubygems'
6
10
 
@@ -13,8 +17,7 @@ require 'rubygems'
13
17
  end
14
18
  end
15
19
 
16
- require 'state-fu'
17
- require File.join( thisdir, '..' , 'lib', 'no_stdout' )
20
+ # require 'state-fu'
18
21
 
19
22
  Spec::Runner.configure do |config|
20
23
  config.mock_with :rr
@@ -20,29 +20,21 @@ describe "Copying / cloning a Machine" do
20
20
  @copy = @original.clone
21
21
  end
22
22
 
23
- it "should update any event in the original when it's changed in the copy" do
23
+ it "should update a state or event in the original when it's changed in the copy" do
24
24
  @original.events[:goto_b].should == @copy.events[:goto_b]
25
25
  @copy.lathe do
26
- event :goto_b do |e|
27
- e.options[:wibble] = :updated
26
+ event( :goto_b, :wibble => :updated ) do
27
+ to :bee
28
+ end
29
+ state( :b, :picture => "Bee" ) do
28
30
  end
29
31
  end
30
32
  @copy. events[:goto_b].options[:wibble].should == :updated
31
33
  @original.events[:goto_b].options[:wibble].should == :updated
34
+ @copy. states[:b].options[:picture].should == 'Bee'
35
+ @original.states[:b].options[:picture].should == 'Bee'
32
36
  end
33
37
 
34
- it "should update any state in the original when it's changed in the copy" do
35
- @original.states[:a].should == @copy.states[:a]
36
- @copy.lathe do
37
- state :a do |s|
38
- s.options[:wibble] = :updated
39
- end
40
- end
41
- @copy. states[:a].options[:wibble].should == :updated
42
- @original.states[:a].options[:wibble].should == :updated
43
- end
44
-
45
- it "should update the original with any changes to options"
46
38
  it "should update the original with any changes to helpers"
47
39
  it "should update the original with any changes to named_procs"
48
40
  it "should update the original with any changes to requirement_messages"
@@ -58,34 +50,26 @@ describe "Copying / cloning a Machine" do
58
50
  event :goto_b, :to => :b
59
51
  end
60
52
  end
61
- @copy = @original.deep_clone
53
+ @copy = @original.deep_copy()
62
54
  end
63
55
 
64
- it "should NOT update any event in the original when it's changed in the copy" do
65
- pending
66
- @original.events[:goto_b].should == @copy.events[:goto_b]
56
+ it "should NOT update a state or event in the original when it's changed in the copy" do
57
+ @copy.states.map(&:name).should == @original.states.map(&:name)
58
+ @copy.events.map(&:name).should == @original.events.map(&:name)
59
+
67
60
  @copy.lathe do
68
- event :goto_b do |e|
69
- e.options[:wibble] = :updated
61
+ event( :goto_b, :wibble => :updated ) do
62
+ to :bee
63
+ end
64
+ state( :b, :picture => "Bee" ) do
70
65
  end
71
66
  end
72
67
  @copy. events[:goto_b].options[:wibble].should == :updated
73
68
  @original.events[:goto_b].options[:wibble].should == nil
69
+ @copy. states[:b].options[:picture].should == 'Bee'
70
+ @original.states[:b].options[:picture].should == nil
74
71
  end
75
72
 
76
- it "should NOT update any state in the original when it's changed in the copy" do
77
- pending
78
- @original.states[:a].should == @copy.states[:a]
79
- @copy.lathe do
80
- state :a do |s|
81
- s.options[:wibble] = :updated
82
- end
83
- end
84
- @copy. states[:a].options[:wibble].should == :updated
85
- @original.states[:a].options[:wibble].should == nil
86
- end
87
-
88
- it "should NOT update the original with any changes to options"
89
73
  it "should NOT update the original with any changes to helpers"
90
74
  it "should NOT update the original with any changes to named_procs"
91
75
  it "should NOT update the original with any changes to requirement_messages"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: davidlee-state-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Lee
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-04 00:00:00 -07:00
12
+ date: 2009-05-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -99,24 +99,24 @@ specification_version: 2
99
99
  summary: A rich library for state-oriented programming with state machines / workflows
100
100
  test_files:
101
101
  - spec/units/machine_spec.rb
102
+ - spec/units/method_factory_spec.rb
103
+ - spec/units/lathe_spec.rb
102
104
  - spec/units/sprocket_spec.rb
105
+ - spec/units/exceptions_spec.rb
103
106
  - spec/units/event_spec.rb
104
- - spec/units/lathe_spec.rb
107
+ - spec/units/fu_space_spec.rb
105
108
  - spec/units/binding_spec.rb
106
109
  - spec/units/state_spec.rb
107
- - spec/units/method_factory_spec.rb
108
- - spec/units/exceptions_spec.rb
109
- - spec/units/fu_space_spec.rb
110
- - spec/helper.rb
111
- - spec/integration/example_01_document_spec.rb
110
+ - spec/integration/example_02_string_spec.rb
111
+ - spec/integration/state_definition_spec.rb
112
+ - spec/integration/active_record_persistence_spec.rb
112
113
  - spec/integration/transition_spec.rb
113
- - spec/integration/class_accessor_spec.rb
114
- - spec/integration/instance_accessor_spec.rb
115
- - spec/integration/requirement_reflection_spec.rb
116
114
  - spec/integration/machine_duplication_spec.rb
117
- - spec/integration/state_definition_spec.rb
118
- - spec/integration/event_definition_spec.rb
119
115
  - spec/integration/sanity_spec.rb
120
- - spec/integration/active_record_persistence_spec.rb
121
- - spec/integration/example_02_string_spec.rb
116
+ - spec/integration/class_accessor_spec.rb
122
117
  - spec/integration/ex_machine_for_accounts_spec.rb
118
+ - spec/integration/instance_accessor_spec.rb
119
+ - spec/integration/event_definition_spec.rb
120
+ - spec/integration/example_01_document_spec.rb
121
+ - spec/integration/requirement_reflection_spec.rb
122
+ - spec/helper.rb