state_machina 0.1.2 → 0.1.4

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: 72088dda2911712eec95b2a4915a9c62375cf43cfdde49338d58c32d448e108a
4
- data.tar.gz: de86ad656d1abb2d6fd06d32dfc49e8030a2dfde4413194adafecfe679c086c3
3
+ metadata.gz: f91cfe9ff343cb7dfb2634ecc825a061ad776661216de23a6e04e8824710d959
4
+ data.tar.gz: d8363c7847375ec9b9c95d52804017be4aa27fce82cc656a1e7102b4287ab423
5
5
  SHA512:
6
- metadata.gz: a9f9d175b449b71693ccb0c879d7022831dbdc90aa6e5efd38d16961090bc235ba28e6952b9f8e4989ec5b1a5cf5ac00994bcdad79d01200fa48a13f1486ab28
7
- data.tar.gz: 4fee723a2a9372cffd177c492c901b0e40aeb9d04025f2514e72dfb04b64929eaa8c572b10fb0ba4f3b1a8ed44d61adc7c90385f38fbec6c83e00f3cb1aded17
6
+ metadata.gz: 118bed2d86e7f529bd5c395d5a0d988aa29b7fc1532bd989442e97f014a7410df632188c36b7350337c144a487497c9848218442458fe7a9672ac5dc45fd0772
7
+ data.tar.gz: ff587876b7a1f2de84f9b573e044bd17ec0c5dde8a99c662291753fc9fac0bb4859897a390deadad5f55b76b535644d05dbf41df454e295f062dc1fb36ed7de1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- state_machina (0.1.1)
4
+ state_machina (0.1.4)
5
5
  concurrent-ruby (< 2)
6
6
 
7
7
  GEM
@@ -60,6 +60,14 @@ module StateMachina
60
60
  end
61
61
  end
62
62
 
63
+ def update_state!(new_state)
64
+ if model.respond_to?(:update!)
65
+ model.update!(column_name => new_state)
66
+ else
67
+ model.public_send("#{column_name}=", new_state)
68
+ end
69
+ end
70
+
63
71
  private
64
72
 
65
73
  def select_possible_events(events)
@@ -9,7 +9,7 @@ module StateMachina
9
9
  end
10
10
 
11
11
  def self.find_machine!(model_name, machine_name)
12
- machines.fetch(model_name.to_s, {}).fetch(machine_name.to_s) || raise(NoMachineFoundError, "for model: #{model_name}, with name: #{machine_name}")
12
+ machines.fetch(model_name.to_s, {}).fetch(machine_name.to_s, nil) || raise(NoMachineFoundError, "for model: #{model_name}, with name: #{machine_name}")
13
13
  end
14
14
 
15
15
  def self.register_machine(machine)
@@ -21,6 +21,7 @@ module StateMachina
21
21
  end
22
22
 
23
23
  def permitted?
24
+ return false unless possible?
24
25
  return true if guard.nil?
25
26
  return false if guard_context.nil?
26
27
 
@@ -43,5 +44,11 @@ module StateMachina
43
44
 
44
45
  machine.update_state(to_state_name)
45
46
  end
47
+
48
+ def execute!
49
+ return false if machine.nil?
50
+
51
+ machine.update_state!(to_state_name)
52
+ end
46
53
  end
47
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StateMachina
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan van der Pas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-27 00:00:00.000000000 Z
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby