taskchampion-rb 0.9.7 → 0.10.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: 42b23c3273d5b9953634be0e881ce7cffbd451f29468f17eb6f9cbcdf236ce0b
4
- data.tar.gz: 6dde1f28ba13970fbb850ecfc82bdd07ac4f20a5f7e2fff54e028995043f11fb
3
+ metadata.gz: 1dc8b1f18f25ae0836d52c2f903e3282cb6244b38480cf6d0f56acc2cf7e25ef
4
+ data.tar.gz: ca39b8342496e5c3559d33cf8964be432f7bdea2fb7f7426d5da35061b9a67f7
5
5
  SHA512:
6
- metadata.gz: 69a4c9013c7441a9ce966e096e07ebd41549460f8160027780ce388a4514946260748f75245cc3fed5da2964d6c029a127d2feb9fb5210589b4487f6b13be94a
7
- data.tar.gz: e5af336507eb5105250be66e308527ba137ee50124cf24de34793f63d6448e618f2d7f996f0fe777bb88ce17e95c7c151755ce6815eeeac60c0bde44e8188401
6
+ metadata.gz: 61c0d662d970c895aeff8fe900666e804d16ec323e5fb9d8ff5f8a204ebea31e4f5edcf3fe0584b9fc2d8b61990b3d763ce12920656b096f18f00f813614a40a
7
+ data.tar.gz: 684c4c35a561b6fe169e4eb66597e335ec1e6a4220ceaa77d59847be3d554f9f457ac9bf0167c65b60a42d32b1f03b2848f9a10f5d42448b1749c31edfe9ab3d
data/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
- ## [Unreleased]
1
+ ## [0.10.0] - 2026-11-04
2
+
3
+ - Add `Replica#close` and `Replica#closed?`. `close` drops the
4
+ underlying TaskChampion replica immediately, closing its SQLite
5
+ connection and releasing the database, `-wal` and `-shm` files
6
+ without waiting for GC. It is idempotent. Every other `Replica`
7
+ method raises the new `Taskchampion::ReplicaClosedError` (a
8
+ `Taskchampion::Error`) afterwards. Like all other methods, both are
9
+ bound to the creating thread and raise `ThreadError` elsewhere.
10
+ Tasks, working sets and dependency maps own their data and keep
11
+ working after the replica is closed.
12
+
13
+ ## [0.9.7] - 2026-10-22
2
14
 
3
15
  - Link the system `libsqlite3` by default again, as 0.9.4 did, so
4
16
  `libsqlite3-dev` is once more a build prerequisite on Linux. Since
@@ -6,6 +6,7 @@ pub fn init_errors(module: &RModule) -> Result<(), Error> {
6
6
  module.define_error("StorageError", error_class)?;
7
7
  module.define_error("ValidationError", error_class)?;
8
8
  module.define_error("ConfigError", error_class)?;
9
+ module.define_error("ReplicaClosedError", error_class)?;
9
10
  let sync_error_class = module.define_error("SyncError", error_class)?;
10
11
  module.define_error("OutOfSyncError", sync_error_class)?;
11
12
  Ok(())
@@ -65,3 +66,11 @@ pub fn map_taskchampion_error(error: taskchampion::Error) -> Error {
65
66
  _ => Error::new(storage_error(), error.to_string()),
66
67
  }
67
68
  }
69
+
70
+ pub fn replica_closed_error() -> magnus::ExceptionClass {
71
+ let ruby = magnus::Ruby::get().expect("Ruby not available");
72
+ let module = ruby.class_object().const_get::<_, RModule>("Taskchampion")
73
+ .expect("Taskchampion module not found");
74
+ module.const_get::<_, magnus::ExceptionClass>("ReplicaClosedError")
75
+ .expect("ReplicaClosedError class not initialized")
76
+ }
@@ -10,12 +10,34 @@ use crate::task_data::TaskData;
10
10
  use crate::working_set::WorkingSet;
11
11
  use crate::dependency_map::DependencyMap;
12
12
  use crate::thread_check::ThreadBound;
13
+ use crate::error::replica_closed_error;
14
+ use std::cell::RefMut;
13
15
  use crate::util::{into_error, option_to_ruby, uuid2tc, vec_to_ruby};
14
16
 
15
17
  #[magnus::wrap(class = "Taskchampion::Replica", free_immediately)]
16
- pub struct Replica(ThreadBound<TCReplica>);
18
+ pub struct Replica(ThreadBound<Option<TCReplica>>);
17
19
 
18
20
  impl Replica {
21
+ /// Borrow the inner replica, or fail if it was closed.
22
+ fn open(&self) -> Result<RefMut<'_, TCReplica>, Error> {
23
+ let guard = self.0.get_mut()?;
24
+ RefMut::filter_map(guard, |r| r.as_mut())
25
+ .map_err(|_| {
26
+ Error::new(replica_closed_error(), "replica is closed")
27
+ })
28
+ }
29
+
30
+ /// Drop the inner replica now, closing its storage. Idempotent.
31
+ fn close(&self) -> Result<(), Error> {
32
+ let taken = self.0.get_mut()?.take();
33
+ drop(taken);
34
+ Ok(())
35
+ }
36
+
37
+ fn is_closed(&self) -> Result<bool, Error> {
38
+ Ok(self.0.get()?.is_none())
39
+ }
40
+
19
41
  fn new_on_disk(
20
42
  path: String,
21
43
  create_if_missing: bool,
@@ -35,7 +57,7 @@ impl Replica {
35
57
  .into_storage()
36
58
  .map_err(into_error)?,
37
59
  );
38
- Ok(Replica(ThreadBound::new(replica)))
60
+ Ok(Replica(ThreadBound::new(Some(replica))))
39
61
  }
40
62
 
41
63
  fn new_in_memory() -> Result<Self, Error> {
@@ -44,11 +66,11 @@ impl Replica {
44
66
  .into_storage()
45
67
  .map_err(into_error)?,
46
68
  );
47
- Ok(Replica(ThreadBound::new(replica)))
69
+ Ok(Replica(ThreadBound::new(Some(replica))))
48
70
  }
49
71
 
50
72
  fn create_task(&self, uuid: String, operations: &Operations) -> Result<Value, Error> {
51
- let mut tc_replica = self.0.get_mut()?;
73
+ let mut tc_replica = self.open()?;
52
74
  let tc_uuid = uuid2tc(&uuid)?;
53
75
 
54
76
  // Create mutable operations vector for TaskChampion
@@ -67,7 +89,7 @@ impl Replica {
67
89
  }
68
90
 
69
91
  fn commit_operations(&self, operations: &Operations) -> Result<(), Error> {
70
- let mut tc_replica = self.0.get_mut()?;
92
+ let mut tc_replica = self.open()?;
71
93
 
72
94
  // Convert Operations to TaskChampion Operations
73
95
  let tc_operations = operations.clone_inner()?;
@@ -79,7 +101,7 @@ impl Replica {
79
101
  }
80
102
 
81
103
  fn all_tasks(&self) -> Result<RHash, Error> {
82
- let mut tc_replica = self.0.get_mut()?;
104
+ let mut tc_replica = self.open()?;
83
105
 
84
106
  let tasks = tc_replica.all_tasks().map_err(into_error)?;
85
107
  let hash = RHash::new();
@@ -94,7 +116,7 @@ impl Replica {
94
116
  }
95
117
 
96
118
  fn pending_tasks(&self) -> Result<RArray, Error> {
97
- let mut tc_replica = self.0.get_mut()?;
119
+ let mut tc_replica = self.open()?;
98
120
 
99
121
  let tc_tasks = tc_replica.pending_tasks().map_err(into_error)?;
100
122
 
@@ -108,7 +130,7 @@ impl Replica {
108
130
  }
109
131
 
110
132
  fn task_data(&self, uuid: String) -> Result<Value, Error> {
111
- let mut tc_replica = self.0.get_mut()?;
133
+ let mut tc_replica = self.open()?;
112
134
 
113
135
  let task_data = tc_replica
114
136
  .get_task_data(uuid2tc(&uuid)?)
@@ -121,7 +143,7 @@ impl Replica {
121
143
  }
122
144
 
123
145
  fn task(&self, uuid: String) -> Result<Value, Error> {
124
- let mut tc_replica = self.0.get_mut()?;
146
+ let mut tc_replica = self.open()?;
125
147
 
126
148
  let task = tc_replica
127
149
  .get_task(uuid2tc(&uuid)?)
@@ -134,14 +156,14 @@ impl Replica {
134
156
  }
135
157
 
136
158
  fn task_uuids(&self) -> Result<RArray, Error> {
137
- let mut tc_replica = self.0.get_mut()?;
159
+ let mut tc_replica = self.open()?;
138
160
 
139
161
  let uuids = tc_replica.all_task_uuids().map_err(into_error)?;
140
162
  vec_to_ruby(uuids, |uuid| Ok(uuid.to_string().into_value()))
141
163
  }
142
164
 
143
165
  fn working_set(&self) -> Result<Value, Error> {
144
- let mut tc_replica = self.0.get_mut()?;
166
+ let mut tc_replica = self.open()?;
145
167
 
146
168
  let tc_working_set = tc_replica.working_set().map_err(into_error)?;
147
169
  let working_set = WorkingSet::from_tc_working_set(tc_working_set.into());
@@ -150,7 +172,7 @@ impl Replica {
150
172
  }
151
173
 
152
174
  fn dependency_map(&self, force: Option<bool>) -> Result<Value, Error> {
153
- let mut tc_replica = self.0.get_mut()?;
175
+ let mut tc_replica = self.open()?;
154
176
  let force = force.unwrap_or(false);
155
177
 
156
178
  let tc_dm = tc_replica.dependency_map(force).map_err(into_error)?;
@@ -160,7 +182,7 @@ impl Replica {
160
182
  }
161
183
 
162
184
  fn sync_to_local(&self, server_dir: String, avoid_snapshots: Option<bool>) -> Result<(), Error> {
163
- let mut tc_replica = self.0.get_mut()?;
185
+ let mut tc_replica = self.open()?;
164
186
  let avoid_snapshots = avoid_snapshots.unwrap_or(false);
165
187
 
166
188
  let mut server = ServerConfig::Local {
@@ -198,7 +220,7 @@ impl Replica {
198
220
  .and_then(|v| bool::try_convert(v).ok())
199
221
  .unwrap_or(false);
200
222
 
201
- let mut tc_replica = self.0.get_mut()?;
223
+ let mut tc_replica = self.open()?;
202
224
 
203
225
  let mut server = ServerConfig::Remote {
204
226
  url,
@@ -214,7 +236,7 @@ impl Replica {
214
236
  }
215
237
 
216
238
  fn rebuild_working_set(&self, renumber: Option<bool>) -> Result<(), Error> {
217
- let mut tc_replica = self.0.get_mut()?;
239
+ let mut tc_replica = self.open()?;
218
240
  let renumber = renumber.unwrap_or(false);
219
241
 
220
242
  tc_replica
@@ -223,7 +245,7 @@ impl Replica {
223
245
  }
224
246
 
225
247
  fn expire_tasks(&self) -> Result<(), Error> {
226
- let mut tc_replica = self.0.get_mut()?;
248
+ let mut tc_replica = self.open()?;
227
249
 
228
250
  tc_replica.expire_tasks().map_err(into_error)
229
251
  }
@@ -248,7 +270,7 @@ impl Replica {
248
270
  .and_then(|v| bool::try_convert(v).ok())
249
271
  .unwrap_or(false);
250
272
 
251
- let mut tc_replica = self.0.get_mut()?;
273
+ let mut tc_replica = self.open()?;
252
274
 
253
275
  let mut server = ServerConfig::Gcp {
254
276
  bucket,
@@ -264,19 +286,19 @@ impl Replica {
264
286
  }
265
287
 
266
288
  fn num_local_operations(&self) -> Result<usize, Error> {
267
- let mut tc_replica = self.0.get_mut()?;
289
+ let mut tc_replica = self.open()?;
268
290
 
269
291
  Ok(tc_replica.num_local_operations().map_err(into_error)?)
270
292
  }
271
293
 
272
294
  fn num_undo_points(&self) -> Result<usize, Error> {
273
- let mut tc_replica = self.0.get_mut()?;
295
+ let mut tc_replica = self.open()?;
274
296
 
275
297
  Ok(tc_replica.num_undo_points().map_err(into_error)?)
276
298
  }
277
299
 
278
300
  fn get_task_operations(&self, uuid: String) -> Result<Value, Error> {
279
- let mut tc_replica = self.0.get_mut()?;
301
+ let mut tc_replica = self.open()?;
280
302
  let tc_uuid = uuid2tc(&uuid)?;
281
303
 
282
304
  let tc_operations = tc_replica.get_task_operations(tc_uuid).map_err(into_error)?;
@@ -286,7 +308,7 @@ impl Replica {
286
308
  }
287
309
 
288
310
  fn get_undo_operations(&self) -> Result<Value, Error> {
289
- let mut tc_replica = self.0.get_mut()?;
311
+ let mut tc_replica = self.open()?;
290
312
 
291
313
  let tc_operations = tc_replica.get_undo_operations().map_err(into_error)?;
292
314
  let operations = Operations::from_tc_operations(tc_operations);
@@ -295,7 +317,7 @@ impl Replica {
295
317
  }
296
318
 
297
319
  fn commit_reversed_operations(&self, operations: &Operations) -> Result<bool, Error> {
298
- let mut tc_replica = self.0.get_mut()?;
320
+ let mut tc_replica = self.open()?;
299
321
 
300
322
  // Convert Operations to TaskChampion Operations
301
323
  let tc_operations = operations.clone_inner()?;
@@ -316,6 +338,8 @@ pub fn init(module: &RModule) -> Result<(), Error> {
316
338
  class.define_singleton_method("new_in_memory", function!(Replica::new_in_memory, 0))?;
317
339
 
318
340
  // Instance methods
341
+ class.define_method("close", method!(Replica::close, 0))?;
342
+ class.define_method("closed?", method!(Replica::is_closed, 0))?;
319
343
  class.define_method("create_task", method!(Replica::create_task, 2))?;
320
344
  class.define_method("commit_operations", method!(Replica::commit_operations, 1))?;
321
345
  class.define_method("all_tasks", method!(Replica::all_tasks, 0))?;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Taskchampion
4
- VERSION = "0.9.7"
4
+ VERSION = "0.10.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taskchampion-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Case
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-22 00:00:00.000000000 Z
11
+ date: 2026-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys