taskchampion-rb 0.3.0 → 0.5.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: c7110e37a7e2a8af13267d10879260e10b920b1ba49c3d9f5b124cc7d618862b
4
- data.tar.gz: '029792b10587e8a680b80936e1156ac2e1a15d2ba19970219b4f1d5496570bc7'
3
+ metadata.gz: 8b267de15e0004e931e2a46f37f9014afe8fdc52e58e675190dab990cb345e75
4
+ data.tar.gz: 6a84efc5a165c428c67e6d50f3ce0b001eab4d3fde464ffed123d218aaf04033
5
5
  SHA512:
6
- metadata.gz: 7e7ba27d8a5202767273e9221d115640493dbba79b8de6563e0cfeb0d9d2c75945244f649d1874745c0c80fe769eb7efd089737843baf843c47dd3e649fa6db4
7
- data.tar.gz: d75725f6f197a67195d290a44ebd045434c1ada09779551a2e3c08e8430e4cfd5c6266d86d000135bc444aea77ac945034cdb2218835d48f706e4b8961efea5f
6
+ metadata.gz: ff860c7dcb85bc6a04aced731b403072a03c3a222f869fec0a25af1436b14fb67e4df0a9dc5cfad4d829b1fe1f39936e6df07c90605eb859202ac8f80fc8a17f
7
+ data.tar.gz: d826c3704fec6432e872abe24423d92e04da810c0718ce0cc224dbddd780b2279b336c635bd1e285405bd4534710fbd9928bf4ee7c5f225f4118baade8315436
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 3.2.0
@@ -18,7 +18,7 @@ db_path = File.join(temp_dir, "tasks")
18
18
  begin
19
19
  # 1. CREATE TASK DATABASE
20
20
  puts "\n1. Creating task database at #{db_path}"
21
- replica = Taskchampion::Replica.new_on_disk(db_path, create_if_missing: true)
21
+ replica = Taskchampion::Replica.new_on_disk(db_path, true, :read_write)
22
22
 
23
23
  # 2. CREATE AND MODIFY TASKS
24
24
  puts "\n2. Creating and modifying tasks"
@@ -39,8 +39,7 @@ begin
39
39
  task1.add_tag(Taskchampion::Tag.new("ruby"), operations)
40
40
 
41
41
  # Add annotation
42
- annotation = Taskchampion::Annotation.new(Time.now, "Started learning TaskChampion")
43
- task1.add_annotation(annotation, operations)
42
+ task1.add_annotation("Started learning TaskChampion", operations)
44
43
 
45
44
  # Create second task
46
45
  uuid2 = SecureRandom.uuid
@@ -61,7 +60,6 @@ begin
61
60
  task3.set_description("Read TaskChampion documentation", operations)
62
61
  task3.set_status(Taskchampion::Status.completed, operations)
63
62
  task3.add_tag(Taskchampion::Tag.new("learning"), operations)
64
- task3.set_end(Time.now, operations)
65
63
 
66
64
  # 3. COMMIT CHANGES TO STORAGE
67
65
  puts "\n3. Committing changes to storage"
@@ -88,14 +86,13 @@ begin
88
86
 
89
87
  # Display tags
90
88
  if !task.tags.empty?
91
- tag_names = task.tags.map(&:name)
89
+ tag_names = task.tags.map(&:to_s)
92
90
  puts " Tags: #{tag_names.join(', ')}"
93
91
  end
94
92
 
95
93
  # Display dates
96
94
  puts " Created: #{task.entry.strftime('%Y-%m-%d %H:%M:%S')}" if task.entry
97
95
  puts " Due: #{task.due.strftime('%Y-%m-%d %H:%M:%S')}" if task.due
98
- puts " Completed: #{task.end.strftime('%Y-%m-%d %H:%M:%S')}" if task.end
99
96
 
100
97
  # Display annotations
101
98
  if !task.annotations.empty?
@@ -136,29 +133,42 @@ begin
136
133
 
137
134
  # Find tasks due today or tomorrow
138
135
  tomorrow = Time.now + 86400
139
- due_soon = all_tasks.select { |t| t.due && t.due <= tomorrow }
136
+ due_soon = all_tasks.select { |t| t.due && t.due.to_time <= tomorrow }
140
137
  puts "Tasks due soon: #{due_soon.length}"
141
138
 
142
139
  # 6. MODIFY EXISTING TASKS
143
140
  puts "\n6. Modifying existing tasks"
144
141
 
145
- # Complete the first task
142
+ # Complete the first task using the done method
146
143
  operations2 = Taskchampion::Operations.new
147
144
 
148
145
  # Retrieve task fresh from storage
149
146
  task_to_complete = replica.task(uuid1)
150
147
  if task_to_complete && task_to_complete.pending?
151
148
  puts "Completing task: #{task_to_complete.description}"
152
- task_to_complete.set_status(Taskchampion::Status.completed, operations2)
153
- task_to_complete.set_end(Time.now, operations2)
149
+
150
+ # Use the done() method - a convenience method for marking tasks as completed
151
+ task_to_complete.done(operations2)
154
152
 
155
153
  # Add completion annotation
156
- completion_note = Taskchampion::Annotation.new(Time.now, "Completed successfully!")
157
- task_to_complete.add_annotation(completion_note, operations2)
154
+ task_to_complete.add_annotation("Completed successfully!", operations2)
158
155
 
159
156
  # Commit the changes
160
157
  replica.commit_operations(operations2)
161
- puts "Task completed and committed"
158
+ puts "Task completed using done() method and committed"
159
+ end
160
+
161
+ # Complete the second task using traditional set_status for comparison
162
+ operations2b = Taskchampion::Operations.new
163
+ task_to_complete2 = replica.task(uuid2)
164
+ if task_to_complete2 && task_to_complete2.pending?
165
+ puts "Completing second task: #{task_to_complete2.description}"
166
+
167
+ # Alternative way: using set_status directly
168
+ task_to_complete2.set_status(Taskchampion::Status.completed, operations2b)
169
+
170
+ replica.commit_operations(operations2b)
171
+ puts "Task completed using set_status() method and committed"
162
172
  end
163
173
 
164
174
  # 7. WORKING WITH WORKING SET
@@ -7,7 +7,7 @@ use crate::annotation::Annotation;
7
7
  use crate::status::Status;
8
8
  use crate::tag::Tag;
9
9
  use crate::thread_check::ThreadBound;
10
- use crate::util::{datetime_to_ruby, into_error, option_to_ruby, ruby_to_datetime, ruby_to_option, vec_to_ruby};
10
+ use crate::util::{datetime_to_ruby, option_to_ruby, ruby_to_datetime, ruby_to_option, vec_to_ruby};
11
11
 
12
12
  #[magnus::wrap(class = "Taskchampion::Task", free_immediately)]
13
13
  pub struct Task(ThreadBound<TCTask>);
@@ -326,6 +326,14 @@ impl Task {
326
326
  Ok(())
327
327
  }
328
328
 
329
+ fn done(&self, operations: &crate::operations::Operations) -> Result<(), Error> {
330
+ let mut task = self.0.get_mut()?;
331
+ operations.with_inner_mut(|ops| {
332
+ task.done(ops)
333
+ })?;
334
+ Ok(())
335
+ }
336
+
329
337
  }
330
338
 
331
339
  // Remove AsRef implementation as it doesn't work well with thread bounds
@@ -384,5 +392,6 @@ pub fn init(module: &RModule) -> Result<(), Error> {
384
392
  class.define_method("set_value", method!(Task::set_value, 3))?;
385
393
  class.define_method("set_uda", method!(Task::set_uda, 4))?;
386
394
  class.define_method("delete_uda", method!(Task::delete_uda, 3))?;
395
+ class.define_method("done", method!(Task::done, 1))?;
387
396
  Ok(())
388
397
  }
@@ -14,8 +14,6 @@ impl TaskData {
14
14
  pub fn from_tc_task_data(tc_task_data: TCTaskData) -> Self {
15
15
  TaskData(ThreadBound::new(tc_task_data))
16
16
  }
17
-
18
-
19
17
  fn inspect(&self) -> Result<String, Error> {
20
18
  let task_data = self.0.get()?;
21
19
  Ok(format!("#<Taskchampion::TaskData: {}>", task_data.get_uuid()))
@@ -45,11 +43,11 @@ impl TaskData {
45
43
  fn to_hash(&self) -> Result<RHash, Error> {
46
44
  let task_data = self.0.get()?;
47
45
  let hash = RHash::new();
48
-
46
+
49
47
  for (key, value) in task_data.iter() {
50
48
  hash.aset(key.clone(), value.clone())?;
51
49
  }
52
-
50
+
53
51
  Ok(hash)
54
52
  }
55
53
 
@@ -78,7 +76,7 @@ impl TaskData {
78
76
 
79
77
  fn delete(&self, operations: &Operations) -> Result<(), Error> {
80
78
  let mut task_data = self.0.get_mut()?;
81
-
79
+
82
80
  operations.with_inner_mut(|ops| {
83
81
  task_data.delete(ops);
84
82
  Ok(())
@@ -90,16 +88,16 @@ impl TaskData {
90
88
 
91
89
  fn create_task_data(uuid: String, operations: &Operations) -> Result<TaskData, Error> {
92
90
  let tc_uuid = uuid2tc(&uuid)?;
93
-
91
+
94
92
  // Create operations for TaskChampion
95
93
  let mut tc_ops = taskchampion::Operations::new();
96
-
94
+
97
95
  // Create the TaskData
98
96
  let tc_task_data = TCTaskData::create(tc_uuid, &mut tc_ops);
99
-
97
+
100
98
  // Add the resulting operations to the provided Operations object
101
99
  operations.extend_from_tc(tc_ops.into_iter().collect())?;
102
-
100
+
103
101
  Ok(TaskData(ThreadBound::new(tc_task_data)))
104
102
  }
105
103
 
@@ -121,4 +119,4 @@ pub fn init(module: &RModule) -> Result<(), Error> {
121
119
  class.define_method("delete", method!(TaskData::delete, 1))?;
122
120
 
123
121
  Ok(())
124
- }
122
+ }
@@ -61,7 +61,7 @@ pub fn ruby_to_datetime(value: Value) -> Result<DateTime<Utc>, Error> {
61
61
  ))
62
62
  }
63
63
  };
64
-
64
+
65
65
  DateTime::parse_from_rfc3339(&iso_string)
66
66
  .map(|dt| dt.with_timezone(&Utc))
67
67
  .or_else(|_| {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Taskchampion
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.0"
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.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Case