foobara 0.0.67 → 0.0.69

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: a1f1ab51b7a473c588672377efea95913afc3c0f09a73a6cf34ec0133d6b9d5a
4
- data.tar.gz: b57286cf4ae31aa411b834b242055d0d8fc03f7acea41fa5a5d763e62fe02e11
3
+ metadata.gz: f6aa740f8aa8c058877cd14db7cf69efdd0509bf39e790d7806d7e4f50309db3
4
+ data.tar.gz: 38fe1c5a5613cc0811d50c19209360f13d507a1dc0ef90d7208103940c6f4d1b
5
5
  SHA512:
6
- metadata.gz: eb4ac756719ec1ce5f7953da955c02b30a59574604f3d627a9cfa57734828af9c246fa60d671dc5cfd52687371c01fca4a1d0de8ce7c165686e4272eecbef74f
7
- data.tar.gz: 867819ea9493b906f0d10d7f44cfe10bfe4370869172fba4682ebf8af2eaccf7a26e9fbe89e84b71a3177b822fe5d897362dbe419f73c79d7f2857d197bb6431
6
+ metadata.gz: 5c0b2ffa28dfadc479c34a86b212079b4ed49bab0506a49db213d9bb50b9d709e883c50208b5b28a86dffcf80f583d0cb2e3baad32536e680605f46529c10d71
7
+ data.tar.gz: c05caa4fd88b37c7b02bf522d965a550fe57e85d5382d98a81c3b7d970f6f091f7784e5069d0135c6694b757322d36c86770ab0fa3b5e832d930a548bd3becaa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.69] - 2025-03-03
2
+
3
+ - Allow StateMachine to use an attribute on another object as its current state for convenience
4
+
5
+ ## [0.0.68] - 2025-02-28
6
+
7
+ - Make use of LruCache for performance boost when converting type declarations to types
8
+
1
9
  ## [0.0.67] - 2025-02-26
2
10
 
3
11
  - Convert / to _ when building constant names in Enumerated::Values
@@ -63,6 +63,8 @@ module Foobara
63
63
  attr_writer :foobara_domain_name, :foobara_full_domain_name
64
64
 
65
65
  def foobara_unregister(scoped)
66
+ foobara_type_builder.clear_cache
67
+
66
68
  if scoped.is_a?(Foobara::Types::Type)
67
69
  parent_mod = nil
68
70
 
@@ -61,6 +61,7 @@ module Foobara
61
61
  return 0 if type.nil?
62
62
  return 9 if type == value
63
63
 
64
+ # TODO: This .process_value call is slow
64
65
  return 5 if type.applicable?(value) && type.process_value(value).success?
65
66
 
66
67
  if value.is_a?(Types::Type)
@@ -3,11 +3,9 @@ module Foobara
3
3
  module Callbacks
4
4
  include Concern
5
5
 
6
- # owner helps with determining the relevant object when running class-registered state transition callbacks
7
- attr_accessor :callback_registry, :owner
6
+ attr_accessor :callback_registry
8
7
 
9
- def initialize(owner: nil)
10
- self.owner = owner
8
+ def initialize(...)
11
9
  self.callback_registry = Callback::Registry::ChainedConditioned.new(self.class.class_callback_registry)
12
10
  end
13
11
 
@@ -34,12 +34,36 @@ module Foobara
34
34
  end
35
35
  end
36
36
 
37
- attr_accessor :current_state
37
+ attr_accessor :target_attribute, :owner
38
+
39
+ # owner is optional. It can help with certain callbacks. It's also required if planning to use the target_attribute
40
+ # feature
41
+ def initialize(*args, owner: nil, target_attribute: nil, **options)
42
+ self.owner = owner
38
43
 
39
- def initialize(*args, **options)
40
44
  super
41
45
 
42
- self.current_state = self.class.initial_state
46
+ if target_attribute
47
+ self.target_attribute = target_attribute
48
+ else
49
+ self.current_state = self.class.initial_state
50
+ end
51
+ end
52
+
53
+ def current_state
54
+ if target_attribute
55
+ owner.send(target_attribute) || self.class.initial_state
56
+ else
57
+ @current_state
58
+ end
59
+ end
60
+
61
+ def current_state=(state)
62
+ if target_attribute
63
+ owner.send("#{target_attribute}=", state)
64
+ else
65
+ @current_state = state
66
+ end
43
67
  end
44
68
 
45
69
  def perform_transition!(transition, &block)
@@ -5,7 +5,7 @@ module Foobara
5
5
 
6
6
  attr_accessor :log
7
7
 
8
- def initialize(*args, **options)
8
+ def initialize(...)
9
9
  super
10
10
 
11
11
  self.log = []
@@ -1,3 +1,5 @@
1
+ require "foobara/lru_cache"
2
+
1
3
  module Foobara
2
4
  module TypeDeclarations
3
5
  class TypeBuilder
@@ -63,6 +65,12 @@ module Foobara
63
65
  end
64
66
 
65
67
  def type_for_declaration(*type_declaration_bits, &block)
68
+ lru_cache.cached([type_declaration_bits, block]) do
69
+ type_for_declaration_without_cache(*type_declaration_bits, &block)
70
+ end
71
+ end
72
+
73
+ def type_for_declaration_without_cache(*type_declaration_bits, &block)
66
74
  type_declaration = if block
67
75
  unless type_declaration_bits.empty?
68
76
  # :nocov:
@@ -88,8 +96,18 @@ module Foobara
88
96
  handler.process_value!(type_declaration)
89
97
  end
90
98
 
99
+ def clear_cache
100
+ if @lru_cache
101
+ lru_cache.reset!
102
+ end
103
+ end
104
+
91
105
  private
92
106
 
107
+ def lru_cache
108
+ @lru_cache ||= Foobara::LruCache.new(100)
109
+ end
110
+
93
111
  def type_declaration_bits_to_type_declaration(type_declaration_bits)
94
112
  type, *symbolic_processors, processor_data = type_declaration_bits
95
113
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.67
4
+ version: 0.0.69
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-26 00:00:00.000000000 Z
10
+ date: 2025-03-04 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: foobara-lru-cache
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: foobara-util
28
42
  requirement: !ruby/object:Gem::Requirement