tsks 0.0.14 → 0.0.16

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: e0ac100edb1bd020860d7f8a63a58e2cca619f8c6c1775db4e9f5d84b5a864ad
4
- data.tar.gz: e1e564b30cfb1f4cbe3969dc9b761c13734374a8ee9623818e9d92efd5769f9f
3
+ metadata.gz: eba37aa1a580178be1d1a37dfa7aac67ee5d133b047a53b186be514ff047b8f4
4
+ data.tar.gz: 6cf976319e8e70cab7dab0529d3c34cfea6428eb559d03ca1f0115d5e296af1a
5
5
  SHA512:
6
- metadata.gz: a57c235a7aef701d2a8537f0449213466c905d7432696eb15cdce666270943b1fcf7681613480aa8fece0815962f777ede0f3f81918ddb9b173ccc69ae6a022b
7
- data.tar.gz: fed3ec9a4952c847d14c004092de4db6d30d1de4d1b06bfc095b86e4d9aa84ba8b621d2e0f3c9d30658f2f4d4dfcf8beca057c0a457137b82f5354f8f0ead3da
6
+ metadata.gz: 8b1e46d8649e769ad5d74e0c0f46628f15cf725faf96838d446afaf9cc5eafa2c25abbab5ab8e7bbb306ac240df42b3d3e58e7fea8fc1712517972a09092af77
7
+ data.tar.gz: 95c1406756b470b2417e3615937ccad9bc3b2ff9622f1e63e8098c6ad55e8d19f80d244d75466627704f997f742d401423588494bf837ee0efec80ce102af409
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tsks (0.0.14)
4
+ tsks (0.0.16)
5
5
  httparty
6
6
  sqlite3
7
7
  thor
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # tsks
2
2
 
3
- [![build](https://dl.circleci.com/status-badge/img/gh/luanrv/tsks-cli/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/luanrv/tsks-cli/tree/main)
4
-
5
3
  A stateful command line interface to help you handle your daily tsks (with
6
4
  synchronisation and contexts!).
7
5
 
data/bin/build ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ bundle exec rake build
data/lib/tsks/actions.rb CHANGED
@@ -6,12 +6,12 @@ module Tsks
6
6
  current_tsks = Tsks::Storage.select_all
7
7
 
8
8
  for tsk in current_tsks
9
- Tsks::Storage.update tsk[:local_id], {user_id: user_id}
9
+ Tsks::Storage.update_by({rowid: tsk[:rowid]}, {user_id: user_id})
10
10
  end
11
11
  end
12
12
 
13
13
  def self.update_server_for_removed_tsks token
14
- tsks_uuids = Tsks::Storage.select_removed_uuids
14
+ tsks_uuids = Tsks::Storage.select_removed_tsk_ids
15
15
 
16
16
  if !tsks_uuids.empty?
17
17
  for id in tsks_uuids
data/lib/tsks/cli.rb CHANGED
@@ -84,7 +84,7 @@ module Tsks
84
84
  if tsks.count > 0
85
85
  for tsk in tsks
86
86
  tsk_status = Tsks::Actions.get_tsk_status tsk[:status]
87
- puts "#{tsk[:id]} #{tsk_status} | #{tsk[:tsk]} @#{tsk[:context]}"
87
+ puts "#{tsk[:id]} | #{tsk_status} #{tsk[:tsk]} @#{tsk[:context]}"
88
88
  end
89
89
  else
90
90
  puts "no tsks found."
@@ -159,8 +159,8 @@ module Tsks
159
159
  token = File.read File.join CLI.setup_folder, "token"
160
160
  Tsks::Actions.update_tsks_with_user_id user_id
161
161
  Tsks::Actions.update_server_for_removed_tsks token
162
- Tsks::Storage.delete_removed_uuids
163
- local_tsks = Tsks::Storage.select_all local_id=false
162
+ Tsks::Storage.delete_removed_tsk_ids
163
+ local_tsks = Tsks::Storage.select_all
164
164
 
165
165
  begin
166
166
  get_res = Tsks::Request.get "/tsks", token
@@ -168,26 +168,33 @@ module Tsks
168
168
 
169
169
  if get_res[:tsks]
170
170
  if get_res[:ok] == true
171
- local_tsks_to_post = local_tsks - remote_tsks
171
+ raw_local_tsks = local_tsks.map {|t| t.reject{|k,_| k == :rowid}}
172
+ local_tsks_to_post = raw_local_tsks - remote_tsks
173
+
174
+ tsks_to_post = []
175
+ for local_tsk in local_tsks
176
+ for local_tsk_to_post in local_tsks_to_post
177
+ if local_tsk[:tsk] == local_tsk_to_post[:tsk]
178
+ tsks_to_post.append local_tsk
179
+ end
180
+ end
181
+ end
172
182
 
173
- if local_tsks_to_post.count > 0
174
- for tsk in local_tsks_to_post
183
+ if tsks_to_post.count > 0
184
+ for tsk in tsks_to_post
175
185
  post_res = Tsks::Request.post "/tsks", token, {tsk: tsk}
176
186
  posted_tsk = post_res[:tsk]
177
187
 
178
188
  if posted_tsk
179
- # TODO: write tests for Storage.select_local_id
180
- tsk_local_id = Tsks::Storage.select_local_id({tsk: posted_tsk[:tsk],
181
- created_at: posted_tsk[:created_at],
182
- updated_at: posted_tsk[:updated_at]})
183
-
184
- Tsks::Storage.update tsk_local_id, {id: posted_tsk[:id]}
189
+ Tsks::Storage.update_by({rowid: tsk[:rowid]}, {id: posted_tsk[:id]})
185
190
  end
186
191
  end
187
192
  end
188
193
 
189
- updated_local_tsks = Tsks::Storage.select_all local_id=false
190
- remote_tsks_to_storage = remote_tsks - updated_local_tsks
194
+ # TODO: review this process
195
+ updated_local_tsks = Tsks::Storage.select_all
196
+ raw_updated_local_tsks = updated_local_tsks.map {|t| t.reject{|k,_| k == :rowid}}
197
+ remote_tsks_to_storage = remote_tsks - raw_updated_local_tsks
191
198
 
192
199
  if remote_tsks_to_storage.count > 0
193
200
  Tsks::Storage.insert_many remote_tsks_to_storage
data/lib/tsks/storage.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "sqlite3"
2
- require "uuid"
3
2
 
4
3
  module Tsks
5
4
  class Storage
@@ -7,8 +6,8 @@ module Tsks
7
6
  storage = get_storage_instance
8
7
  storage.execute <<-SQL
9
8
  CREATE TABLE tsks (
10
- id VARCHAR PRIMARY KEY UNIQUE,
11
- user_id INTEGER DEFAULT 1,
9
+ id INTEGER PRIMARY KEY UNIQUE,
10
+ user_id INTEGER DEFAULT 0,
12
11
  tsk VARCHAR NOT NULL,
13
12
  status VARCHAR DEFAULT todo,
14
13
  context VARCHAR DEFAULT inbox,
@@ -19,7 +18,7 @@ module Tsks
19
18
 
20
19
  storage.execute <<-SQL
21
20
  CREATE TABLE removed_tsks (
22
- tsk_id VARCHAR UNIQUE NOT NULL
21
+ tsk_id INTEGER UNIQUE NOT NULL
23
22
  )
24
23
  SQL
25
24
  end
@@ -62,7 +61,7 @@ module Tsks
62
61
  end
63
62
  end
64
63
 
65
- def self.update local_id, params=nil
64
+ def self.update tsk_id, params=nil
66
65
  storage = get_storage_instance
67
66
 
68
67
  if params && params.count == 1
@@ -73,13 +72,24 @@ module Tsks
73
72
  storage.execute(
74
73
  "UPDATE tsks SET " \
75
74
  "#{params.keys.first}=? " \
76
- "WHERE rowid=?",
77
- [params.values.first, local_id])
75
+ "WHERE id=?",
76
+ [params.values.first, tsk_id])
78
77
  else
79
- storage.execute "UPDATE tsks SET status='done' WHERE rowid=?", local_id
78
+ storage.execute "UPDATE tsks SET status='done' WHERE id=?", tsk_id
80
79
  end
81
80
  end
82
81
 
82
+ # TODO: write tests
83
+ def self.update_by tsk_params, params=nil
84
+ storage = get_storage_instance
85
+
86
+ storage.execute(
87
+ "UPDATE tsks SET " \
88
+ "#{params.keys.first}=? " \
89
+ "WHERE #{tsk_params.keys.first}=?",
90
+ [params.values.first, tsk_params.values.first])
91
+ end
92
+
83
93
  def self.select_by params
84
94
  storage = get_storage_instance
85
95
 
@@ -100,23 +110,10 @@ module Tsks
100
110
  tsks = structure_tsks raw_tsks
101
111
  end
102
112
 
103
- # TODO: write tests for Storage.select_local_id
104
- def self.select_local_id params
105
- storage = get_storage_instance
106
-
107
- tsk = storage.execute(
108
- "SELECT rowid, * FROM tsks WHERE #{params.keys.first}=? AND #{params.keys[1]}=? AND #{params.keys.last}=?",
109
- params.values.first, params.values[1], params.values.last)
110
-
111
- tsk_local_id = tsk[0][0]
112
- end
113
-
114
- def self.select_all local_id=true
113
+ def self.select_all
115
114
  storage = get_storage_instance
116
- raw_tsks = local_id ?
117
- storage.execute("SELECT rowid, * FROM tsks") :
118
- storage.execute("SELECT * FROM tsks")
119
- tsks = structure_tsks(raw_tsks, local_id=local_id)
115
+ raw_tsks = storage.execute("SELECT rowid, * FROM tsks")
116
+ tsks = structure_tsks raw_tsks
120
117
  end
121
118
 
122
119
  def self.select_active
@@ -125,17 +122,18 @@ module Tsks
125
122
  tsks = structure_tsks raw_tsks
126
123
  end
127
124
 
128
- def self.delete local_id
125
+ def self.delete tsk_id
129
126
  storage = get_storage_instance
130
- removed_tsks = storage.execute("SELECT * FROM tsks WHERE rowid=?", local_id)
127
+ removed_tsks = storage.execute("SELECT * FROM tsks WHERE id=?", tsk_id)
128
+
131
129
  if removed_tsks.empty?
132
130
  return false
133
131
  end
134
132
  storage.execute("INSERT INTO removed_tsks (tsk_id) VALUES (?)", removed_tsks[0][0])
135
- storage.execute("DELETE FROM tsks WHERE rowid=?", local_id)
133
+ storage.execute("DELETE FROM tsks WHERE id=?", tsk_id)
136
134
  end
137
135
 
138
- def self.select_removed_uuids
136
+ def self.select_removed_tsk_ids
139
137
  storage = get_storage_instance
140
138
  result = storage.execute("SELECT * FROM removed_tsks")
141
139
 
@@ -146,7 +144,7 @@ module Tsks
146
144
  return tsk_ids
147
145
  end
148
146
 
149
- def self.delete_removed_uuids
147
+ def self.delete_removed_tsk_ids
150
148
  storage = get_storage_instance
151
149
  storage.execute("DELETE FROM removed_tsks")
152
150
  end
@@ -157,30 +155,19 @@ module Tsks
157
155
  SQLite3::Database.new File.join CLI.setup_folder, "tsks.db"
158
156
  end
159
157
 
160
- def self.structure_tsks tsks, local_id=true
158
+ def self.structure_tsks tsks
161
159
  structured_tsks = []
162
160
 
163
161
  for tsk in tsks
164
162
  t = {}
165
-
166
- if local_id
167
- t[:local_id] = tsk[0]
168
- t[:id] = tsk[1]
169
- t[:user_id] = tsk[2]
170
- t[:tsk] = tsk[3]
171
- t[:status] = tsk[4]
172
- t[:context] = tsk[5]
173
- t[:created_at] = tsk[6]
174
- t[:updated_at] = tsk[7]
175
- else
176
- t[:id] = tsk[0]
177
- t[:user_id] = tsk[1]
178
- t[:tsk] = tsk[2]
179
- t[:status] = tsk[3]
180
- t[:context] = tsk[4]
181
- t[:created_at] = tsk[5]
182
- t[:updated_at] = tsk[6]
183
- end
163
+ t[:rowid] = tsk[0]
164
+ t[:id] = tsk[1]
165
+ t[:user_id] = tsk[2]
166
+ t[:tsk] = tsk[3]
167
+ t[:status] = tsk[4]
168
+ t[:context] = tsk[5]
169
+ t[:created_at] = tsk[6]
170
+ t[:updated_at] = tsk[7]
184
171
 
185
172
  structured_tsks.append t
186
173
  end
data/lib/tsks/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tsks
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.16"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luan Ramos Vicente
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-10 00:00:00.000000000 Z
11
+ date: 2023-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -92,11 +92,11 @@ files:
92
92
  - ".env.sample"
93
93
  - ".gitignore"
94
94
  - ".rspec"
95
- - ".travis.yml"
96
95
  - Gemfile
97
96
  - Gemfile.lock
98
97
  - README.md
99
98
  - Rakefile
99
+ - bin/build
100
100
  - bin/console
101
101
  - bin/install
102
102
  - bin/release
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.0
6
- before_install: gem install bundler -v 2.1.4