taskchampion-rb 0.9.1 → 0.9.2

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: 97cd610777ff12232ab4625cbbca59e2a9241d1789926dd9a5f21d982876f25d
4
- data.tar.gz: d8b3232d7fe7fe9cdc518136e08e7b3873683c90ac32cf62e1947179f53ded8c
3
+ metadata.gz: 6d963e64502ad438957e3345671387a3915de84947a63bbcced83270f5c50848
4
+ data.tar.gz: 19309ecfe6ccf1a5a077a513a7b6ff769109ba7949c0282617b8b74e3b54f116
5
5
  SHA512:
6
- metadata.gz: 61a011d70095d38bb2009a653fa151115b5327282977243cf6bc56947ab38d488b62a027470c363fe45ee40e17c5673f95857207ceb7d5f1d150b109dc60b469
7
- data.tar.gz: 71e0d7baa33d944308f03d5ae5fb210b840b8834c7081980073e68f1649f2c21b86c0c7a39763a21f8c676019ae3d94bef1f82803071164c6963d59546c015c9
6
+ metadata.gz: '052509a0688871de92bc3d4219d7c257b712b7f4b7f5693f4e051d2ff38f891d5b6095d66aaf0cec8d06466ec272ec1fe5bd7e166dd790fb2a0c649592a29d4b'
7
+ data.tar.gz: f21cca16bd5da5921474361eb81d18937a1e328313a4c3dac2ea521ccc4d7b93cf356816d11e67abfa7292bbcfb76e40548766b94718030e42a315a80c3e5531
@@ -11,14 +11,6 @@ pub fn init_errors(module: &RModule) -> Result<(), Error> {
11
11
  Ok(())
12
12
  }
13
13
 
14
- pub fn base_error() -> magnus::ExceptionClass {
15
- let ruby = magnus::Ruby::get().expect("Ruby not available");
16
- let module = ruby.class_object().const_get::<_, RModule>("Taskchampion")
17
- .expect("Taskchampion module not found");
18
- module.const_get::<_, magnus::ExceptionClass>("Error")
19
- .expect("Error class not initialized")
20
- }
21
-
22
14
  pub fn thread_error() -> magnus::ExceptionClass {
23
15
  let ruby = magnus::Ruby::get().expect("Ruby not available");
24
16
  let module = ruby.class_object().const_get::<_, RModule>("Taskchampion")
@@ -58,7 +58,7 @@ impl Replica {
58
58
  let tc_task = tc_replica.create_task(tc_uuid, &mut tc_ops).map_err(into_error)?;
59
59
 
60
60
  // Add the resulting operations to the provided Operations object
61
- operations.extend_from_tc(tc_ops);
61
+ operations.extend_from_tc(tc_ops)?;
62
62
 
63
63
  // Convert to Ruby Task object
64
64
  let task = Task::from_tc_task(tc_task);
@@ -137,24 +137,22 @@ impl Task {
137
137
 
138
138
  fn get_uda(&self, namespace: String, key: String) -> Result<Value, Error> {
139
139
  let task = self.0.get()?;
140
- match task.get_uda(&namespace, &key) {
140
+ let combined_key = if namespace.is_empty() { key } else { format!("{}.{}", namespace, key) };
141
+ match task.get_user_defined_attribute(&combined_key) {
141
142
  Some(value) => Ok(value.into_value()),
142
- None => Ok(().into_value()), // () converts to nil in Magnus
143
+ None => Ok(().into_value()),
143
144
  }
144
145
  }
145
146
 
146
147
  fn udas(&self) -> Result<RArray, Error> {
147
148
  let task = self.0.get()?;
148
- let udas: Vec<((String, String), String)> = task.get_udas()
149
- .map(|((ns, key), value)| ((ns.to_string(), key.to_string()), value.to_string()))
149
+ let udas: Vec<(String, String)> = task.get_user_defined_attributes()
150
+ .map(|(key, value)| (key.to_string(), value.to_string()))
150
151
  .collect();
151
152
 
152
- vec_to_ruby(udas, |(key_tuple, value)| {
153
+ vec_to_ruby(udas, |(key, value)| {
153
154
  let array = RArray::new();
154
- let key_array = RArray::new();
155
- key_array.push(key_tuple.0)?;
156
- key_array.push(key_tuple.1)?;
157
- array.push(key_array)?;
155
+ array.push(key)?;
158
156
  array.push(value)?;
159
157
  Ok(array.into_value())
160
158
  })
@@ -360,7 +358,7 @@ impl Task {
360
358
  Some(timestamp_str) => {
361
359
  // Parse the string as Unix timestamp (seconds since epoch)
362
360
  if let Ok(timestamp_secs) = timestamp_str.parse::<i64>() {
363
- use chrono::{DateTime, Utc};
361
+ use chrono::DateTime;
364
362
  if let Some(dt) = DateTime::from_timestamp(timestamp_secs, 0) {
365
363
  return datetime_to_ruby(dt);
366
364
  }
@@ -387,8 +385,9 @@ impl Task {
387
385
  }
388
386
 
389
387
  let mut task = self.0.get_mut()?;
388
+ let combined_key = format!("{}.{}", namespace, key);
390
389
  operations.with_inner_mut(|ops| {
391
- task.set_uda(&namespace, &key, &value, ops)
390
+ task.set_user_defined_attribute(&combined_key, &value, ops)
392
391
  })?;
393
392
  Ok(())
394
393
  }
@@ -408,8 +407,9 @@ impl Task {
408
407
  }
409
408
 
410
409
  let mut task = self.0.get_mut()?;
410
+ let combined_key = format!("{}.{}", namespace, key);
411
411
  operations.with_inner_mut(|ops| {
412
- task.remove_uda(&namespace, &key, ops)
412
+ task.remove_user_defined_attribute(&combined_key, ops)
413
413
  })?;
414
414
  Ok(())
415
415
  }
@@ -32,12 +32,12 @@ impl<T> ThreadBound<T> {
32
32
  Ok(())
33
33
  }
34
34
 
35
- pub fn get(&self) -> Result<std::cell::Ref<T>, Error> {
35
+ pub fn get(&self) -> Result<std::cell::Ref<'_, T>, Error> {
36
36
  self.check_thread()?;
37
37
  Ok(self.inner.borrow())
38
38
  }
39
39
 
40
- pub fn get_mut(&self) -> Result<std::cell::RefMut<T>, Error> {
40
+ pub fn get_mut(&self) -> Result<std::cell::RefMut<'_, T>, Error> {
41
41
  self.check_thread()?;
42
42
  Ok(self.inner.borrow_mut())
43
43
  }
@@ -31,8 +31,6 @@ pub fn datetime_to_ruby(dt: DateTime<Utc>) -> Result<Value, Error> {
31
31
 
32
32
  /// Convert Ruby DateTime/Time/String to Rust DateTime<Utc> with enhanced validation
33
33
  pub fn ruby_to_datetime(value: Value) -> Result<DateTime<Utc>, Error> {
34
- let ruby = magnus::Ruby::get().map_err(|e| Error::new(magnus::exception::runtime_error(), e.to_string()))?;
35
-
36
34
  // If it's a string, parse it
37
35
  if let Ok(s) = RString::try_convert(value) {
38
36
  let s = unsafe { s.as_str()? };
@@ -99,15 +97,6 @@ where
99
97
  }
100
98
  }
101
99
 
102
- /// Convert HashMap to Ruby Hash
103
- pub fn hashmap_to_ruby(map: HashMap<String, String>) -> Result<RHash, Error> {
104
- let hash = RHash::new();
105
- for (k, v) in map {
106
- hash.aset(k, v)?;
107
- }
108
- Ok(hash)
109
- }
110
-
111
100
  /// Convert Ruby Hash to HashMap
112
101
  pub fn ruby_to_hashmap(hash: RHash) -> Result<HashMap<String, String>, Error> {
113
102
  let mut map = HashMap::new();
@@ -130,15 +119,3 @@ where
130
119
  Ok(array)
131
120
  }
132
121
 
133
- /// Convert Ruby Array to Vec
134
- pub fn ruby_to_vec<T, F>(array: RArray, converter: F) -> Result<Vec<T>, Error>
135
- where
136
- F: Fn(Value) -> Result<T, Error>,
137
- {
138
- let mut vec = Vec::with_capacity(array.len());
139
- for i in 0..array.len() {
140
- let value: Value = array.entry(i as isize)?;
141
- vec.push(converter(value)?);
142
- }
143
- Ok(vec)
144
- }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Taskchampion
4
- VERSION = "0.9.1"
4
+ VERSION = "0.9.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taskchampion-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Case