taskchampion-rb 0.9.6 → 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: 4d630eddac8dfcb822f6e7f09d61f47abf4bc7597cc2d5cc127b53bff7a6a2f2
4
- data.tar.gz: 7fbf3649576f7b77114f67fb9ea04c5018d06ba27dc0746b74a35a67c8af1cb5
3
+ metadata.gz: 1dc8b1f18f25ae0836d52c2f903e3282cb6244b38480cf6d0f56acc2cf7e25ef
4
+ data.tar.gz: ca39b8342496e5c3559d33cf8964be432f7bdea2fb7f7426d5da35061b9a67f7
5
5
  SHA512:
6
- metadata.gz: a412f351c3b06ba461ae2404bad35c2944cbd25245e7f7ed7415e8d97647fd21c397c15b538064530481029ce10be0a37d0ad75156f6907cb515ea89fa66382e
7
- data.tar.gz: b428ea2050a5286a05a6c73037434874161c7cc4c3df0784c1741b53fffc47918819a88c1aae537ebde2ca5466b46be071905aebffc2995034ad9a3784337996
6
+ metadata.gz: 61c0d662d970c895aeff8fe900666e804d16ec323e5fb9d8ff5f8a204ebea31e4f5edcf3fe0584b9fc2d8b61990b3d763ce12920656b096f18f00f813614a40a
7
+ data.tar.gz: 684c4c35a561b6fe169e4eb66597e335ec1e6a4220ceaa77d59847be3d554f9f457ac9bf0167c65b60a42d32b1f03b2848f9a10f5d42448b1749c31edfe9ab3d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
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
14
+
15
+ - Link the system `libsqlite3` by default again, as 0.9.4 did, so
16
+ `libsqlite3-dev` is once more a build prerequisite on Linux. Since
17
+ 0.9.5 the extension compiled its own copy of SQLite, which leaves two
18
+ SQLite copies in any process that also loads the `sqlite3` gem; they
19
+ do not share POSIX file locks, which can corrupt the database.
20
+ - Add an opt-in switch for bundled SQLite: set
21
+ `TASKCHAMPION_BUNDLED_SQLITE=1` or pass `--with-bundled-sqlite` at
22
+ install time. Only use it when nothing else in the process loads
23
+ SQLite.
24
+
1
25
  ## [0.9.6] - 2026-10-22
2
26
 
3
27
  - Update `rb-sys` to 0.9.130 (pulling in `bindgen` 0.72.1) in
data/README.md CHANGED
@@ -20,15 +20,35 @@ This gem supports Ruby 3.3 and later. We follow Ruby's end-of-life (EOL) schedul
20
20
  libclang over Ruby's headers to generate FFI bindings during `rake compile`.
21
21
  - **Debian/Ubuntu:** `sudo apt install clang libclang-dev`
22
22
  - **macOS:** `xcode-select --install`
23
- 3. Rust toolchain (optional — if `cargo` is not found, `rb-sys` bootstraps its
23
+ 3. System SQLite development files — the extension links the system
24
+ `libsqlite3` by default.
25
+ - **Debian/Ubuntu:** `sudo apt install libsqlite3-dev`
26
+ - **macOS:** nothing to install; the OS ships `libsqlite3`.
27
+ 4. Rust toolchain (optional — if `cargo` is not found, `rb-sys` bootstraps its
24
28
  own rustup + toolchain during the build). To install it yourself:
25
29
 
26
30
  ```bash
27
31
  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
28
32
  ```
29
33
 
30
- > SQLite is compiled from source into the extension (the `bundled` feature), so
31
- > no system SQLite / `libsqlite3-dev` is required.
34
+ ### Bundled SQLite (opt-in)
35
+
36
+ To compile SQLite from source into the extension instead of linking the
37
+ system library, set the switch at install time:
38
+
39
+ ```bash
40
+ TASKCHAMPION_BUNDLED_SQLITE=1 gem install taskchampion-rb
41
+ # or
42
+ gem install taskchampion-rb -- --with-bundled-sqlite
43
+ # or, with Bundler
44
+ bundle config build.taskchampion-rb --with-bundled-sqlite
45
+ ```
46
+
47
+ > **Warning:** do not use bundled SQLite in a process that also loads another
48
+ > copy of SQLite, such as the `sqlite3` gem (e.g. a Rails app). Two SQLite
49
+ > copies in one process do not see each other's POSIX file locks, which can
50
+ > corrupt the database. Bundling is only safe when taskchampion-rb is the sole
51
+ > SQLite user in the process.
32
52
 
33
53
  ### Building from source
34
54
 
data/Rakefile CHANGED
@@ -32,10 +32,17 @@ task :publish, [:version] do |t, args|
32
32
  version = args[:version] || "patch"
33
33
 
34
34
  puts "Bumping version (#{version})..."
35
- sh "bump #{version} --tag"
35
+ # Commit and tag here rather than with bump --tag: bump's "vX.Y.Z"
36
+ # subject fails the commit-msg hook, and bump tags even when the
37
+ # commit fails.
38
+ sh "bump #{version} --no-commit"
39
+ new_version = `bump current --value-only`.strip
40
+ sh "git add lib/taskchampion/version.rb Gemfile.lock"
41
+ sh "git commit -m 'Bump to v#{new_version}'"
42
+ sh "git tag -a v#{new_version} -m v#{new_version}"
36
43
 
37
44
  puts "Pushing to git..."
38
- sh "git push && git push --tags"
45
+ sh "git push && git push origin v#{new_version}"
39
46
 
40
47
  puts "Building and releasing gem..."
41
48
  Rake::Task["release"].invoke
@@ -12,11 +12,15 @@ crate-type = ["cdylib"]
12
12
  [dependencies]
13
13
  magnus = { version = "0.7", features = ["rb-sys"] }
14
14
  rb-sys = "0.9.103"
15
- # `bundled` compiles SQLite from source into the extension so the build does not
16
- # depend on the host having libsqlite3-dev / a compatible system SQLite.
17
- taskchampion = { version = "2.0", default-features = false, features = ["bundled", "server-sync", "server-gcp"] }
15
+ # SQLite is linked from the system by default. See the bundled-sqlite feature.
16
+ taskchampion = { version = "2.0", default-features = false, features = ["server-sync", "server-gcp"] }
18
17
  chrono = "0.4"
19
18
  uuid = "1.0"
20
19
 
21
20
  [features]
22
21
  default = ["rb-sys/stable-api-compiled-fallback"]
22
+ # Compile a private copy of SQLite into the extension instead of linking the
23
+ # system libsqlite3. Do not enable this in a process that also loads another
24
+ # SQLite (e.g. the sqlite3 gem): two copies do not share POSIX file locks,
25
+ # which can corrupt the database. Enabled through extconf.rb.
26
+ bundled-sqlite = ["taskchampion/bundled"]
@@ -3,4 +3,14 @@
3
3
  require "mkmf"
4
4
  require "rb_sys/mkmf"
5
5
 
6
- create_rust_makefile("taskchampion/taskchampion")
6
+ # Opt in to compiling SQLite into the extension with either
7
+ # TASKCHAMPION_BUNDLED_SQLITE=1
8
+ # or
9
+ # gem install taskchampion-rb -- --with-bundled-sqlite
10
+ # bundle config build.taskchampion-rb --with-bundled-sqlite
11
+ bundled_sqlite = with_config("bundled-sqlite") ||
12
+ %w[1 true yes].include?(ENV["TASKCHAMPION_BUNDLED_SQLITE"])
13
+
14
+ create_rust_makefile("taskchampion/taskchampion") do |r|
15
+ r.features = ["bundled-sqlite"] if bundled_sqlite
16
+ end
@@ -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.6"
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.6
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