aasm 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
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/lib/aasm.rb CHANGED
@@ -5,7 +5,7 @@ require File.join(File.dirname(__FILE__), 'persistence')
5
5
 
6
6
  module AASM
7
7
  def self.Version
8
- '2.0.4'
8
+ '2.0.5'
9
9
  end
10
10
 
11
11
  class InvalidTransition < RuntimeError
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Barron