progressive 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64289288aa2a2161424c2f7e917358fb6ecbd49e
4
- data.tar.gz: ad002250254baacb97690247cd5ee6fc89348e0a
3
+ metadata.gz: 950a9e588f18cdf8b6c8e3096c2786f0ef1d8f86
4
+ data.tar.gz: 0d382df9f963fcf7bd29cfee79361a922c132865
5
5
  SHA512:
6
- metadata.gz: a2dcc8a2730c54a7af80ecb691b7a3a5bff4fbf0c38c51545ee9af1f49e1c4b67c0236972462dd95b39bfe0daa9db0880aeb4176e586e8f83b7d6b14a83eb6d4
7
- data.tar.gz: f23dd3192472187b93046ee3191d2ae94fff61160d0770feaa399f8305860e41e8bcc43c04aef7b749406ca146ec7c064d4a491acedac61e56d6627284c765e0
6
+ metadata.gz: 3cb78e9cd695073da8674e8fa3c3c51eabd891ea96c4bedcc39e51b858501452dabbd90ea940a3b2b96110e91a456623035b13ee1797a699207930ea9860d7dd
7
+ data.tar.gz: 8178a0b45cb87205cb94374cdeb8afcda2ce6fa7945e7316b03a2831798d690dc1f96c9c0c2dfe073c3611109d8bf93b7d4a80ce21c7d4815b7289774379c90c
@@ -51,6 +51,7 @@ module Progressive
51
51
  # Returns nothing.
52
52
  def to(event, options = {})
53
53
  return false unless current_state.event?(event)
54
+ new_record = !!options.delete(:new_record) || subject.new_state_record_on_change?
54
55
 
55
56
  current_event = current_state.events[event]
56
57
 
@@ -62,7 +63,17 @@ module Progressive
62
63
 
63
64
  subject.run_callbacks(:progress) do
64
65
  subject.run_callbacks(current_event.name) do
65
- update_attribute(:state, current_event.to)
66
+ if new_record
67
+ record = dup
68
+ record.state = current_event.to
69
+ if record.save
70
+ record
71
+ else
72
+ false
73
+ end
74
+ else
75
+ update_attribute(:state, current_event.to)
76
+ end
66
77
  end
67
78
  end
68
79
  ensure
@@ -6,12 +6,6 @@ module Progressive
6
6
  extend ActiveSupport::Concern
7
7
  include ActiveModel::Callbacks
8
8
 
9
- included do
10
- define_model_callbacks :progress, only: [:before, :after]
11
-
12
- attr_accessor :event_context
13
- end
14
-
15
9
  module ClassMethods
16
10
  # Public: Define the different states and events the subject can go through.
17
11
  #
@@ -35,8 +29,21 @@ module Progressive
35
29
  end
36
30
  end
37
31
 
32
+ included do
33
+ define_model_callbacks :progress, only: [:before, :after]
34
+
35
+ attr_accessor :event_context
36
+
37
+ class_attribute :new_state_record_on_change
38
+ self.new_state_record_on_change = false
39
+ end
40
+
38
41
  def specification
39
42
  self.class.specification
40
43
  end
44
+
45
+ def new_state_record_on_change?
46
+ !!self.class.new_state_record_on_change
47
+ end
41
48
  end
42
49
  end
@@ -1,3 +1,3 @@
1
1
  module Progressive
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - dewski