transitionable 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +6 -0
- data/lib/transitionable.rb +4 -1
- data/lib/transitionable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54fe1db2c558071ebf31786937491e86fdb7f40f
|
4
|
+
data.tar.gz: de76dac91d7bfae85136997d46ef25f2e3dc5cd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ef6dcf574eb6c1f0e6b2873989aec8411d2aa3281a8ea5bf56894aacc77d91fbe6d66cbebeff406ceed357b1b9b6ef1c8c342474f004ab8514e13a6c5397ed8
|
7
|
+
data.tar.gz: 03e6a03d97e62f050fd6f2f74f60938ae8efa97b7f84a8f60413b3943f4d0dc6deaaa9c6068fbe45b4dae72fe4ab801b584249ebd263643148ee77e126c6da57
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -114,6 +114,12 @@ Provides 2 validation methods
|
|
114
114
|
event.validate_transition(target_state: 'new_state')
|
115
115
|
# => returns true or false
|
116
116
|
|
117
|
+
# optionally, validate_transition also yield an error object when transition is invalid.
|
118
|
+
event.validate_transition(target_state: 'new_state') do |error|
|
119
|
+
# You can do things like:
|
120
|
+
Airbrake.notify(error, attributes) # sends the error along with including model's attributes
|
121
|
+
end
|
122
|
+
|
117
123
|
event.validate_transition!(target_state: 'new_state')
|
118
124
|
# => returns true or raises Transitionable::InvalidStateTransition exception
|
119
125
|
```
|
data/lib/transitionable.rb
CHANGED
@@ -46,8 +46,11 @@ module Transitionable
|
|
46
46
|
matched_transition = machine[:transitions].detect do |transition|
|
47
47
|
transition[:from] == current_state && transition[:to] == target_state
|
48
48
|
end
|
49
|
-
return matched_transition.present?
|
49
|
+
return true if matched_transition.present?
|
50
|
+
yield(InvalidStateTransition.new(current_state, target_state)) if block_given?
|
51
|
+
return false
|
50
52
|
end
|
53
|
+
# raise error if can't find the provided target state
|
51
54
|
raise InvalidStateTransition.new(nil, target_state)
|
52
55
|
end
|
53
56
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transitionable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zino
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|