maintain 0.2.22 → 0.2.23

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.22
1
+ 0.2.23
@@ -8,7 +8,8 @@ module Maintain
8
8
 
9
9
  def on(maintainee, attribute, event, state, method, options)
10
10
  attribute_check = "#{attribute}#{"_was" if event == :exit}_#{state}?"
11
- maintainee.before_save method, :if => lambda {|instance|
11
+ hook_method = options[:after] ? :after : :before
12
+ maintainee.send("#{hook_method}_save", method, :if => lambda {|instance|
12
13
  if instance.send("#{attribute}_changed?") && instance.send(attribute_check)
13
14
  if options[:if]
14
15
  if options[:if].is_a?(Proc)
@@ -28,7 +29,7 @@ module Maintain
28
29
  else
29
30
  false
30
31
  end
31
- }
32
+ })
32
33
  end
33
34
 
34
35
  def read(instance, attribute)
@@ -86,7 +86,7 @@ module Maintain
86
86
  end
87
87
 
88
88
  def on(*args, &block)
89
- options = args.last.is_a?(Hash) ? args.pop : {}
89
+ options = {:when => :before}.merge(args.last.is_a?(Hash) ? args.pop : {})
90
90
  event, state = args.shift, args.shift
91
91
  method = args.shift
92
92
  if block_given?
data/maintain.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "maintain"
8
- s.version = "0.2.19"
8
+ s.version = "0.2.23"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Flip Sasser"]
12
- s.date = "2011-11-02"
12
+ s.date = "2012-08-21"
13
13
  s.description = "\n Maintain is a simple state machine mixin for Ruby objects. It supports comparisons, bitmasks,\n and hooks that really work. It can be used for multiple attributes and will always do its best to\n stay out of your way and let your code drive the machine, and not vice versa.\n "
14
14
  s.email = "flip@x451.com"
15
15
  s.extra_rdoc_files = [
@@ -51,7 +51,7 @@ Gem::Specification.new do |s|
51
51
  ]
52
52
  s.homepage = "http://github.com/flipsasser/maintain"
53
53
  s.require_paths = ["lib"]
54
- s.rubygems_version = "1.8.10"
54
+ s.rubygems_version = "1.8.24"
55
55
  s.summary = "A Ruby state machine that lets your code do the driving"
56
56
 
57
57
  if s.respond_to? :specification_version then
@@ -134,6 +134,7 @@ if proceed
134
134
  on :exit, :foo, :do_something_else
135
135
  on :enter, :bar, lambda { hello! }, :if => :run_hello?
136
136
  on :exit, :bar, lambda { hello! }, :unless => :run_hello?
137
+ on :enter, :bar, :show_my_id, :after => true
137
138
  end
138
139
 
139
140
  ActiveMaintainTest.class_eval do
@@ -156,6 +157,10 @@ if proceed
156
157
  def run_hello?
157
158
  @run_hello
158
159
  end
160
+
161
+ def show_my_id
162
+ puts id
163
+ end
159
164
  end
160
165
  end
161
166
 
@@ -212,6 +217,13 @@ if proceed
212
217
  active_maintain_test.status = :foo
213
218
  active_maintain_test.save
214
219
  end
220
+
221
+ it "should ONLY run the :bar / :show_my_id exit hook AFTER the record is saved" do
222
+ active_maintain_test = ActiveMaintainTest.new(:status => :foo)
223
+ active_maintain_test.status = :bar
224
+ active_maintain_test.should_receive(:puts).with(1)
225
+ active_maintain_test.save!
226
+ end
215
227
  end
216
228
 
217
229
  describe "named_scopes" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maintain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.22
4
+ version: 0.2.23
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
12
+ date: 2012-08-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "\n Maintain is a simple state machine mixin for Ruby objects.
15
15
  It supports comparisons, bitmasks,\n and hooks that really work. It can be