state_machina 0.1.1 → 0.1.3

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: 96e79a8445f5e634f2960c84426f8077c14a47d194b3c57aaf6c42d4af3f051a
4
- data.tar.gz: 5e468a6142945e806388559b25acd51de47e572a2db00f5e98031ed369515fe9
3
+ metadata.gz: f1ce6ace127413c5e3ea50cc6163740defad6f378f3485716cbbd8bcd1e301bd
4
+ data.tar.gz: a42a94cb064e593a95f9d4d13750ce3dc850e51b2882570749ca03b4df667c94
5
5
  SHA512:
6
- metadata.gz: 70ba62ffb247210651920127acb68c00db4d8e21acd5440f48c58d92f21ede835acb3cc6bf8bdc41027a25919b86ca5c8a4796280af7988a6f42906959f1c164
7
- data.tar.gz: 271323b162d7617010f34080d093efcaa588edfd80b60c481178a8aa3844d45df8a0a5d1728497e79f5550d9bc762f41529daedbc9560f3380f7a03f1aa2b7a3
6
+ metadata.gz: c50c65b8264fc4149a0560e3b2ac6cd3d53e6dab4dea14b5731cf50380917b003811a5b0cad2e808772dbc16eef0318601505fe36efe2373a7eadc8765b0aa0d
7
+ data.tar.gz: 415f21703f10b5d1094bb8c78972ea47a70a3f152be7d781e38901aee8be75a15229a7a5d088dfdc347ef41db10c58ec50f31c54d024f9d562dc20318a0dd07a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- state_machina (0.1.0)
4
+ state_machina (0.1.2)
5
5
  concurrent-ruby (< 2)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  coderay (1.1.3)
12
- concurrent-ruby (1.1.9)
12
+ concurrent-ruby (1.2.2)
13
13
  diff-lcs (1.5.0)
14
14
  method_source (1.0.0)
15
15
  parallel (1.21.0)
@@ -0,0 +1,18 @@
1
+ module StateMachina
2
+ module ExtendedIntegration
3
+ module ClassMethods
4
+ # Extends a machine on a model where the machine is already defined
5
+ def extend_machine(klass, machine_name = 'default')
6
+ model_name = StateMachina::Util.normalized_klass_to_name(klass)
7
+
8
+ yield(StateMachina::Registry.find_machine!(model_name, machine_name))
9
+ end
10
+
11
+ alias_method :extend_state_machine, :extend_machine
12
+ end
13
+
14
+ def self.included(model)
15
+ model.extend(StateMachina::ExtendedIntegration::ClassMethods)
16
+ end
17
+ end
18
+ end
@@ -1,9 +1,49 @@
1
1
  module StateMachina
2
2
  module Integration
3
+ module ClassMethods
4
+ # Defines a new machine on a model
5
+ def define_machine(machine_name = 'default', column_name: :state, metadata: {})
6
+ model_name = StateMachina::Util.normalized_klass_to_name(self)
7
+ machine = StateMachina::Machine.new(model_name, machine_name, column_name: column_name, metadata: metadata)
8
+
9
+ yield(StateMachina::Registry.register_machine(machine))
10
+ end
11
+
12
+ alias_method :define_state_machine, :define_machine
13
+
14
+ # Extends a machine on a model where the machine is already defined
15
+ def extend_machine(klass, machine_name = 'default')
16
+ model_name = StateMachina::Util.normalized_klass_to_name(klass)
17
+
18
+ yield(StateMachina::Registry.find_machine!(model_name, machine_name))
19
+ end
20
+
21
+ alias_method :extend_state_machine, :extend_machine
22
+
23
+ # Returns the defined machine on a model
24
+ def machine(machine_name = 'default')
25
+ model_name = StateMachina::Util.normalized_klass_to_name(self)
26
+
27
+ StateMachina::Registry.find_machine!(model_name, machine_name)
28
+ end
29
+
30
+ alias_method :state_machine, :machine
31
+
32
+ # Returns the defined machines on a model
33
+ def machines
34
+ model_name = StateMachina::Util.normalized_klass_to_name(self)
35
+
36
+ StateMachina::Registry.find_machines(model_name)
37
+ end
38
+
39
+ alias_method :state_machines, :machines
40
+ end
41
+
3
42
  def self.included(model)
4
- model.extend StateMachina::Definitions
43
+ model.extend(StateMachina::Integration::ClassMethods)
5
44
  end
6
45
 
46
+ # Returns the defined machine on a model instance
7
47
  def machine(machine_name = 'default')
8
48
  model_name = StateMachina::Util.normalized_klass_to_name(self.class)
9
49
 
@@ -14,6 +54,7 @@ module StateMachina
14
54
 
15
55
  alias_method :state_machine, :machine
16
56
 
57
+ # Returns the defined machines on a model instance
17
58
  def machines
18
59
  model_name = StateMachina::Util.normalized_klass_to_name(self.class)
19
60
 
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StateMachina
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/state_machina.rb CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  require "concurrent"
4
4
 
5
- require_relative "state_machina/definitions"
6
5
  require_relative "state_machina/event"
7
6
  require_relative "state_machina/events_collection"
7
+ require_relative "state_machina/extended_integration"
8
8
  require_relative "state_machina/integration"
9
9
  require_relative "state_machina/machine"
10
10
  require_relative "state_machina/registry"
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.1
4
+ version: 0.1.3
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-26 00:00:00.000000000 Z
11
+ date: 2023-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -56,9 +56,9 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - lib/state_machina.rb
59
- - lib/state_machina/definitions.rb
60
59
  - lib/state_machina/event.rb
61
60
  - lib/state_machina/events_collection.rb
61
+ - lib/state_machina/extended_integration.rb
62
62
  - lib/state_machina/integration.rb
63
63
  - lib/state_machina/machine.rb
64
64
  - lib/state_machina/registry.rb
@@ -1,26 +0,0 @@
1
- module StateMachina
2
- module Definitions
3
- def machine(machine_name = 'default', column_name: :state, metadata: {})
4
- model_name = StateMachina::Util.normalized_klass_to_name(self)
5
- machine = StateMachina::Machine.new(model_name, machine_name, column_name: column_name, metadata: metadata)
6
-
7
- yield(StateMachina::Registry.register_machine(machine))
8
- end
9
-
10
- alias_method :state_machine, :machine
11
-
12
- def extend_machine(klass, machine_name = 'default')
13
- model_name = StateMachina::Util.normalized_klass_to_name(klass)
14
-
15
- yield(StateMachina::Registry.find_machine!(model_name, machine_name))
16
- end
17
-
18
- alias_method :extend_state_machine, :extend_machine
19
-
20
- def find_machine(machine_name = 'default')
21
- model_name = StateMachina::Util.normalized_klass_to_name(self)
22
-
23
- StateMachina::Registry.find_machine!(model_name, machine_name)
24
- end
25
- end
26
- end