ask-graph 0.3.0 → 0.4.0

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: 59959ae9ec12f0d79aecfe21ae07748baa067bb47efb9c519d291dd352032873
4
- data.tar.gz: ea54f68d9693259b6fbe2833693391e7844c26b9f442551af09fe3d1e4d6b84d
3
+ metadata.gz: c3062914e848e9fea15dd9b02bd001946b7a3fd0ab015a1805b4e21a371b68bf
4
+ data.tar.gz: 17866f6bfaf40d6e195c71655ac134430747e3690ce32c355036a8e30a62bbf1
5
5
  SHA512:
6
- metadata.gz: 221a7565d2feb4ac3769793dbb510687b56f0058bc259ecf94a32acb59e4d8dcebe23a4d7cc14888a6001ffc53a3e06bbc940e45032138dcd734fb6476b76a28
7
- data.tar.gz: 68e22b21cffae4f146781926d89dd7c767f31234212181ce60707f9dd8e35ec90841f868677517d772a0221ca80fe7a53b15f93a7a067f6c5a280c4ebd5e7ae4
6
+ metadata.gz: ac9dad679a58246c1bd04d67de6812e9126f8f341edad4a72e842b80b759bcf2e020a2ad0c5bedd625eff861f22f0cbb224d4d2dc058a136d4c13087c4420248
7
+ data.tar.gz: b0f7285fd1e447c3f48e06d061aa441f64bb37de1952022e22e44835c3b549c639bceec13d9a690d0d14becb5eb724e1d2f31c05ea47a514ba2be57d9680de3b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,44 @@
1
+ ## [0.4.0] — 2026-07-27
2
+
3
+ ### Changed
4
+
5
+ - **`checkpoint_store:` renamed to `storage:`** — shorter, more general name
6
+ for the backend that persists checkpoint data for crash recovery.
7
+
8
+ ```ruby
9
+ # Before
10
+ MyGraph.call(input, checkpoint_store: RedisPool.new)
11
+ g.new(input, checkpoint_store: RedisPool.new)
12
+
13
+ # After
14
+ MyGraph.call(input, storage: RedisPool.new)
15
+ g.new(input, storage: RedisPool.new)
16
+ ```
17
+
18
+ ### Added
19
+
20
+ - **Class-level `storage`** — set once at the class level instead of passing
21
+ per-call. Works the same as `timeout`: per-call → graph class → global.
22
+
23
+ ```ruby
24
+ # Global default for all graphs
25
+ Ask::Graph.storage RedisPool.new
26
+
27
+ # Per-graph override
28
+ class MyGraph < Ask::Graph
29
+ storage PostgresStore.new
30
+ end
31
+
32
+ # Per-call override (overrides everything)
33
+ MyGraph.call(input, storage: InMemory.new)
34
+ ```
35
+
36
+ Falls back to `Ask::State::Memory.new` when nothing is configured.
37
+
38
+ ### Tested
39
+
40
+ - 70 tests, 92 assertions, 0 failures
41
+
1
42
  ## [0.3.0] — 2026-07-27
2
43
 
3
44
  ### Added
@@ -21,16 +21,16 @@ module Ask
21
21
  attr_reader :declarations, :store
22
22
 
23
23
  # @param declarations [Array<Hash>] step declarations
24
- # @param checkpoint_store [#set, #get, #delete] key-value store
24
+ # @param storage [#set, #get, #delete] key-value store for checkpoint data
25
25
  # @param hooks [Hash] lifecycle hook method names
26
26
  # @param graph_instance [Object] the graph instance (for hooks)
27
27
  # @param default_timeout [Integer, nil] fallback timeout for steps with no explicit timeout
28
- def initialize(declarations, checkpoint_store: nil,
28
+ def initialize(declarations, storage: nil,
29
29
  hooks: { before_step: [], after_step: [], on_failure: [] },
30
30
  graph_instance: nil,
31
31
  default_timeout: nil)
32
32
  @declarations = declarations
33
- @store = checkpoint_store
33
+ @store = storage
34
34
  @hooks = hooks
35
35
  @graph = graph_instance
36
36
  @default_timeout = default_timeout
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ask
4
4
  class Graph
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
data/lib/ask/graph.rb CHANGED
@@ -77,6 +77,39 @@ module Ask
77
77
  end
78
78
  end
79
79
 
80
+ # --- Storage ---
81
+
82
+ # Set or get the default storage backend for checkpoint data.
83
+ # The storage object must respond to +#set(key, value)+ and +#get(key)+.
84
+ #
85
+ # Setting on {Ask::Graph} itself applies to all graphs that don't set
86
+ # their own storage — a global default.
87
+ #
88
+ # @example Global default for all graphs
89
+ # Ask::Graph.storage RedisPool.new
90
+ #
91
+ # @example Per-graph override
92
+ # class MyGraph < Ask::Graph
93
+ # storage PostgresStore.new
94
+ # end
95
+ #
96
+ # @example Per-call override
97
+ # MyGraph.call(input, storage: InMemory.new)
98
+ #
99
+ # @param store [Object, nil] a backend that responds to +#set+ and +#get+
100
+ # @return [Object, nil] the current storage for this graph
101
+ def storage(store = :not_set)
102
+ if store == :not_set
103
+ if instance_variable_defined?(:@storage)
104
+ @storage
105
+ elsif superclass.respond_to?(:storage)
106
+ superclass.storage
107
+ end
108
+ else
109
+ @storage = store
110
+ end
111
+ end
112
+
80
113
  # --- Lifecycle hooks ---
81
114
 
82
115
  def lifecycle_hooks
@@ -142,8 +175,8 @@ module Ask
142
175
  end
143
176
 
144
177
  # Convenience: create instance and call.
145
- def call(input = nil, checkpoint_store: nil)
146
- new(input, checkpoint_store: checkpoint_store).call
178
+ def call(input = nil, storage: nil)
179
+ new(input, storage: storage).call
147
180
  end
148
181
  alias run call
149
182
 
@@ -163,12 +196,12 @@ module Ask
163
196
  end
164
197
  end
165
198
 
166
- def initialize(input = nil, checkpoint_store: nil)
199
+ def initialize(input = nil, storage: nil)
167
200
  @input = input
168
- store = checkpoint_store || Ask::State::Memory.new
201
+ store = storage || self.class.storage || Ask::State::Memory.new
169
202
  hooks = self.class.lifecycle_hooks
170
203
  @runner = Runner.new(self.class.declarations,
171
- checkpoint_store: store,
204
+ storage: store,
172
205
  hooks: hooks,
173
206
  graph_instance: self,
174
207
  default_timeout: self.class.timeout)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-graph
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
  - Kaka Ruto