transitions 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.todo.reek +14 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/lib/transitions/event.rb +16 -11
- data/lib/transitions/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db4e533a8cede13eb9cbf2e0291f129374d8e59a
|
4
|
+
data.tar.gz: d1131c392f74131b23ce68d0204aebe8c5441b23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 089e9d32d55496832507a763c7a4dfffb4b0df01489d84828b78637eb66887cb33131856d0e72025088530c932809b52498638d34539d615c1fc62cee94e70cc
|
7
|
+
data.tar.gz: cd7f5928d0d86d90d9f43ccc5d33b1e5003931f20fe12d928572d5922647c74504dbb23b13eaeadbf07a676a9167809184e338d885065b93f78c626b7252fcdc
|
data/.todo.reek
CHANGED
@@ -4,15 +4,11 @@ DuplicateMethodCall:
|
|
4
4
|
- ActiveModel::Transitions#read_state
|
5
5
|
- ActiveModel::Transitions#reload
|
6
6
|
- ActiveModel::Transitions#set_initial_state
|
7
|
-
- ActiveModel::Transitions#set_initial_state
|
8
7
|
- Transitions::Event#error_message_for_invalid_transitions
|
9
8
|
- Transitions::Event#fire
|
10
|
-
- Transitions::Event#fire
|
11
|
-
- Transitions::Event#initialize
|
12
9
|
- Transitions::Event#initialize
|
13
10
|
- Transitions::Event#update
|
14
11
|
- Transitions::Machine#handle_event_success_callback
|
15
|
-
- Transitions::Machine#handle_event_success_callback
|
16
12
|
- Transitions::Machine#initial_state
|
17
13
|
- Transitions::State#define_state_query_method
|
18
14
|
IrresponsibleModule:
|
@@ -46,6 +42,19 @@ FeatureEnvy:
|
|
46
42
|
- Transitions::Event#can_execute_transition_from_state?
|
47
43
|
- Transitions::Event#default_timestamp_name
|
48
44
|
- Transitions::Event#error_message_for_invalid_transitions
|
45
|
+
InstanceVariableAssumption:
|
46
|
+
exclude:
|
47
|
+
- Transitions::Event
|
48
|
+
- Transitions::Machine
|
49
|
+
- Transitions::State
|
50
|
+
ManualDispatch:
|
51
|
+
exclude:
|
52
|
+
- Transitions::Event#default_timestamp_name
|
53
|
+
- Transitions::Machine#fire_event
|
54
|
+
- Transitions::Machine#handle_event_failed_callback
|
55
|
+
- Transitions::Machine#handle_event_fired_callback
|
56
|
+
- Transitions::Machine#include_scopes
|
57
|
+
- Transitions::StateTransition#perform_guard
|
49
58
|
NestedIterators:
|
50
59
|
exclude:
|
51
60
|
- Transitions::Event#build_success_callback
|
@@ -56,6 +65,7 @@ TooManyInstanceVariables:
|
|
56
65
|
- Transitions::StateTransition
|
57
66
|
TooManyStatements:
|
58
67
|
exclude:
|
68
|
+
- initialize
|
59
69
|
- Transitions::Event#build_success_callback
|
60
70
|
- Transitions::Event#fire
|
61
71
|
- Transitions::Machine#fire_event
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -300,7 +300,8 @@ corresponding discussion).
|
|
300
300
|
If you'd like to note the time of a state change, Transitions comes with
|
301
301
|
timestamps free! To activate them, simply pass the `timestamp` option to the
|
302
302
|
event definition with a value of either true or the name of the timestamp
|
303
|
-
column. *NOTE - This should be either true, a String or
|
303
|
+
column. *NOTE - This should be either true, a String, a Symbol, or an Array of
|
304
|
+
these*
|
304
305
|
```ruby
|
305
306
|
# This will look for an attribute called exploded_at or exploded_on (in that order)
|
306
307
|
# If present, it will be updated
|
data/lib/transitions/event.rb
CHANGED
@@ -8,6 +8,7 @@ module Transitions
|
|
8
8
|
@machine = machine
|
9
9
|
@name = name
|
10
10
|
@transitions = []
|
11
|
+
@timestamps = []
|
11
12
|
if machine
|
12
13
|
machine.klass.send(:define_method, "#{name}!") do |*args|
|
13
14
|
machine.fire_event(name, self, true, *args)
|
@@ -67,29 +68,33 @@ module Transitions
|
|
67
68
|
|
68
69
|
# Has the timestamp option been specified for this event?
|
69
70
|
def timestamp_defined?
|
70
|
-
!@
|
71
|
+
!@timestamps.nil?
|
71
72
|
end
|
72
73
|
|
73
74
|
def update(options = {}, &block)
|
74
75
|
@success = build_success_callback(options[:success]) if options.key?(:success)
|
75
|
-
self.timestamp = options[:timestamp] if options[:timestamp]
|
76
|
+
self.timestamp = Array(options[:timestamp]) if options[:timestamp]
|
76
77
|
instance_eval(&block) if block
|
77
78
|
self
|
78
79
|
end
|
79
80
|
|
80
81
|
# update the timestamp attribute on obj
|
81
82
|
def update_event_timestamp(obj, next_state)
|
82
|
-
|
83
|
+
@timestamps.each do |timestamp|
|
84
|
+
obj.public_send "#{timestamp_attribute_name(obj, next_state, timestamp)}=", Time.now
|
85
|
+
end
|
83
86
|
end
|
84
87
|
|
85
88
|
# Set the timestamp attribute.
|
86
89
|
# @raise [ArgumentError] timestamp should be either a String, Symbol or true
|
87
|
-
def timestamp=(
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
def timestamp=(values)
|
91
|
+
values.each do |value|
|
92
|
+
case value
|
93
|
+
when String, Symbol, TrueClass
|
94
|
+
@timestamps << value
|
95
|
+
else
|
96
|
+
fail ArgumentError, 'timestamp must be either: true, a String or a Symbol'
|
97
|
+
end
|
93
98
|
end
|
94
99
|
end
|
95
100
|
|
@@ -98,8 +103,8 @@ module Transitions
|
|
98
103
|
# Returns the name of the timestamp attribute for this event
|
99
104
|
# If the timestamp was simply true it returns the default_timestamp_name
|
100
105
|
# otherwise, returns the user-specified timestamp name
|
101
|
-
def timestamp_attribute_name(obj, next_state)
|
102
|
-
|
106
|
+
def timestamp_attribute_name(obj, next_state, user_timestamp)
|
107
|
+
user_timestamp == true ? default_timestamp_name(obj, next_state) : user_timestamp
|
103
108
|
end
|
104
109
|
|
105
110
|
# If @timestamp is true, try a default timestamp name
|
data/lib/transitions/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transitions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timo Rößner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -201,4 +201,3 @@ signing_key:
|
|
201
201
|
specification_version: 4
|
202
202
|
summary: State machine extracted from ActiveModel
|
203
203
|
test_files: []
|
204
|
-
has_rdoc:
|