state_machina 0.1.6 → 0.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dafbf3b6c0e98deba3f63e96af9dc514736a486e1c899ef3160085141c987a95
4
- data.tar.gz: c243f44bf6bc3c1fed703a8233ad9afe8f712081b946a7f72e3a227d621e0567
3
+ metadata.gz: 3f0a424d08f9a7c3103b4e1eca3d27cda85089c72c25fecdceaad77bf4ba7ad1
4
+ data.tar.gz: 5eb6269265360180bc155872205765ae49574e593b1614ec003125ab8109c27a
5
5
  SHA512:
6
- metadata.gz: 685b1a4811ba9ce5949ade06712bb1381c88d4cec75d8677b125797e5095abc8b1de51f089450ac5e2cc335e829a2431251cf8f43924ca1fde074eee8b258360
7
- data.tar.gz: b6c32281cef34382ad98b978c9f2df9204b96e15e2ffea630fd3dabd8a88ff63a1b53944549f63a24d7a17fb20626a7a1ef2ddb36eb84635dd68b13a761f57ff
6
+ metadata.gz: 3f19e17c7e7ac1f8420027b727954bac2677878ef4c9bc2c8b9b8a17af09b9902b7d00f170d3eea7cab154caa90a0e13382a4237f4adbed5c2436f5958608bf5
7
+ data.tar.gz: ee4ba5d3bdc4aa9e4f6fa03612312a5f53215fdabf270d99d032a1e4ba73a72429dc45b1bc3166de030b34217c8c03288cf4458ce35a95b9dd16e5b32f0f00cf
data/Gemfile CHANGED
@@ -10,3 +10,5 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
+
14
+ gem "activesupport", "< 8", require: false
data/Gemfile.lock CHANGED
@@ -7,11 +7,19 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ activesupport (5.2.8.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
10
15
  ast (2.4.2)
11
16
  coderay (1.1.3)
12
17
  concurrent-ruby (1.2.3)
13
18
  diff-lcs (1.5.0)
19
+ i18n (1.14.5)
20
+ concurrent-ruby (~> 1.0)
14
21
  method_source (1.0.0)
22
+ minitest (5.22.3)
15
23
  parallel (1.21.0)
16
24
  parser (3.1.1.0)
17
25
  ast (~> 2.4.1)
@@ -47,14 +55,19 @@ GEM
47
55
  rubocop-ast (1.16.0)
48
56
  parser (>= 3.1.1.0)
49
57
  ruby-progressbar (1.11.0)
58
+ thread_safe (0.3.6)
59
+ tzinfo (1.2.11)
60
+ thread_safe (~> 0.1)
50
61
  unicode-display_width (2.1.0)
51
62
 
52
63
  PLATFORMS
53
64
  arm64-darwin-21
54
65
  arm64-darwin-22
66
+ arm64-darwin-23
55
67
  x86_64-darwin-20
56
68
 
57
69
  DEPENDENCIES
70
+ activesupport (< 8)
58
71
  pry (< 0.15)
59
72
  rake (~> 13.0)
60
73
  rspec (~> 3.0)
@@ -3,6 +3,8 @@ module StateMachina
3
3
  attr_reader :model_name, :name, :column_name, :metadata
4
4
  attr_accessor :model
5
5
 
6
+ delegate :before?, :before_inclusive?, :past?, :past_inclusive?, :between?, :between_inclusive?, to: :current_state
7
+
6
8
  def initialize(model_name, name, column_name: :state, metadata: {})
7
9
  @model_name = model_name
8
10
  @name = name.to_s
@@ -13,25 +13,25 @@ module StateMachina
13
13
  def before?(other_state_name)
14
14
  return false if machine.nil?
15
15
 
16
- !machine.states.before(machine.current_state_name).map(&:name).include?(other_state_name)
16
+ machine.states.before(other_state_name).map(&:name).include?(machine.current_state_name)
17
17
  end
18
18
 
19
19
  def before_inclusive?(other_state_name)
20
20
  return false if machine.nil?
21
21
 
22
- !machine.states.before_inclusive(machine.current_state_name).map(&:name).include?(other_state_name)
22
+ machine.states.before_inclusive(other_state_name).map(&:name).include?(machine.current_state_name)
23
23
  end
24
24
 
25
25
  def past?(other_state_name)
26
26
  return false if machine.nil?
27
27
 
28
- !machine.states.past(machine.current_state_name).map(&:name).include?(other_state_name)
28
+ machine.states.past(other_state_name).map(&:name).include?(machine.current_state_name)
29
29
  end
30
30
 
31
31
  def past_inclusive?(other_state_name)
32
32
  return false if machine.nil?
33
33
 
34
- !machine.states.past_inclusive(machine.current_state_name).map(&:name).include?(other_state_name)
34
+ machine.states.past_inclusive(other_state_name).map(&:name).include?(machine.current_state_name)
35
35
  end
36
36
 
37
37
  def between?(from_state_name, to_state_name)
@@ -21,7 +21,10 @@ module StateMachina
21
21
  end
22
22
 
23
23
  def before(state_name)
24
- to_a[..(index_by_name(state_name) - 1)]
24
+ index = index_by_name(state_name) - 1
25
+ return [] if index.negative?
26
+
27
+ to_a[..index]
25
28
  end
26
29
 
27
30
  def before_inclusive(state_name)
@@ -37,11 +40,17 @@ module StateMachina
37
40
  end
38
41
 
39
42
  def between(from_state_name, to_state_name)
40
- to_a[index_by_name(from_state_name)...index_by_name(to_state_name)]
43
+ indexes = [index_by_name(from_state_name), index_by_name(to_state_name)]
44
+ raise(ArgumentError, "to_state should be higher than from_state") if indexes != indexes.sort
45
+
46
+ to_a[indexes[0]...indexes[1]]
41
47
  end
42
48
 
43
49
  def between_inclusive(from_state_name, to_state_name)
44
- to_a[index_by_name(from_state_name)..index_by_name(to_state_name)]
50
+ indexes = [index_by_name(from_state_name), index_by_name(to_state_name)]
51
+ raise(ArgumentError, "to_state should be higher than from_state") if indexes != indexes.sort
52
+
53
+ to_a[indexes[0]..indexes[1]]
45
54
  end
46
55
 
47
56
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StateMachina
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
data/lib/state_machina.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "concurrent"
4
+ require "active_support/core_ext/module/delegation"
4
5
 
5
6
  require_relative "state_machina/event"
6
7
  require_relative "state_machina/events_collection"
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.6
4
+ version: 0.1.7
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: 2024-01-30 00:00:00.000000000 Z
11
+ date: 2024-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -68,7 +68,6 @@ files:
68
68
  - lib/state_machina/util.rb
69
69
  - lib/state_machina/version.rb
70
70
  - sig/state_machina.rbs
71
- - state_machina.gemspec
72
71
  homepage:
73
72
  licenses:
74
73
  - MIT
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/state_machina/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "state_machina"
7
- spec.version = StateMachina::VERSION
8
- spec.authors = ["Jan van der Pas"]
9
- spec.email = ["jan.vanderpas@beequip.nl"]
10
-
11
- spec.summary = "State machine supporting multiple machines per object"
12
- # spec.description = "TODO: Write a longer description or delete this line."
13
- # spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
16
-
17
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
-
19
- # spec.metadata["homepage_uri"] = spec.homepage
20
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
- end
29
- end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
-
34
- spec.add_dependency "concurrent-ruby", "< 2"
35
- spec.add_development_dependency "pry", "< 0.15"
36
- end