runcoderun-aasm 2.0.2.4 → 2.0.5

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
@@ -41,19 +41,19 @@ Here's a quick example highlighting some of the features.
41
41
  class Conversation
42
42
  include AASM
43
43
 
44
- aasm_initial_state :new
44
+ aasm_initial_state :unread
45
45
 
46
- aasm_state :new
46
+ aasm_state :unread
47
47
  aasm_state :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 => [:unread]
53
53
  end
54
54
 
55
55
  aasm_event :close do
56
- transitions :to => :closed, :from => [:read, :new]
56
+ transitions :to => :closed, :from => [:read, :unread]
57
57
  end
58
58
  end
59
59
 
data/Rakefile CHANGED
@@ -71,7 +71,7 @@ else
71
71
  Spec::Rake::SpecTask.new('cruise') do |t|
72
72
  t.spec_files = FileList['spec/**/*.rb']
73
73
  t.rcov = true
74
- t.rcov_opts = ['--exclude', 'spec', '--exclude', 'Library']
74
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'Library', '--exclude', 'rcov.rb']
75
75
  end
76
76
 
77
77
  desc "Run all examples"
data/lib/aasm.rb CHANGED
@@ -5,11 +5,14 @@ require File.join(File.dirname(__FILE__), 'persistence')
5
5
 
6
6
  module AASM
7
7
  def self.Version
8
- '2.0.2.4'
8
+ '2.0.5'
9
9
  end
10
10
 
11
11
  class InvalidTransition < RuntimeError
12
12
  end
13
+
14
+ class UndefinedState < RuntimeError
15
+ end
13
16
 
14
17
  def self.included(base) #:nodoc:
15
18
  # TODO - need to ensure that a machine is being created because
@@ -22,7 +25,7 @@ module AASM
22
25
 
23
26
  module ClassMethods
24
27
  def inherited(klass)
25
- AASM::StateMachine[klass] = AASM::StateMachine[self].dup
28
+ AASM::StateMachine[klass] = AASM::StateMachine[self].clone
26
29
  super
27
30
  end
28
31
 
@@ -117,7 +120,9 @@ module AASM
117
120
  end
118
121
 
119
122
  def aasm_state_object_for_state(name)
120
- self.class.aasm_states.find {|s| s == name}
123
+ obj = self.class.aasm_states.find {|s| s == name}
124
+ raise AASM::UndefinedState, "State :#{name} doesn't exist" if obj.nil?
125
+ obj
121
126
  end
122
127
 
123
128
  def aasm_fire_event(name, persist, *args)
@@ -37,10 +37,10 @@ module AASM
37
37
  base.send(:include, AASM::Persistence::ActiveRecordPersistence::ReadState) unless base.method_defined?(:aasm_read_state)
38
38
  base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteState) unless base.method_defined?(:aasm_write_state)
39
39
  base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence) unless base.method_defined?(:aasm_write_state_without_persistence)
40
-
40
+
41
41
  if base.respond_to?(:named_scope)
42
42
  base.extend(AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods)
43
-
43
+
44
44
  base.class_eval do
45
45
  class << self
46
46
  alias_method :aasm_state_without_named_scope, :aasm_state
@@ -48,7 +48,7 @@ module AASM
48
48
  end
49
49
  end
50
50
  end
51
-
51
+
52
52
  base.before_validation_on_create :aasm_ensure_initial_state
53
53
  end
54
54
 
@@ -119,7 +119,7 @@ module AASM
119
119
 
120
120
  # Returns the current aasm_state of the object. Respects reload and
121
121
  # any changes made to the aasm_state field directly
122
- #
122
+ #
123
123
  # Internally just calls <tt>aasm_read_state</tt>
124
124
  #
125
125
  # foo = Foo.find(1)
@@ -136,7 +136,7 @@ module AASM
136
136
  end
137
137
 
138
138
  private
139
-
139
+
140
140
  # Ensures that if the aasm_state column is nil and the record is new
141
141
  # that the initial state gets populated before validation on create
142
142
  #
@@ -160,7 +160,7 @@ module AASM
160
160
 
161
161
  module WriteStateWithoutPersistence
162
162
  # Writes <tt>state</tt> to the state column, but does not persist it to the database
163
- #
163
+ #
164
164
  # foo = Foo.find(1)
165
165
  # foo.aasm_current_state # => :opened
166
166
  # foo.close
@@ -179,7 +179,7 @@ module AASM
179
179
  module WriteState
180
180
  # Writes <tt>state</tt> to the state column and persists it to the database
181
181
  # using update_attribute (which bypasses validation)
182
- #
182
+ #
183
183
  # foo = Foo.find(1)
184
184
  # foo.aasm_current_state # => :opened
185
185
  # foo.close!
@@ -190,12 +190,12 @@ module AASM
190
190
  def aasm_write_state(state)
191
191
  old_value = read_attribute(self.class.aasm_column)
192
192
  write_attribute(self.class.aasm_column, state.to_s)
193
-
193
+
194
194
  unless self.save
195
195
  write_attribute(self.class.aasm_column, old_value)
196
196
  return false
197
197
  end
198
-
198
+
199
199
  true
200
200
  end
201
201
  end
@@ -212,17 +212,17 @@ module AASM
212
212
  # aasm_state :opened
213
213
  # aasm_state :closed
214
214
  # end
215
- #
215
+ #
216
216
  # foo = Foo.new
217
217
  # foo.current_state # => :opened
218
218
  # foo.close
219
219
  # foo.current_state # => :closed
220
- #
220
+ #
221
221
  # foo = Foo.find(1)
222
222
  # foo.current_state # => :opened
223
223
  # foo.aasm_state = nil
224
224
  # foo.current_state # => nil
225
- #
225
+ #
226
226
  # NOTE: intended to be called from an event
227
227
  #
228
228
  # This allows for nil aasm states - be sure to add validation to your model
@@ -238,8 +238,8 @@ module AASM
238
238
  module NamedScopeMethods
239
239
  def aasm_state_with_named_scope name, options = {}
240
240
  aasm_state_without_named_scope name, options
241
- self.named_scope name, :conditions => {self.aasm_column => name.to_s} unless self.scopes.include?(name)
242
- end
241
+ self.named_scope name, :conditions => {self.aasm_column => name.to_s} unless self.respond_to?(name)
242
+ end
243
243
  end
244
244
  end
245
245
  end
data/lib/state_machine.rb CHANGED
@@ -22,6 +22,12 @@ 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
+
25
31
  def create_state(name, options)
26
32
  @states << AASM::SupportingClasses::State.new(name, options) unless @states.include?(name)
27
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runcoderun-aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2.4
4
+ version: 2.0.5
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-09 00:00:00 -07:00
12
+ date: 2009-02-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15