eric-aasm 2.0.2.2 → 2.0.3

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.rdoc CHANGED
@@ -44,12 +44,13 @@ Here's a quick example highlighting some of the features.
44
44
  aasm_initial_state :new
45
45
 
46
46
  aasm_state :new
47
- aasm_state :read
47
+ aasm_state :read, :enter => :mark_thread_as_read
48
48
  aasm_state :closed
49
49
 
50
50
 
51
51
  aasm_event :view do
52
- transitions :to => :read, :from => [:new]
52
+ transitions :to => :read, :from => [:new],
53
+ :on_transition => :send_received_receipt, :guard => :user_authorized
53
54
  end
54
55
 
55
56
  aasm_event :close do
@@ -57,6 +58,29 @@ Here's a quick example highlighting some of the features.
57
58
  end
58
59
  end
59
60
 
61
+
62
+ == Explanation of transitions
63
+
64
+ The current state machine has the following process. If we were to call
65
+ <tt>Conversation#view!</tt>, we would get:
66
+
67
+ state:new
68
+ |
69
+ | <-- :exit called on state[new]
70
+ |
71
+ | <-- :guard called on state[read]
72
+ |
73
+ | <-- :on_transition called on state[read]
74
+ |
75
+ | <-- aasm_current_state set to "read"
76
+ |
77
+ | <-- :success called on state[read]
78
+ |
79
+ | <-- :enter called on state[read]
80
+ |
81
+ state:read
82
+
83
+
60
84
  = Other Stuff
61
85
 
62
86
  Author:: Scott Barron <scott at elitists dot net>
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ rescue Exception
14
14
  nil
15
15
  end
16
16
 
17
- if `ruby -Ilib -raasm -e "print AASM.Version"` =~ /([0-9.]+)$/
17
+ if `ruby -Ilib -rversion -e "print AASM::VERSION::STRING"` =~ /([0-9.]+)$/
18
18
  CURRENT_VERSION = $1
19
19
  else
20
20
  CURRENT_VERSION = '0.0.0'
data/lib/aasm.rb CHANGED
@@ -4,10 +4,6 @@ require File.join(File.dirname(__FILE__), 'state_machine')
4
4
  require File.join(File.dirname(__FILE__), 'persistence')
5
5
 
6
6
  module AASM
7
- def self.Version
8
- '0.0.2'
9
- end
10
-
11
7
  class InvalidTransition < RuntimeError
12
8
  end
13
9
 
@@ -18,14 +14,15 @@ module AASM
18
14
  base.extend AASM::ClassMethods
19
15
  AASM::Persistence.set_persistence(base)
20
16
  AASM::StateMachine[base] = AASM::StateMachine.new('')
21
- end
22
17
 
23
- module ClassMethods
24
- def inherited(klass)
25
- AASM::StateMachine[klass] = AASM::StateMachine[self].clone
26
- super
18
+ base.class_eval do
19
+ def base.inherited(klass)
20
+ AASM::StateMachine[klass] = AASM::StateMachine[self].dup
21
+ end
27
22
  end
23
+ end
28
24
 
25
+ module ClassMethods
29
26
  def aasm_initial_state(set_state=nil)
30
27
  if set_state
31
28
  AASM::StateMachine[self].initial_state = set_state
@@ -99,14 +96,11 @@ module AASM
99
96
  end
100
97
 
101
98
  private
102
- def set_aasm_current_state_with_persistence(state)
103
- save_success = true
99
+ def aasm_current_state_with_persistence=(state)
104
100
  if self.respond_to?(:aasm_write_state) || self.private_methods.include?('aasm_write_state')
105
- save_success = aasm_write_state(state)
101
+ aasm_write_state(state)
106
102
  end
107
- self.aasm_current_state = state if save_success
108
-
109
- save_success
103
+ self.aasm_current_state = state
110
104
  end
111
105
 
112
106
  def aasm_current_state=(state)
@@ -121,28 +115,26 @@ module AASM
121
115
  end
122
116
 
123
117
  def aasm_fire_event(name, persist, *args)
124
- aasm_state_object_for_state(aasm_current_state).call_action(:exit, self, *args)
118
+ aasm_state_object_for_state(aasm_current_state).call_action(:exit, self)
125
119
 
126
- new_state = self.class.aasm_events[name].fire(self, nil, *args)
120
+ new_state = self.class.aasm_events[name].fire(self, *args)
127
121
 
128
122
  unless new_state.nil?
129
- aasm_state_object_for_state(new_state).call_action(:enter, self, *args)
130
-
131
- persist_successful = true
132
123
  if persist
133
- persist_successful = set_aasm_current_state_with_persistence(new_state)
134
- self.class.aasm_events[name].execute_success_callback(self, *args) if persist_successful
124
+ self.aasm_current_state_with_persistence = new_state
135
125
  else
136
126
  self.aasm_current_state = new_state
137
127
  end
138
-
139
- if persist_successful
140
- self.aasm_event_fired(self.aasm_current_state, new_state) if self.respond_to?(:aasm_event_fired)
141
- else
142
- self.aasm_event_failed(name) if self.respond_to?(:aasm_event_failed)
128
+
129
+ self.send(self.class.aasm_events[name].success) if self.class.aasm_events[name].success
130
+
131
+ aasm_state_object_for_state(new_state).call_action(:enter, self)
132
+
133
+ if self.respond_to?(:aasm_event_fired)
134
+ self.aasm_event_fired(self.aasm_current_state, new_state)
143
135
  end
144
136
 
145
- persist_successful
137
+ true
146
138
  else
147
139
  if self.respond_to?(:aasm_event_failed)
148
140
  self.aasm_event_failed(name)
data/lib/event.rb CHANGED
@@ -19,7 +19,7 @@ module AASM
19
19
  next_state = nil
20
20
  transitions.each do |transition|
21
21
  next if to_state and !Array(transition.to).include?(to_state)
22
- if transition.perform(obj, *args)
22
+ if transition.perform(obj)
23
23
  next_state = to_state || Array(transition.to).first
24
24
  transition.execute(obj, *args)
25
25
  break
@@ -32,17 +32,6 @@ module AASM
32
32
  @transitions.any? { |t| t.from == state }
33
33
  end
34
34
 
35
- def execute_success_callback(obj, *args)
36
- case success
37
- when String, Symbol:
38
- obj.send(success, *args)
39
- when Array:
40
- success.each { |meth| obj.send(meth, *args) }
41
- when Proc:
42
- success.call(obj, *args)
43
- end
44
- end
45
-
46
35
  private
47
36
  def transitions(trans_opts)
48
37
  Array(trans_opts[:from]).each do |s|
@@ -188,15 +188,7 @@ module AASM
188
188
  #
189
189
  # NOTE: intended to be called from an event
190
190
  def aasm_write_state(state)
191
- old_value = read_attribute(self.class.aasm_column)
192
- write_attribute(self.class.aasm_column, state.to_s)
193
-
194
- unless self.save
195
- write_attribute(self.class.aasm_column, old_value)
196
- return false
197
- end
198
-
199
- true
191
+ update_attribute(self.class.aasm_column, state.to_s)
200
192
  end
201
193
  end
202
194
 
data/lib/state.rb CHANGED
@@ -15,13 +15,13 @@ module AASM
15
15
  end
16
16
  end
17
17
 
18
- def call_action(action, record, *args)
18
+ def call_action(action, record)
19
19
  action = @options[action]
20
20
  case action
21
21
  when Symbol, String
22
- record.send(action, *args)
22
+ record.send(action)
23
23
  when Proc
24
- action.call(record, *args)
24
+ action.call(record)
25
25
  end
26
26
  end
27
27
 
data/lib/state_machine.rb CHANGED
@@ -22,12 +22,6 @@ module AASM
22
22
  @config = OpenStruct.new
23
23
  end
24
24
 
25
- def clone
26
- klone = super
27
- klone.states = states.clone
28
- klone
29
- end
30
-
31
25
  def create_state(name, options)
32
26
  @states << AASM::SupportingClasses::State.new(name, options) unless @states.include?(name)
33
27
  end
@@ -8,12 +8,12 @@ module AASM
8
8
  @opts = opts
9
9
  end
10
10
 
11
- def perform(obj, *args)
11
+ def perform(obj)
12
12
  case @guard
13
13
  when Symbol, String
14
- obj.send(@guard, *args)
14
+ obj.send(@guard)
15
15
  when Proc
16
- @guard.call(obj, *args)
16
+ @guard.call(obj)
17
17
  else
18
18
  true
19
19
  end
data/lib/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ module AASM
2
+ module VERSION
3
+ STRING = '2.0.2'
4
+ end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eric-aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Barron
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-27 00:00:00 -07:00
12
+ date: 2008-08-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -37,6 +37,7 @@ files:
37
37
  - lib/state.rb
38
38
  - lib/state_machine.rb
39
39
  - lib/state_transition.rb
40
+ - lib/version.rb
40
41
  - doc/jamis.rb
41
42
  has_rdoc: true
42
43
  homepage: http://github.com/rubyist/aasm