state_manager 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -40,6 +40,9 @@ module StateManager
40
40
  new_states = state.find_states(path)
41
41
  end
42
42
 
43
+ # The first time we enter a state, the state_manager gets entered as well
44
+ new_states.unshift(self) unless has_state?
45
+
43
46
  # Can only transition to leaf states
44
47
  # TODO: transition to the initial_state of the state?
45
48
  raise(InvalidTransition, path) unless new_states.last.leaf?
@@ -48,7 +51,9 @@ module StateManager
48
51
  exit_states = exit_states - new_states
49
52
 
50
53
  from_state = current_state
51
- to_state = enter_states.last
54
+ # TODO: does it make more sense to throw an error instead of allowing
55
+ # a transition to the current state?
56
+ to_state = enter_states.last || from_state
52
57
 
53
58
  # Before Callbacks
54
59
  will_transition(from_state, to_state, current_event)
@@ -102,7 +107,8 @@ module StateManager
102
107
  end
103
108
 
104
109
  def to_s
105
- "#{current_state.path}" if current_state
110
+ path = "#{current_state.path}" if current_state
111
+ "#<%s:0x%x:%s>" % [self.class, object_id, path]
106
112
  end
107
113
 
108
114
  # Returns true if the underlying object is in the state specified by the
@@ -118,6 +124,11 @@ module StateManager
118
124
  self.find_states(current_state.path).include? find_state(path)
119
125
  end
120
126
 
127
+ # Will not have a state if the state is invalid or nil
128
+ def has_state?
129
+ !!current_state
130
+ end
131
+
121
132
  # These methods can be overriden by an adapter
122
133
  def write_state(value)
123
134
  resource.send "#{self.class._state_property.to_s}=", value.path
@@ -3,5 +3,6 @@ require 'state_manager/base'
3
3
  require 'state_manager/helpers'
4
4
  require 'state_manager/dsl'
5
5
  require 'state_manager/resource'
6
+ require 'state_manager/serialization'
6
7
  require 'state_manager/adapters'
7
8
  require 'state_manager/plugins'
@@ -0,0 +1,13 @@
1
+ module StateManager
2
+ class Base
3
+ yaml_as "tag:grouptalent.com,2012:StateManager"
4
+
5
+ def self.yaml_new(klass, tag, val)
6
+ klass.new(val['resource'], val['context'])
7
+ end
8
+
9
+ def to_yaml_properties
10
+ ['@resource', '@context']
11
+ end
12
+ end
13
+ end
@@ -98,7 +98,7 @@ module StateManager
98
98
  def find_states(path)
99
99
  state = self
100
100
  parts = path.split('.')
101
- ret = [state]
101
+ ret = []
102
102
  parts.each do |name|
103
103
  state = state.states[name.to_sym]
104
104
  ret << state
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "state_manager"
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gordon Hempton"]
12
- s.date = "2012-06-09"
12
+ s.date = "2012-06-12"
13
13
  s.description = "Finite state machine implementation that keeps logic separate from model classes and supports sub-states."
14
14
  s.email = "ghempton@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "lib/state_manager/plugins.rb",
36
36
  "lib/state_manager/plugins/delayed_job.rb",
37
37
  "lib/state_manager/resource.rb",
38
+ "lib/state_manager/serialization.rb",
38
39
  "lib/state_manager/state.rb",
39
40
  "state_manager.gemspec",
40
41
  "test/adapters/active_record_test.rb",
data/test/basic_test.rb CHANGED
@@ -129,4 +129,11 @@ class BasicTest < Test::Unit::TestCase
129
129
  end
130
130
  end
131
131
 
132
+ def test_transition_to_current_state
133
+ @resource = PostWithInitialState.new
134
+ assert_state 'submitted.awaiting_review'
135
+ @resource.state_manager.transition_to('submitted.awaiting_review')
136
+ assert_state 'submitted.awaiting_review'
137
+ end
138
+
132
139
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: state_manager
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.5
5
+ version: 0.2.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gordon Hempton
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-06-09 00:00:00 Z
13
+ date: 2012-06-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -183,6 +183,7 @@ files:
183
183
  - lib/state_manager/plugins.rb
184
184
  - lib/state_manager/plugins/delayed_job.rb
185
185
  - lib/state_manager/resource.rb
186
+ - lib/state_manager/serialization.rb
186
187
  - lib/state_manager/state.rb
187
188
  - state_manager.gemspec
188
189
  - test/adapters/active_record_test.rb
@@ -205,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
206
  requirements:
206
207
  - - ">="
207
208
  - !ruby/object:Gem::Version
208
- hash: 696568598486714476
209
+ hash: -3482260086007933081
209
210
  segments:
210
211
  - 0
211
212
  version: "0"