timet 1.5.0 → 1.5.1

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: fcf74496e5767f780af32f515ddaa47aac3a80056c62dd4e4ab680b4e380d9ea
4
- data.tar.gz: 8013d89eb5d8f13c794bc3a8b65d976e6e5658d674183a82aa5c11df3c5e65e3
3
+ metadata.gz: 9174050872f06486ce9307f0aa9ab28decce4345f7169cc0537741028a8cfcae
4
+ data.tar.gz: 2eaa910c4a79265fe273bdeb9ff0cffb4f5e5330f8849c1ccc197d1ee5e5edbb
5
5
  SHA512:
6
- metadata.gz: b0b961c8397a2db270284d7a25530265c79861e812674f376a2457675cdf5f1b6614117ead4e7de39ae73118ffcf30998a17d15ee010b6ec08725f63803bc99a
7
- data.tar.gz: aa487be7cff8c23f5c578ea624ad2cd8382d5216833275fde531266d87efd850b678a3df28e350d95561758ba5ea1efa255db9e7eb5fe60e1c09580e4c805ea6
6
+ metadata.gz: 61d368a8f2e30693c6c29abff6ae067001798b0b30c3012cfbce4fe0ced2d31ce0e89e76fe716e026b361d391ca0d13d58e29e61db6231fb23cbaed2e7cfd8fa
7
+ data.tar.gz: '0299cb83c55d19053a98dcb795da56e485b14e7b45b10e7c45ed8f1ecc03218d0966a2f5b7a28c1d0939f1455d6e14978caa2cfb8a9bfc8509681f8d7fc813ae'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.5.1] - 2024-12-07
4
+
5
+ **Improvements:**
6
+
7
+ - Extracted the logic for syncing items by ID into a separate method `sync_items_by_id` for better readability and maintainability.
8
+ - Improved the writing of missing environment variables to the .env file in the S3Supabase module by ensuring the file content ends with a newline character.
9
+ - Refactored the `all_items` method to use `beginning_of_day` for today's timestamp, improving the accuracy of the timestamp calculation.
10
+
11
+ **Bug Fixes:**
12
+
13
+ - Fixed the issue of having parameter lists longer than 5 parameters by refactoring the method to use a hash for named parameters.
14
+
3
15
  ## [1.5.0] - 2024-12-06
4
16
 
5
17
  **Improvements:**
@@ -94,7 +94,9 @@ module Timet
94
94
  # insert_item(1633072800, 'work', 'Completed task X')
95
95
  #
96
96
  # @note The method executes SQL to insert a new row into the 'items' table.
97
- def insert_item(start, tag, notes, pomodoro = nil, updated_at = nil, created_at = nil)
97
+ def insert_item(*args, pomodoro: nil, updated_at: nil, created_at: nil)
98
+ # Unpacking args into meaningful variables for clarity
99
+ start, tag, notes = args
98
100
  execute_sql('INSERT INTO items (start, tag, notes, pomodoro, updated_at, created_at) VALUES (?, ?, ?, ?, ?, ?)',
99
101
  [start, tag, notes, pomodoro, updated_at, created_at])
100
102
  end
@@ -185,7 +187,7 @@ module Timet
185
187
  # @note The method executes SQL to fetch all items from the 'items' table that have a start time greater than
186
188
  # or equal to today.
187
189
  def all_items
188
- today = Time.now.to_i - (Time.now.to_i % 86_400)
190
+ today = Time.now.beginning_of_day.to_i
189
191
  execute_sql('SELECT * FROM items WHERE start >= ? AND (deleted IS NULL OR deleted = 0) ORDER BY start DESC',
190
192
  [today])
191
193
  end
@@ -198,21 +198,30 @@ module Timet
198
198
  remote_items = remote_db.execute('SELECT * FROM items ORDER BY updated_at DESC')
199
199
  local_items = local_db.execute_sql('SELECT * FROM items ORDER BY updated_at DESC')
200
200
 
201
- remote_by_id = items_to_hash(remote_items)
202
- local_by_id = items_to_hash(local_items)
203
- all_ids = (remote_by_id.keys + local_by_id.keys).uniq
201
+ sync_items_by_id(
202
+ local_db,
203
+ items_to_hash(local_items),
204
+ items_to_hash(remote_items)
205
+ )
206
+ end
204
207
 
205
- all_ids.each do |id|
206
- remote_item = remote_by_id[id]
207
- local_item = local_by_id[id]
208
+ # Syncs items between local and remote databases based on their IDs
209
+ #
210
+ # @param local_db [SQLite3::Database] The local database connection
211
+ # @param local_items_by_id [Hash] Local items indexed by ID
212
+ # @param remote_items_by_id [Hash] Remote items indexed by ID
213
+ # @return [void]
214
+ def self.sync_items_by_id(local_db, local_items_by_id, remote_items_by_id)
215
+ all_item_ids = (remote_items_by_id.keys + local_items_by_id.keys).uniq
208
216
 
209
- if remote_item && local_item
210
- process_existing_item(id, local_item, remote_item, local_db)
211
- elsif remote_item
212
- puts "Adding remote item #{id} to local"
213
- insert_item_from_hash(local_db, remote_item)
214
- else # local_item exists
217
+ all_item_ids.each do |id|
218
+ if !remote_items_by_id[id]
215
219
  puts "Local item #{id} will be uploaded"
220
+ elsif !local_items_by_id[id]
221
+ puts "Adding remote item #{id} to local"
222
+ insert_item_from_hash(local_db, remote_items_by_id[id])
223
+ else
224
+ process_existing_item(id, local_items_by_id[id], remote_items_by_id[id], local_db)
216
225
  end
217
226
  end
218
227
  end
@@ -34,7 +34,7 @@ module Timet
34
34
  # Append missing variables with empty values
35
35
  return if missing_vars.empty?
36
36
 
37
- File.write(env_file_path, missing_vars.map { |var| "#{var}=''" }.join("\n") + "\n", mode: 'a')
37
+ File.write(env_file_path, "#{missing_vars.map { |var| "#{var}=''" }.join("\n")}\n", mode: 'a')
38
38
  end
39
39
 
40
40
  # S3Supabase is a class that provides methods to interact with an S3-compatible
@@ -110,7 +110,8 @@ module Timet
110
110
  # Lists all objects in the specified bucket.
111
111
  #
112
112
  # @param bucket_name [String] The name of the bucket to list objects from
113
- # @return [Array<Hash>, false, nil] Array of object hashes if objects found, false if bucket is empty, nil if error occurs
113
+ # @return [Array<Hash>, false, nil] Array of object hashes if objects found, false if bucket is empty,
114
+ # nil if error occurs
114
115
  # @raise [Aws::S3::Errors::ServiceError] if there's an error accessing the S3 service
115
116
  # @example
116
117
  # list_objects('my-bucket') #=> [{key: 'example.txt', last_modified: '2023-01-01', ...}, ...]
data/lib/timet/version.rb CHANGED
@@ -6,6 +6,6 @@ module Timet
6
6
  # @return [String] The version number in the format 'major.minor.patch'.
7
7
  #
8
8
  # @example Get the version of the Timet application
9
- # Timet::VERSION # => '1.5.0'
10
- VERSION = '1.5.0'
9
+ # Timet::VERSION # => '1.5.1'
10
+ VERSION = '1.5.1'
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Vielma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-06 00:00:00.000000000 Z
11
+ date: 2024-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor