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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 952f7bc9e470346c073f9e6ea3a57dfe99cdd95c
4
- data.tar.gz: c3160957e7b0ab4084c17ca8df4e23eb2ab53717
3
+ metadata.gz: 54fe1db2c558071ebf31786937491e86fdb7f40f
4
+ data.tar.gz: de76dac91d7bfae85136997d46ef25f2e3dc5cd2
5
5
  SHA512:
6
- metadata.gz: 8179578162e736f2a85b4a24d0e8ad7f5d8b7662b0f4581ed8cf5cf962111d262e103d4867403a829e0aa5781fbdc5bbbc724f6f896c1cd06db1a68fb477fa39
7
- data.tar.gz: 9dba3437433e2ffd449623790055c8427d3a343d6cc99bc0bfd1854ca13a6e2cb558fbacf567e685e137421def9f140328e952d3d6c63a2e09a598bce2fe460f
6
+ metadata.gz: 5ef6dcf574eb6c1f0e6b2873989aec8411d2aa3281a8ea5bf56894aacc77d91fbe6d66cbebeff406ceed357b1b9b6ef1c8c342474f004ab8514e13a6c5397ed8
7
+ data.tar.gz: 03e6a03d97e62f050fd6f2f74f60938ae8efa97b7f84a8f60413b3943f4d0dc6deaaa9c6068fbe45b4dae72fe4ab801b584249ebd263643148ee77e126c6da57
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- transitionable (0.2.0)
4
+ transitionable (0.3.0)
5
5
  activesupport (~> 5.2)
6
6
 
7
7
  GEM
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
  ```
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Transitionable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.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 00:00:00.000000000 Z
11
+ date: 2018-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler