dsu 0.1.0.alpha.2 → 0.1.0.alpha.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +125 -23
- data/bin/console +0 -1
- data/lib/dsu/cli.rb +0 -9
- data/lib/dsu/models/entry_group.rb +18 -0
- data/lib/dsu/services/configuration_loader_service.rb +5 -7
- data/lib/dsu/services/temp_file_reader_service.rb +31 -0
- data/lib/dsu/services/temp_file_writer_service.rb +33 -0
- data/lib/dsu/subcommands/config.rb +34 -4
- data/lib/dsu/subcommands/edit.rb +43 -6
- data/lib/dsu/support/configuration.rb +5 -0
- data/lib/dsu/validators/entries_validator.rb +9 -12
- data/lib/dsu/version.rb +1 -1
- data/lib/dsu/views/entry_group/edit.rb +12 -5
- metadata +16 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c27f3abb1daf923976963a1612f08258fd8a0460d672c1674dc2c149aa69ed03
|
4
|
+
data.tar.gz: 8611ccb51518e24f9497ffc0c02a7b1dd567321419728f727969718620da5b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1b1bcd4f9222bf2629ffa0d02434b429280f20e760676f2cde2eaca40860f56952995ce7a69628981cc0f7caf941a48c07cca91a9c1f96b4334e872d5a7374a
|
7
|
+
data.tar.gz: 0436e614b146dbfd71ca098cc699d7b6de99cafe47cfbad8141ac6268853b6f7d68285d8222053796bb2db729cf86c14e03e3fa3f2dca97554fd78998449fbbe
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
## [0.1.0.alpha.
|
2
|
-
|
1
|
+
## [0.1.0.alpha.4] - 2023-05-09
|
2
|
+
* Changes
|
3
|
+
- Gemfile gemspec description changes.
|
4
|
+
## [0.1.0.alpha.3] - 2023-05-09
|
5
|
+
* Changes
|
6
|
+
- Entry groups are now editable using the `dsu edit SUBCOMMAND` command. See the README.md or `dsu help edit` for more information.
|
7
|
+
- Added `editor` configuration option to specify the editor to use when editing an entry group. This configuration option is used if the $EDITOR environment variable is not set.
|
8
|
+
* Bug fixes
|
9
|
+
- Fix bug that failed to load default configuration values properly when provided (surfaced in specs).
|
3
10
|
|
4
11
|
## [0.1.0.alpha.2] - 2023-05-08
|
5
|
-
* ATTENTION: After installing this pre-release, run `dsu config info` and take note of the `entries_folder` config option value (e.g. something like '/Users/<whoami>/dsu/entries' on a nix os). You'll need to delete the entry group files therein (
|
12
|
+
* ATTENTION: After installing this pre-release, run `dsu config info` and take note of the `entries_folder` config option value (e.g. something like '/Users/<whoami>/dsu/entries' on a nix os). You'll need to delete the entry group files therein ( \<YYYY\>\-\<MM\>\-\<DD\>.json e.g. 2023-05-07.json) to avoid errors when running this version of `dsu`.
|
6
13
|
* WIP (not fully implemented yet)
|
7
14
|
- Added `dsu edit` command to edit an existing entry.
|
8
15
|
* Changes
|
@@ -13,3 +20,6 @@
|
|
13
20
|
- `dsu config info` now displays the default configuration being used if no configuration file is being used.
|
14
21
|
* Bug fixes
|
15
22
|
- Fix bug that fails to load/use configuration file options when a config file exists.
|
23
|
+
|
24
|
+
## [0.1.0.alpha.1] - 2023-05-06
|
25
|
+
- Initial (alpha) release. See README.md for instructions.
|
data/Gemfile
CHANGED
@@ -5,12 +5,12 @@ source 'https://rubygems.org'
|
|
5
5
|
# Specify your gem's dependencies in dsu.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
+
gem 'dotenv', '~> 2.8', '>= 2.8.1'
|
8
9
|
gem 'rake', '~> 13.0'
|
9
10
|
gem 'rspec', '~> 3.0'
|
10
11
|
gem 'rubocop', '~> 1.50', '>= 1.50.2'
|
11
12
|
gem 'rubocop-performance', '~> 1.17', '>= 1.17.1'
|
12
13
|
gem 'rubocop-rspec', '~> 2.20'
|
13
|
-
gem 'dotenv', '~> 2.8', '>= 2.8.1'
|
14
14
|
|
15
15
|
gem 'factory_bot', '~> 6.2', '>= 6.2.1'
|
16
16
|
gem 'ffaker', '~> 2.21'
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
**NOTE:** This gem is in development (alpha version). Please see the [WIP Notes](#wip-notes) section for current `dsu` features.
|
13
13
|
|
14
|
-
##
|
14
|
+
## Help
|
15
15
|
|
16
16
|
After installation (`gem install dsu`), the first thing you may want to do is run the `dsu` help:
|
17
17
|
### Displaying Help
|
@@ -32,32 +32,33 @@ Options:
|
|
32
32
|
|
33
33
|
The next thing you may want to do is `add` some DSU activities (entries) for a particular day:
|
34
34
|
|
35
|
-
|
35
|
+
## Adding DSU Entries
|
36
36
|
`dsu add [OPTIONS] DESCRIPTION`
|
37
37
|
|
38
38
|
Adding DSU entry using this command will _add_ the DSU entry for the given day (or date, `-d`), and also _display_ the given day's (or date's, `-d`) DSU entries, as well as the DSU entries for the previous day relative to the given day or date (`-d`).
|
39
39
|
|
40
|
-
|
41
|
-
If you need to add a DSU entry to the current day (today), you can use the `-
|
40
|
+
### Today
|
41
|
+
If you need to add a DSU entry to the current day (today), you can use the `-n`|`--today` option. Today (`-n`) is the default; therefore, the `-n` flag is optional when adding DSU entries for the current day:
|
42
42
|
|
43
|
-
`$ dsu add
|
43
|
+
`$ dsu add -n|-today "Pair with John on ticket IN-12345"`
|
44
44
|
|
45
|
-
|
46
|
-
If for some reason you need to add a DSU entry for
|
45
|
+
### Yesterday
|
46
|
+
If for some reason you need to add a DSU entry for yesterday, you can use the `-y`| `--yesterday` option:
|
47
47
|
|
48
|
-
`$ dsu add -
|
48
|
+
`$ dsu add -y|--yesterday "Pick up ticket IN-12345"`
|
49
49
|
|
50
|
-
|
51
|
-
If you need to add a DSU entry for
|
50
|
+
### Tomorrow
|
51
|
+
If you need to add a DSU entry for tomorrow, you can use the `-t`|`--tomorrow` option:
|
52
52
|
|
53
|
-
`$ dsu add -
|
53
|
+
`$ dsu add -t|--tomorrow "Pick up ticket IN-12345"`
|
54
54
|
|
55
|
-
|
56
|
-
If you need to add a DSU entry for a date other than yesterday, today or tomorrow, you can use the `-d, [--date=DATE]` option, where DATE is any date string that can be parsed using `Time.parse`. For example: `require 'time'; Time.parse("2023-01-01")`:
|
55
|
+
### Miscellaneous Date
|
57
56
|
|
58
57
|
`$ dsu add -d "2022-12-31" "Attend company New Years Coffee Meet & Greet"`
|
59
58
|
|
60
|
-
|
59
|
+
See the [Dates](#dates) section for more information on acceptable DATE formats used by `dsu`.
|
60
|
+
|
61
|
+
## Displaying DSU Entries
|
61
62
|
You can display DSU entries for a particular day or date (`date`) using any of the following commands. When displaying DSU entries for a particular day or date (`date`), `dsu` will display the given day or date's (`date`) DSU entries, as well as the DSU entries for the _previous_ day, relative to the given day or date. If the date or day you are trying to view falls on a weekend or Monday, `dsu` will display back to, and including the weekend and previous Friday inclusive; this is so that you can share what you did over the weekend (if anything) and the previous Friday at your DSU:
|
62
63
|
|
63
64
|
- `$ dsu list today|n`
|
@@ -65,7 +66,7 @@ You can display DSU entries for a particular day or date (`date`) using any of t
|
|
65
66
|
- `$ dsu list yesterday|y`
|
66
67
|
- `$ dsu list date|d DATE`
|
67
68
|
|
68
|
-
|
69
|
+
### Examples
|
69
70
|
The following displays the entries for "Today", where `Time.now == '2023-05-06 08:54:57.6861 -0400'`
|
70
71
|
|
71
72
|
`$ dsu list today`
|
@@ -82,7 +83,7 @@ Friday, (Yesterday) 2023-05-05
|
|
82
83
|
|
83
84
|
`$ dsu list date "2023-05-06"`
|
84
85
|
|
85
|
-
|
86
|
+
See the [Dates](#dates) section for more information on acceptable DATE formats used by `dsu`.
|
86
87
|
|
87
88
|
```shell
|
88
89
|
#=>
|
@@ -94,12 +95,100 @@ Friday, (Yesterday) 2023-05-05
|
|
94
95
|
1. edc25a9a Pick up ticket IN-12345
|
95
96
|
2. f7d3018c Attend new hire meet & greet
|
96
97
|
```
|
98
|
+
## Editing DSU Entries
|
99
|
+
|
100
|
+
You can edit DSU entry groups by date. `dsu` will allow you to edit a DSU entry group using the `dsu edit SUBCOMMAND` date (today|tomorrow|yesterday|date DATE) you specify. `dsu edit` will open your DSU entry group entries in your editor, where you'll be able to perform editing functions against one or all of the entries.
|
101
|
+
|
102
|
+
Note: See the "[Customizing the `dsu` Configuration File](#customizing-the-dsu-configuration-file)"" section to configure `dsu` to use the editor of your choice.
|
103
|
+
|
104
|
+
- `$ dsu edit today|n`
|
105
|
+
- `$ dsu edit tomorrow|t`
|
106
|
+
- `$ dsu edit yesterday|y`
|
107
|
+
- `$ dsu edit date|d DATE`
|
108
|
+
|
109
|
+
### Examples
|
110
|
+
|
111
|
+
The following will edit your DSU entry group entries for "Today", where `Time.now == '2023-05-09 12:13:45.8273 -0400'`. Simply follow the directions in the editor file, then save and close your editor to apply the changes:
|
112
|
+
|
113
|
+
`$ dsu edit today`
|
114
|
+
`$ dsu e n`
|
115
|
+
|
116
|
+
```shell
|
117
|
+
#=> In your editor, you will see...
|
118
|
+
# Editing DSU Entries for Tuesday, (Today) 2023-05-09 EDT
|
119
|
+
|
120
|
+
# [SHA/COMMAND] [DESCRIPTION]
|
121
|
+
3849f0c0 Interative planning meeting 11:00AM.
|
122
|
+
586478f5 Pair with Chad on ticket 31211.
|
123
|
+
9e5f82c8 Investigate spike ticket 31255.
|
124
|
+
59b25ca7 Review Kelsey's PR ticket 30721.
|
125
|
+
|
126
|
+
# INSTRUCTIONS:
|
127
|
+
# ADD a DSU entry: use one of the following commands: [+|a|add] followed by the description.
|
128
|
+
# EDIT a DSU entry: change the description.
|
129
|
+
# DELETE a DSU entry: delete the entry or replace the sha with one of the following commands: [-|d|delete].
|
130
|
+
# NOTE: deleting all the entries will delete the entry group file;
|
131
|
+
# this is preferable if this is what you want to do :)
|
132
|
+
# REORDER a DSU entry: reorder the DSU entries in order preference.
|
133
|
+
#
|
134
|
+
# *** When you are done, save and close your editor ***
|
135
|
+
```
|
136
|
+
|
137
|
+
#### Edit an Entry
|
138
|
+
|
139
|
+
Simply change the entry descripton text.
|
140
|
+
|
141
|
+
For example...
|
142
|
+
```
|
143
|
+
from: 3849f0c0 Interative planning meeting 11:00AM.
|
144
|
+
to: 3849f0c0 Interative planning meeting 12:00AM.
|
145
|
+
```
|
146
|
+
|
147
|
+
#### Add an Entry
|
148
|
+
|
149
|
+
Replace the entry `sha` one of the add commands: `[+|a|add]`.
|
150
|
+
|
151
|
+
For example...
|
152
|
+
```
|
153
|
+
+ Add me to this entry group.
|
154
|
+
```
|
155
|
+
|
156
|
+
#### Delete an Entry
|
157
|
+
|
158
|
+
Simply delete the entry or replace the entry `sha` one of the delete commands: `[-|d|delete]`.
|
159
|
+
|
160
|
+
For example...
|
161
|
+
```
|
162
|
+
# Delete this this entry from the editor file
|
163
|
+
3849f0c0 Interative planning meeting 11:00AM.
|
164
|
+
```
|
165
|
+
or
|
166
|
+
```
|
167
|
+
from: 3849f0c0 Interative planning meeting 11:00AM.
|
168
|
+
to: - Interative planning meeting 11:00AM.
|
169
|
+
```
|
97
170
|
|
98
|
-
|
171
|
+
#### Reorder Entries
|
172
|
+
|
173
|
+
Simply reorder the entries in the editor.
|
174
|
+
|
175
|
+
For example...
|
176
|
+
```
|
177
|
+
from: 3849f0c0 Interative planning meeting 11:00AM.
|
178
|
+
586478f5 Pair with Chad on ticket 31211.
|
179
|
+
9e5f82c8 Investigate spike ticket 31255.
|
180
|
+
59b25ca7 Review Kelsey's PR ticket 30721.
|
181
|
+
to: 59b25ca7 Review Kelsey's PR ticket 30721.
|
182
|
+
9e5f82c8 Investigate spike ticket 31255.
|
183
|
+
586478f5 Pair with Chad on ticket 31211.
|
184
|
+
3849f0c0 Interative planning meeting 11:00AM.
|
185
|
+
```
|
186
|
+
|
187
|
+
## Customizing the `dsu` Configuration File
|
99
188
|
|
100
189
|
It is **not** recommended that you create and customize a `dsu` configuration file while this gem is in alpha release. This is because changes to what configuration options are available may take place while in alpha that could break `dsu`. If you *do* want to create and customize the `dsu` configuration file reglardless, you may do the following.
|
101
190
|
|
102
|
-
|
191
|
+
### Initializing/Customizing the `dsu` Configuration File
|
103
192
|
|
104
193
|
```shell
|
105
194
|
# Creates a dsu configuration file in your home folder.
|
@@ -109,6 +198,7 @@ $ dsu config init
|
|
109
198
|
Configuration file (/Users/<whoami>/.dsu) created.
|
110
199
|
Config file (/Users/<whoami>/.dsu) contents:
|
111
200
|
---
|
201
|
+
editor: nano
|
112
202
|
entries_display_order: desc
|
113
203
|
entries_file_name: "%Y-%m-%d.json"
|
114
204
|
entries_folder: "/Users/<whoami>/dsu/entries"
|
@@ -118,20 +208,26 @@ Where `<whoami>` would be your username (`$ whoami` on nix systems)
|
|
118
208
|
|
119
209
|
Once the configuration file is created, you can locate where the `dsu` configuration file is located by running `$ dsu config info` and taking note of the confiruration file path. You may then edit this file using your favorite editor.
|
120
210
|
|
121
|
-
|
122
|
-
|
211
|
+
#### Configuration File Options
|
212
|
+
|
213
|
+
##### editor
|
214
|
+
This is the default editor to use when editing entry groups if the EDITOR environment variable on your system is not set.
|
215
|
+
|
216
|
+
Default: `nano` (you'll need to change the default editor on Windows systems)
|
217
|
+
|
218
|
+
##### entries_display_order
|
123
219
|
Valid values are 'asc' and 'desc', and will sort listed DSU entries in ascending or descending order respectfully, by day.
|
124
220
|
|
125
221
|
Default: `'desc'`
|
126
222
|
|
127
|
-
|
223
|
+
##### entries_file_name
|
128
224
|
The entries file name format. It is recommended that you do not change this. The file name must include `%Y`, `%m` and `%d` `Time` formatting specifiers to make sure the file name is unique and able to be located by `dsu` functions. For example, the default file name is `%Y-%m-%d.json`; however, something like `%m-%d-%Y.json` or `entry-group-%m-%d-%Y.json` would work as well.
|
129
225
|
|
130
226
|
ATTENTION: Please keep in mind that if you change this value `dsu` will not recognize entry files using a different format. You would (at this time), have to manually rename any existing entry file names to the new format.
|
131
227
|
|
132
228
|
Default: `'%Y-%m-%d.json'`
|
133
229
|
|
134
|
-
|
230
|
+
##### entries_folder
|
135
231
|
This is the folder where `dsu` stores entry files. You may change this to anything you want. `dsu` will create this folder for you, as long as your system's write permissions allow this.
|
136
232
|
|
137
233
|
ATTENTION: Please keep in mind that if you change this value `dsu` will not be able to find entry files in any previous folder. You would (at this time), have to manually mode any existing entry files to this new folder.
|
@@ -140,8 +236,14 @@ Default: `'/Users/<whoami>/dsu/entries'` on nix systems.
|
|
140
236
|
|
141
237
|
Where `<whoami>` would be your username (`$ whoami` on nix systems)
|
142
238
|
|
239
|
+
## Dates
|
240
|
+
|
241
|
+
These notes apply to anywhere DATE is used...
|
242
|
+
|
243
|
+
DATE may be any date string that can be parsed using `Time.parse`. Consequently, you may use also use '/' as date separators, as well as omit the year if the date you want to display is the current year (e.g. <month>/<day>, or 1/31). For example: `require 'time'; Time.parse('2023-01-02'); Time.parse('1/2') # etc.`
|
244
|
+
|
143
245
|
## WIP Notes
|
144
|
-
This gem is in development (alpha release)
|
246
|
+
This gem is in development (alpha release).
|
145
247
|
|
146
248
|
## Installation
|
147
249
|
|
data/bin/console
CHANGED
data/lib/dsu/cli.rb
CHANGED
@@ -7,17 +7,8 @@ require_relative 'subcommands/edit'
|
|
7
7
|
require_relative 'subcommands/list'
|
8
8
|
|
9
9
|
module Dsu
|
10
|
-
#
|
11
10
|
# The `dsu` command.
|
12
|
-
#
|
13
11
|
class CLI < BaseCLI
|
14
|
-
# map %w[add -a] => :add
|
15
|
-
# map %w[config -c] => :config
|
16
|
-
# map %w[edit -e] => :edit
|
17
|
-
# #map %w[help -h] => :help
|
18
|
-
# map %w[list -l] => :list
|
19
|
-
# map %w[version -v] => :version
|
20
|
-
|
21
12
|
map %w[a -a] => :add
|
22
13
|
map %w[c -c] => :config
|
23
14
|
map %w[e -e] => :edit
|
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'deco_lite'
|
4
4
|
require_relative '../support/entry_group_loadable'
|
5
|
+
require_relative '../services/entry_group_deleter_service'
|
5
6
|
require_relative '../services/entry_group_reader_service'
|
7
|
+
require_relative '../services/entry_group_writer_service'
|
6
8
|
require_relative '../validators/entries_validator'
|
7
9
|
require_relative '../validators/time_validator'
|
8
10
|
|
@@ -30,6 +32,10 @@ module Dsu
|
|
30
32
|
end
|
31
33
|
|
32
34
|
class << self
|
35
|
+
def delete(time:, options: {})
|
36
|
+
Services::EntryGroupDeleterService.new(time: time, options: options).call
|
37
|
+
end
|
38
|
+
|
33
39
|
def exists?(time:)
|
34
40
|
Dsu::Services::EntryGroupReaderService.entry_group_file_exists?(time: time)
|
35
41
|
end
|
@@ -53,6 +59,18 @@ module Dsu
|
|
53
59
|
%i[time entries]
|
54
60
|
end
|
55
61
|
|
62
|
+
def save!
|
63
|
+
validate!
|
64
|
+
Services::EntryGroupWriterService.new(entry_group: self).call
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
# Deletes the entry group file from the file system.
|
69
|
+
def delete
|
70
|
+
self.class.delete(time: time)
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
56
74
|
def to_h
|
57
75
|
super.tap do |hash|
|
58
76
|
hash[:entries] = hash[:entries].dup
|
@@ -15,24 +15,22 @@ module Dsu
|
|
15
15
|
unless default_options.nil? ||
|
16
16
|
default_options.is_a?(Hash) ||
|
17
17
|
default_options.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
18
|
-
raise ArgumentError, 'default_options must be a Hash'
|
18
|
+
raise ArgumentError, 'default_options must be a Hash or ActiveSupport::HashWithIndifferentAccess'
|
19
19
|
end
|
20
20
|
|
21
|
-
@default_options
|
21
|
+
@default_options ||= default_options || {}
|
22
22
|
@default_options = @default_options.with_indifferent_access if @default_options.is_a?(Hash)
|
23
23
|
end
|
24
24
|
|
25
25
|
def call
|
26
|
-
|
27
|
-
|
28
|
-
config_options.with_indifferent_access
|
26
|
+
config_options.merge(default_options).with_indifferent_access
|
29
27
|
end
|
30
28
|
|
31
29
|
private
|
32
30
|
|
33
|
-
attr_writer :default_options
|
34
|
-
|
35
31
|
def config_options
|
32
|
+
return Support::Configuration::DEFAULT_DSU_OPTIONS unless config_file?
|
33
|
+
|
36
34
|
@config_options ||= YAML.safe_load(ERB.new(File.read(config_file)).result)
|
37
35
|
end
|
38
36
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dsu
|
4
|
+
module Services
|
5
|
+
class TempFileReaderService
|
6
|
+
def initialize(temp_file_path:, options: {})
|
7
|
+
raise ArgumentError, 'temp_file_path is nil' if temp_file_path.nil?
|
8
|
+
raise ArgumentError, 'temp_file_path is the wrong object type' unless temp_file_path.is_a?(String)
|
9
|
+
raise ArgumentError, 'temp_file_path is empty' if temp_file_path.empty?
|
10
|
+
raise ArgumentError, 'temp_file_path does not exist' unless File.exist?(temp_file_path)
|
11
|
+
raise ArgumentError, 'options is nil' if options.nil?
|
12
|
+
raise ArgumentError, 'options is the wrong object type' unless options.is_a?(Hash)
|
13
|
+
|
14
|
+
@temp_file_path = temp_file_path
|
15
|
+
@options = options || {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
raise ArgumentError, 'no block given' unless block_given?
|
20
|
+
|
21
|
+
File.foreach(temp_file_path) do |line|
|
22
|
+
yield line.strip
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :temp_file_path, :options
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
module Dsu
|
6
|
+
module Services
|
7
|
+
class TempFileWriterService
|
8
|
+
def initialize(temp_file_content:, options: {})
|
9
|
+
raise ArgumentError, 'temp_file_content is nil' if temp_file_content.nil?
|
10
|
+
raise ArgumentError, 'temp_file_content is the wrong object type' unless temp_file_content.is_a?(String)
|
11
|
+
raise ArgumentError, 'options is nil' if options.nil?
|
12
|
+
raise ArgumentError, 'options is the wrong object type' unless options.is_a?(Hash)
|
13
|
+
|
14
|
+
@temp_file_content = temp_file_content
|
15
|
+
@options = options || {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
raise ArgumentError, 'no block given' unless block_given?
|
20
|
+
|
21
|
+
Tempfile.new('dsu').tap do |file|
|
22
|
+
file.write("#{temp_file_content}\n")
|
23
|
+
file.close
|
24
|
+
yield file.path
|
25
|
+
end.unlink
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :temp_file_content, :options
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -33,14 +33,44 @@ module Dsu
|
|
33
33
|
desc 'init', 'Creates and initializes a .dsu file in your home folder'
|
34
34
|
long_desc <<-LONG_DESC
|
35
35
|
NAME
|
36
|
-
|
37
|
-
`dsu config init` -- will create and initialize a .dsu file
|
38
|
-
in the "#{Dsu::Support::FolderLocations.root_folder}" folder.
|
36
|
+
|
37
|
+
`dsu config init` -- will create and initialize a .dsu file ("#{Dsu::Support::FolderLocations.root_folder}/.dsu") that you may edit. Otherwise, the default configuration will be used.
|
39
38
|
|
40
39
|
SYNOPSIS
|
41
|
-
|
40
|
+
|
42
41
|
dsu config init
|
42
|
+
|
43
|
+
CONFIGURATION FILE OPTIONS
|
44
|
+
|
45
|
+
The following configuration file options are available:
|
46
|
+
|
47
|
+
editor:
|
48
|
+
|
49
|
+
The default editor to use when editing entry groups if the EDITOR environment variable on your system is not set. The default is 'nano'. You'll need to change the default editor on Windows systems.
|
50
|
+
|
51
|
+
entries_display_order:
|
52
|
+
|
53
|
+
The order by which entries will be displayed, 'asc' or 'desc' (ascending or descending, respectively).
|
54
|
+
|
55
|
+
Default: 'desc'
|
56
|
+
|
57
|
+
entries_file_name:
|
58
|
+
|
59
|
+
The entries file name format. It is recommended that you do not change this. The file name must include `%Y`, `%m` and `%d` `Time` formatting specifiers to make sure the file name is unique and able to be located by `dsu` functions. For example, the default file name is `%Y-%m-%d.json`; however, something like `%m-%d-%Y.json` or `entry-group-%m-%d-%Y.json` would work as well.
|
60
|
+
|
61
|
+
ATTENTION: Please keep in mind that if you change this value `dsu` will not recognize entry files using a different format. You would (at this time), have to manually rename any existing entry file names to the new format.
|
62
|
+
|
63
|
+
Default: '%Y-%m-%d.json'
|
64
|
+
|
65
|
+
entries_folder:
|
66
|
+
|
67
|
+
This is the folder where `dsu` stores entry files. You may change this to anything you want. `dsu` will create this folder for you, as long as your system's write permissions allow this.
|
68
|
+
|
69
|
+
ATTENTION: Please keep in mind that if you change this value `dsu` will not be able to find entry files in any previous folder. You would (at this time), have to manually mode any existing entry files to this new folder.
|
70
|
+
|
71
|
+
Default: "'#{Dsu::Support::FolderLocations.root_folder}/dsu/entries'"
|
43
72
|
LONG_DESC
|
73
|
+
|
44
74
|
def init
|
45
75
|
create_config_file!
|
46
76
|
end
|
data/lib/dsu/subcommands/edit.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'English'
|
3
4
|
require_relative '../base_cli'
|
4
5
|
require_relative '../models/entry_group'
|
6
|
+
require_relative '../services/temp_file_reader_service'
|
7
|
+
require_relative '../services/temp_file_writer_service'
|
5
8
|
require_relative '../support/time_formatable'
|
6
9
|
require_relative '../views/entry_group/edit'
|
10
|
+
require_relative '../views/entry_group/show'
|
7
11
|
|
8
12
|
module Dsu
|
9
13
|
module Subcommands
|
@@ -21,7 +25,7 @@ module Dsu
|
|
21
25
|
Edits the DSU entries for today.
|
22
26
|
LONG_DESC
|
23
27
|
def today
|
24
|
-
edit_entry_group(time: Time.now)
|
28
|
+
Views::EntryGroup::Show.new(entry_group: edit_entry_group(time: Time.now)).render
|
25
29
|
end
|
26
30
|
|
27
31
|
desc 'tomorrow, t',
|
@@ -30,7 +34,7 @@ module Dsu
|
|
30
34
|
Edits the DSU entries for tomorrow.
|
31
35
|
LONG_DESC
|
32
36
|
def tomorrow
|
33
|
-
edit_entry_group(time: Time.now.tomorrow)
|
37
|
+
Views::EntryGroup::Show.new(entry_group: edit_entry_group(time: Time.now.tomorrow)).render
|
34
38
|
end
|
35
39
|
|
36
40
|
desc 'yesterday, y',
|
@@ -39,7 +43,7 @@ module Dsu
|
|
39
43
|
Edits the DSU entries for yesterday.
|
40
44
|
LONG_DESC
|
41
45
|
def yesterday
|
42
|
-
edit_entry_group(time: Time.now.yesterday)
|
46
|
+
Views::EntryGroup::Show.new(entry_group: edit_entry_group(time: Time.now.yesterday)).render
|
43
47
|
end
|
44
48
|
|
45
49
|
desc 'date, d DATE',
|
@@ -50,7 +54,7 @@ module Dsu
|
|
50
54
|
\x5 #{date_option_description}
|
51
55
|
LONG_DESC
|
52
56
|
def date(date)
|
53
|
-
edit_entry_group(time: Time.parse(date))
|
57
|
+
Views::EntryGroup::Show.new(entry_group: edit_entry_group(time: Time.parse(date))).render
|
54
58
|
rescue ArgumentError => e
|
55
59
|
say "Error: #{e.message}", ERROR
|
56
60
|
exit 1
|
@@ -67,12 +71,45 @@ module Dsu
|
|
67
71
|
|
68
72
|
say "Editing DSU entries for #{formatted_time}..."
|
69
73
|
entry_group = Models::EntryGroup.load(time: time)
|
70
|
-
# system("${EDITOR:-nano} #{file_path}")
|
71
74
|
|
75
|
+
# This renders the view to a string...
|
72
76
|
output = capture_stdxxx do
|
73
77
|
Views::EntryGroup::Edit.new(entry_group: entry_group).render
|
74
78
|
end
|
75
|
-
|
79
|
+
# ...which is then written to a temp file.
|
80
|
+
Services::TempFileWriterService.new(temp_file_content: output).call do |temp_file_path|
|
81
|
+
unless system("${EDITOR:-#{configuration[:editor]}} #{temp_file_path}")
|
82
|
+
say "Failed to open temporary file in editor '#{configuration[:editor]}';" \
|
83
|
+
"the system error returned was: '#{$CHILD_STATUS}'.", ERROR
|
84
|
+
say 'Either set the EDITOR environment variable ' \
|
85
|
+
'or set the dsu editor configuration option (`$ dsu config init`).', ERROR
|
86
|
+
say 'Run `$ dsu help config` for more information.', ERROR
|
87
|
+
system('dsu help config')
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
entries = []
|
91
|
+
Services::TempFileReaderService.new(temp_file_path: temp_file_path).call do |temp_file_line|
|
92
|
+
# Skip comments and blank lines.
|
93
|
+
next if ['#', nil].include? temp_file_line[0]
|
94
|
+
|
95
|
+
match_data = temp_file_line.match(/(\S+)\s(.+)/)
|
96
|
+
# TODO: Error handling if match_data is nil.
|
97
|
+
entry_sha = match_data[1]
|
98
|
+
entry_description = match_data[2]
|
99
|
+
|
100
|
+
next if %w[- d delete].include?(entry_sha) # delete the entry
|
101
|
+
|
102
|
+
entry_sha = nil if %w[+ a add].include?(entry_sha) # add the new entry
|
103
|
+
entries << Models::Entry.new(uuid: entry_sha, description: entry_description)
|
104
|
+
end
|
105
|
+
|
106
|
+
entry_group.entries = entries
|
107
|
+
|
108
|
+
return entry_group.delete if entries.empty?
|
109
|
+
|
110
|
+
entry_group.save!
|
111
|
+
end
|
112
|
+
entry_group
|
76
113
|
end
|
77
114
|
|
78
115
|
# https://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby/4459463#4459463
|
@@ -18,6 +18,11 @@ module Dsu
|
|
18
18
|
|
19
19
|
# rubocop:disable Style/StringHashKeys - YAML writing/loading necessitates this
|
20
20
|
DEFAULT_DSU_OPTIONS = {
|
21
|
+
# The default editor to use when editing entry groups if the EDITOR
|
22
|
+
# environment variable on your system is not set. On nix systmes,
|
23
|
+
# the default editor is`nano`. You need to change this default on
|
24
|
+
# Windows systems.
|
25
|
+
'editor' => 'nano',
|
21
26
|
# The order by which entries should be displayed by default:
|
22
27
|
# asc or desc, ascending or descending, respectively.
|
23
28
|
'entries_display_order' => 'desc',
|
@@ -12,14 +12,14 @@ module Dsu
|
|
12
12
|
def validate(record)
|
13
13
|
raise 'options[:fields] is not defined.' unless options.key? :fields
|
14
14
|
raise 'options[:fields] is not an Array.' unless options[:fields].is_a? Array
|
15
|
-
raise 'options[:fields] elements are not Symbols.' unless options[:fields].all?
|
15
|
+
raise 'options[:fields] elements are not Symbols.' unless options[:fields].all?(Symbol)
|
16
16
|
|
17
17
|
options[:fields].each do |field|
|
18
18
|
entries = record.send(field)
|
19
19
|
|
20
20
|
unless entries.is_a?(Array)
|
21
21
|
record.errors.add(field, 'is the wrong object type. ' \
|
22
|
-
|
22
|
+
"\"Array\" was expected, but \"#{entries.class}\" was received.")
|
23
23
|
next
|
24
24
|
end
|
25
25
|
|
@@ -35,7 +35,7 @@ module Dsu
|
|
35
35
|
next if entry.is_a? Dsu::Models::Entry
|
36
36
|
|
37
37
|
record.errors.add(field, 'entry Array element is the wrong object type. ' \
|
38
|
-
|
38
|
+
"\"Entry\" was expected, but \"#{entry.class}\" was received.",
|
39
39
|
type: Dsu::Support::FieldErrors::FIELD_TYPE_ERROR)
|
40
40
|
|
41
41
|
next
|
@@ -47,16 +47,13 @@ module Dsu
|
|
47
47
|
|
48
48
|
entry_objects = entries.select { |entry| entry.is_a?(Dsu::Models::Entry) }
|
49
49
|
|
50
|
-
entry_objects.map(&:uuid)
|
51
|
-
|
52
|
-
end
|
50
|
+
uuids = entry_objects.map(&:uuid)
|
51
|
+
return if uuids.uniq.length == uuids.length
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
type: Dsu::Support::FieldErrors::FIELD_DUPLICATE_ERROR)
|
59
|
-
end
|
53
|
+
non_unique_uuids = uuids.select { |element| uuids.count(element) > 1 }.uniq
|
54
|
+
if non_unique_uuids.any?
|
55
|
+
record.errors.add(field, "contains duplicate UUIDs: #{non_unique_uuids.join(', ')}.",
|
56
|
+
type: Dsu::Support::FieldErrors::FIELD_DUPLICATE_ERROR)
|
60
57
|
end
|
61
58
|
end
|
62
59
|
end
|
data/lib/dsu/version.rb
CHANGED
@@ -45,17 +45,24 @@ module Dsu
|
|
45
45
|
say('(no entries available for this day)') and return if entry_group.entries.empty?
|
46
46
|
|
47
47
|
say ''
|
48
|
+
say '# [SHA/COMMAND] [DESCRIPTION]'
|
48
49
|
|
49
50
|
entry_group.entries.each do |entry|
|
50
51
|
say "#{entry.uuid} #{entry.description}"
|
51
52
|
end
|
52
53
|
|
53
54
|
say ''
|
54
|
-
say '#
|
55
|
-
say
|
56
|
-
'
|
57
|
-
say '#
|
58
|
-
|
55
|
+
say '# INSTRUCTIONS:'
|
56
|
+
say '# ADD a DSU entry: use one of the following commands: [+|a|add] ' \
|
57
|
+
'followed by the description.'
|
58
|
+
say '# EDIT a DSU entry: change the description.'
|
59
|
+
say '# DELETE a DSU entry: delete the entry or replace the sha with one ' \
|
60
|
+
'of the following commands: [-|d|delete].'
|
61
|
+
say '# NOTE: deleting all the entries will delete the entry group file; '
|
62
|
+
say '# this is preferable if this is what you want to do :)'
|
63
|
+
say '# REORDER a DSU entry: reorder the DSU entries in order preference.'
|
64
|
+
say '#'
|
65
|
+
say '# *** When you are done, save and close your editor ***'
|
59
66
|
end
|
60
67
|
end
|
61
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.alpha.
|
4
|
+
version: 0.1.0.alpha.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gene M. Angelo, Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -112,12 +112,18 @@ dependencies:
|
|
112
112
|
- - "~>"
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '1.0'
|
115
|
-
description:
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
115
|
+
description: " dsu is little gem that helps manage your Agile DSU (Daily Stand
|
116
|
+
Up) participation. How? by providing a simple command line interface (CLI) which
|
117
|
+
allows you to create, read, update, and delete (CRUD) noteworthy activities that
|
118
|
+
you performed during your day. During your DSU, you can then easily recall and share
|
119
|
+
these these activities with your team. Activities are grouped by day and can be
|
120
|
+
viewed in simple text format from the command line. When displaying DSU entries
|
121
|
+
for a particular day or date (date), dsu will display the given day or date's (date)
|
122
|
+
DSU entries, as well as the DSU entries for the previous day, relative to the given
|
123
|
+
day or date. If the date or day you are trying to view falls on a weekend or Monday,
|
124
|
+
dsu will display back to, and including the weekend and previous Friday inclusive;
|
125
|
+
this is so that you can share what you did over the weekend (if anything) and the
|
126
|
+
previous Friday at your DSU.\n"
|
121
127
|
email:
|
122
128
|
- public.gma@gmail.com
|
123
129
|
executables:
|
@@ -151,6 +157,8 @@ files:
|
|
151
157
|
- lib/dsu/services/entry_group_reader_service.rb
|
152
158
|
- lib/dsu/services/entry_group_writer_service.rb
|
153
159
|
- lib/dsu/services/entry_hydrator_service.rb
|
160
|
+
- lib/dsu/services/temp_file_reader_service.rb
|
161
|
+
- lib/dsu/services/temp_file_writer_service.rb
|
154
162
|
- lib/dsu/subcommands/config.rb
|
155
163
|
- lib/dsu/subcommands/edit.rb
|
156
164
|
- lib/dsu/subcommands/list.rb
|