closed_loop 0.3.0 → 0.4.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
  SHA256:
3
- metadata.gz: 3ff1ecd4ed9a2bf4145dd0a74174f17323cce5aa80f23aaf4291de4870c74a61
4
- data.tar.gz: '07286939fcee7c4a1519ae88dc862706eca84b27bf508e313af9253c34e89b12'
3
+ metadata.gz: 215c8d6c36a00683966575960ce1ae019d418308ef9589b5acad9032eebc9b65
4
+ data.tar.gz: e0ada82086f7f9893b5439e4d2dcca9362a0042566a406dcf7d4a83c4a718cd7
5
5
  SHA512:
6
- metadata.gz: 6631a4bcdcc0a30e531e54d0ec843f09ea0b67f215a90c8447468770fdfab6ec19a333321c29f565e573d40d87e9fbfa22f360d3fcc834819674a41fceb3814c
7
- data.tar.gz: 76290f04f6f710986fdc50120c3817fb7196168cf1dc79bd2bc767157bf53671ad05f146ccba071e0b8820b91e43e1abfb5be7861dd3ae7b09f223075d08502c
6
+ metadata.gz: d128e66f02f90e054623afe177a02b42c021d63d61f78099f62e82901f9d3d9ba0eac8daedd4e632ce5646bf9eb1980ba0ffbf94520a07d527e8c7ee279bfb4e
7
+ data.tar.gz: bb0e34235ed7b41e1e4ecf650385fc93921b0a3100aca253845db35c12983d66bb196b485263630e817c15d1cad53158fc23a239aebc3e38e500c391e205fe91
@@ -20,25 +20,22 @@ module ClosedLoop
20
20
  end
21
21
 
22
22
  def transit!(target, user, to:, &block)
23
- available_transition = available_transitions(target, user).find do |transition|
24
- transition.from == target.status.to_sym && transition.to == to.to_sym
25
- end
23
+ transition = find_transition(target, user, to:)
26
24
 
27
- if available_transition&.available?(target, user)
28
- available_transition.perform!(target, user, &block)
29
- else
25
+ unless transition
30
26
  raise("Transition #{self.class} #{target.status}->#{to} for #{target.id} by #{user} not available!")
31
27
  end
28
+
29
+ transition.perform!(target, user, &block)
32
30
  end
33
31
 
34
32
  def transit(target, user, to:, attributes: {}, &block)
35
- available_transition = available_transitions(target, user).find do |transition|
36
- transition.from == target.status.to_sym && transition.to == to.to_sym
37
- end
33
+ transition = find_transition(target, user, to:)
34
+ transition&.perform(target, user, attributes, &block)
35
+ end
38
36
 
39
- if available_transition&.available?(target, user)
40
- available_transition.perform(target, user, attributes, &block)
41
- end
37
+ def find_transition(target, user, to:)
38
+ available_transitions(target, user).find { |transition| transition.to == to.to_sym }
42
39
  end
43
40
 
44
41
  def resolve_role(*args)
@@ -6,8 +6,8 @@ module ClosedLoop
6
6
  end
7
7
 
8
8
  def available?(target, user)
9
- role == machine.resolve_role(target, user) &&
10
- target.status.to_sym == from &&
9
+ Array(role).include?(machine.resolve_role(target, user)) &&
10
+ Array(from).include?(target.status.to_sym) &&
11
11
  none_constraints?(target, user)
12
12
  end
13
13
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClosedLoop
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: closed_loop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vilius Luneckas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-09 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler