argon 1.1.5 → 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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/argon.rb +15 -7
  3. data/lib/argon/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f853de6635b2fa7f7f2396dbd717b887db8551b4
4
- data.tar.gz: bde251e06db6bbca9139ffaca646324baf6b2292
3
+ metadata.gz: b09160785840c5182b6b589f4d5f54b0d63195a1
4
+ data.tar.gz: 5a41ae363e257e607726e453304da872849546b2
5
5
  SHA512:
6
- metadata.gz: a0c5d625c54084e0ef75160f1e898201c16bd96bd004aaccf672858b8fc190e2f8afe7abd9262e62e6c177bcf8c65683879f40646a519742021ede2079402278
7
- data.tar.gz: 77212e155468547c7fc3656ed6715b97184e8ee4b8b8b519b44a8bbe1c78245a882b169629504f95d0d5399877489a9e2fccc389b472b09fba4afa5aad391274
6
+ metadata.gz: a1f0d95b2405e163b88c8a07f7636fe9150fe8be919220ed97505efc1cc8bbe7d5dd3aff08cfc26c16960c6410703b1c1246e209699971e2d8afd76eae79ac5b
7
+ data.tar.gz: a6ff9a9fc30fafc0f44e9b4c7be3ddcbef2493f04c8b4878f13a5ac68b5deee39942396f6ef4f20cd1ca5df84d996a6db9543cf5894c78e2096a07be0f07f56d
@@ -103,11 +103,13 @@ module Argon
103
103
  end
104
104
  end
105
105
 
106
- raise Argon::Error.new("`on_successful_transition` must be a lambda of signature `(record:, from:, to:)`") if !on_successful_transition.nil? && !on_successful_transition.is_a?(Proc)
107
- raise Argon::Error.new("`on_successful_transition` must be a lambda of signature `(record:, from:, to:)`") if on_successful_transition.parameters.to_set != [[:keyreq, :record],[:keyreq, :from],[:keyreq, :to]].to_set
106
+ raise Argon::Error.new("`on_successful_transition` must be a boolean") unless [true, false].include?(on_successful_transition)
107
+ raise Argon::Error.new("`on_successful_transition` must be a method of signature `(field:, action:, from:, to:)`") if on_successful_transition && !self.instance_methods.include?(:on_successful_transition)
108
+ raise Argon::Error.new("`on_successful_transition` must be a method of signature `(field:, action:, from:, to:)`") if on_successful_transition && self.instance_method(:on_successful_transition).parameters.to_set != %i(field action from to).map{|f| [:keyreq, f] }.to_set
108
109
 
109
- raise Argon::Error.new("`on_failed_transition` must be a lambda of signature `(record:, from:, to:)`") if !on_failed_transition.nil? && !on_failed_transition.is_a?(Proc)
110
- raise Argon::Error.new("`on_failed_transition` must be a lambda of signature `(record:, from:, to:)`") if on_failed_transition.parameters.to_set != [[:keyreq, :record],[:keyreq, :from],[:keyreq, :to]].to_set
110
+ raise Argon::Error.new("`on_failed_transition` must be a boolean") unless [true, false].include?(on_failed_transition)
111
+ raise Argon::Error.new("`on_failed_transition` must be a method of signature `(field:, action:, from:, to:)`") if on_failed_transition && !self.instance_methods.include?(:on_failed_transition)
112
+ raise Argon::Error.new("`on_failed_transition` must be a method of signature `(field:, action:, from:, to:)`") if on_failed_transition && self.instance_method(:on_failed_transition).parameters.to_set != %i(field action from to).map{|f| [:keyreq, f] }.to_set
111
113
 
112
114
  events_list.each do |event_name|
113
115
  end
@@ -158,7 +160,9 @@ module Argon
158
160
  end
159
161
 
160
162
  if self.send(field) != from
161
- on_failed_transition.call(record: self, from: self.send(field), to: to)
163
+ if on_failed_transition
164
+ self.on_failed_transition(field: field, action: action, from: from, to: to)
165
+ end
162
166
  raise Argon::InvalidTransitionError.new("Invalid state transition")
163
167
  end
164
168
 
@@ -184,11 +188,15 @@ module Argon
184
188
  end
185
189
  end
186
190
  rescue => e
187
- on_failed_transition.call(record: self, from: self.send(field), to: to)
191
+ if on_failed_transition
192
+ self.on_failed_transition(field: field, action: action, from: from, to: to)
193
+ end
188
194
  raise e
189
195
  end
190
196
 
191
- on_successful_transition.call(record: self, from: from, to: to)
197
+ if on_successful_transition
198
+ self.on_successful_transition(field: field, action: action, from: from, to: to)
199
+ end
192
200
 
193
201
  unless after_lock_callback.nil?
194
202
  if args.empty?
@@ -1,3 +1,3 @@
1
1
  module Argon
2
- VERSION = "1.1.5"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: argon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajith Hussain
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-26 00:00:00.000000000 Z
11
+ date: 2018-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler