transitions 1.1.1 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34d3864fac5bd100f261d06295299b1d9b08acd3
4
- data.tar.gz: 41982c65bdea9c3b3aa1160c9ea6bcb2f2232a1d
3
+ metadata.gz: db4e533a8cede13eb9cbf2e0291f129374d8e59a
4
+ data.tar.gz: d1131c392f74131b23ce68d0204aebe8c5441b23
5
5
  SHA512:
6
- metadata.gz: e842c89b94f099b134ffd915b72142cea017338ba209cb4446ad8ebeaea12c7d1a4e3c50feaf1ac16d5fd6ace5073b252a8c09579aca9850db4551311949e6e3
7
- data.tar.gz: 7d383004c82e4ea0fad5ea92ac79d28050699774816737c315442532db8ee89437488b074e9b434a4c17bdb23ce4a23c4ec14eb5dac2003555e2d21c37ffddfe
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
@@ -1,3 +1,7 @@
1
+ # 1.2.0
2
+
3
+ * (atomaka) Allow timestamp to accept an array of timestamps
4
+
1
5
  # 1.1.1
2
6
 
3
7
  * (beornborn) use instance_exec for defining scope because @klass sometimes is resolved as nil
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 a Symbol*
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
@@ -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
- !@timestamp.nil?
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
- obj.send "#{timestamp_attribute_name(obj, next_state)}=", Time.now
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=(value)
88
- case value
89
- when String, Symbol, TrueClass
90
- @timestamp = value
91
- else
92
- fail ArgumentError, 'timestamp must be either: true, a String or a Symbol'
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
- timestamp == true ? default_timestamp_name(obj, next_state) : @timestamp
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
@@ -1,3 +1,3 @@
1
1
  module Transitions
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
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.1.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-05-02 00:00:00.000000000 Z
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: