dayrb 2.0.4 → 2.0.5

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
- SHA1:
3
- metadata.gz: 9bd54d621f2ea27a6da4f10359e31ff7a365c9d1
4
- data.tar.gz: 15e902f847d739d4d13fac1a05ec6e5ebe473e74
2
+ SHA256:
3
+ metadata.gz: e50c30b0000ccc24e77b817926f38361c57d88dbce651c494807b4dd4e80418b
4
+ data.tar.gz: dcafa943ff153920c433c069aa4631badb97505a75601c19b5960a1ce95d4263
5
5
  SHA512:
6
- metadata.gz: 89b92e1d09a1501b9a12816f5661c299eebce95948cc1b838d6a212f54e1b60409c81a5bdc676b1c43116e0bcd996c9b758756223aa0d4c9952632cbe9c00b59
7
- data.tar.gz: 4097d69eeb3ea33c1806db806c61dc92e3d271b1bf179eea1fc33c56dc675d0cb1bd60134c7fb9d39e5868dc8ade11f3c69aadc44f7b17e6dd4d5a68c80c880a
6
+ metadata.gz: 4f097fefc6b32690049cecf2c1ba8a9adb21c64f8a8274c235915383faef462e67d7ae73b4b06234105648194d1e2066bb9b6cb2bb069a585bc9f636dcf8324e
7
+ data.tar.gz: 22fce23b5c01a6376065ed6054b35a8d1128a767f114916fc1b82f07f1159d91168a7aeac2f7b7aaeaca11a4cf28ac9471154ca4000ecc90aaa2d696a7b2a40d
data/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
  The MIT License (MIT)
2
- Copyright © 2014 Cameron Carroll, http://ckcarroll.herokuapp.com
2
+ Copyright © 2024 Cam Carroll, http://ieve.me
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
5
 
data/bin/day.rb CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  # DayRB Main File
4
4
  # Day.rb is a minimalistic command-line to-do and time-tracking application.
5
- # Created in July 2013
5
+ # Created in July 2013, last updated September 2024
6
6
  # See 'day.rb help' for usage.
7
7
  #
8
- # MIT License; See LICENSE file; Cameron Carroll 2015
8
+ # MIT License; See LICENSE file; Cam Carroll 2024
9
9
 
10
10
  require_relative '../lib/day/configuration'
11
11
  require_relative '../lib/day/tasklist'
@@ -14,14 +14,17 @@ require_relative '../lib/day/presenter'
14
14
 
15
15
  require 'fileutils'
16
16
 
17
- VERSION = '2.0.4'
17
+ VERSION = '2.0.5'
18
+
19
+ require 'pry-byebug'
18
20
 
19
21
  #-------------- User Configuration:
20
22
  #-------------- Please DO edit the following to your liking:
21
23
 
22
24
  # Configuration File: Stores tasks and their data
23
- CONFIG_DIR = ENV['HOME'] + '/.config/dayrb/'
24
- CONFIG_FILE = CONFIG_DIR + 'daytodo'
25
+ #CONFIG_DIR = ENV['HOME'] + '/.config/dayrb/'
26
+ CONFIG_DIR = '/home/cam/wip/day/'
27
+ CONFIG_FILE = CONFIG_DIR + 'config_dayrb'
25
28
 
26
29
  # Colorization:
27
30
  # Use ANSI color codes...
@@ -87,11 +90,9 @@ class String
87
90
  end
88
91
 
89
92
  #-------------- Application Logic:
93
+ FileUtils.mkdir_p(CONFIG_DIR) unless Dir.exist? CONFIG_DIR
90
94
 
91
- FileUtils.mkdir_p(CONFIG_DIR) unless Dir.exists? CONFIG_DIR
92
-
93
- db = YAML::DBM.new(CONFIG_FILE)
94
- config = Configuration.new(db)
95
+ config = Configuration.new(CONFIG_FILE)
95
96
  opts = Parser.parse_options(config)
96
97
 
97
98
  # TODO: Simplify following logic, we don't need so many variables.
@@ -109,10 +110,10 @@ end
109
110
 
110
111
  # Easier (named) access to config and opts:
111
112
  new_context = opts[:task]
112
- current_context = config.data['context']
113
+ current_context = config.context
113
114
  # If we were already tracking a task when program was called,
114
115
  # this refers to the time spent in that task:
115
- old_time = Time.now - config.data['entry_time'] if config.data['entry_time']
116
+ old_time = Time.now - config.entry_time if config.entry_time
116
117
 
117
118
  # Take action based on operation:
118
119
  case opts[:operation]
@@ -137,7 +138,7 @@ when :leave
137
138
  Presenter.announce_leave_context(current_context, old_time)
138
139
  config.clear_context
139
140
  when :delete
140
- confirmation = Presenter.confirm_deletion(new_context, config.data['tasks'][new_context]['description'])
141
+ confirmation = Presenter.confirm_deletion(new_context, config.tasks[new_context]['description'])
141
142
  if confirmation
142
143
  config.delete(new_context)
143
144
  end
@@ -145,5 +146,4 @@ else
145
146
  Presenter.print_error_unknown
146
147
  end
147
148
 
148
- config.save
149
- db.close
149
+ config.save(CONFIG_FILE)
data/changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ 2.0.5 -- 09/18/2024
2
+ -------------------
3
+ * Bug fix: Replaced deprecated File.exists? method with .exist?
4
+ * Bug fix: Replaced (seemingly) deprecated yaml/dbm library - using psych directly instead to load config yaml file.
5
+ * Bug fix: Reorganized YAML file bootstrapping code to ensure we always load config data (previously a bootstrap run would not initialize config data class variables)
6
+
1
7
  2.0.4 -- 03/20/14
2
8
  -------------------
3
9
 
@@ -22,7 +28,7 @@
22
28
 
23
29
  ### Bug Fixes:
24
30
 
25
- * Changed shebang to user /usr/bin/env ruby instead of /usr/bin/ruby.
31
+ * Changed shebang to use /usr/bin/env ruby instead of /usr/bin/ruby.
26
32
  * Fixed some spec regressions.
27
33
 
28
34
  2.0.1 -- 08/12/14
data/dayrb.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dayrb'
3
- s.version = '2.0.4'
3
+ s.version = '2.0.5'
4
4
  s.summary = "To-do & Time-Tracking CLI App"
5
5
  s.description = "Create and track time on tasks via command-line."
6
- s.authors = ["Cameron Carroll"]
6
+ s.authors = ["Cam Carroll"]
7
7
  s.email = 'ckcarroll4@gmail.com'
8
8
  s.files = `git ls-files`.split($/)
9
9
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
10
10
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
11
11
  s.homepage =
12
- 'http://github.com/sanarothe/day'
12
+ 'http://github.com/CameronCarroll/day'
13
13
  s.license = 'MIT'
14
14
  end
@@ -1,10 +1,10 @@
1
1
  # DayRB Configuration (Data-Access Layer) Module
2
2
  #
3
- # Provides convenience methods for database access and holds db data.
3
+ # Provides convenience methods for database access and holds config data.
4
4
  #
5
- # MIT License; See LICENSE file; Cameron Carroll 2014
5
+ # MIT License; See LICENSE file; Cameron Carroll 2024
6
6
 
7
- require 'yaml/dbm'
7
+ require 'psych'
8
8
 
9
9
  # Config class handles access to our config file, which mostly just provides a data-access layer.
10
10
  # Schema:
@@ -22,15 +22,26 @@ require 'yaml/dbm'
22
22
  # }
23
23
 
24
24
  class Configuration
25
- attr_reader :data, :context, :entry_time
25
+ attr_reader :tasks, :context, :entry_time
26
26
 
27
- # Load DB data and bootstrap it if empty.
27
+ # Load config data from file -- bootstrap it if empty.
28
28
  #
29
- # @param db [PSYCH::DBM] database (hash-like) initialized and closed by caller.
30
- def initialize(db)
31
- @db = db
32
- @data = @db.to_hash
33
- bootstrap_db if @data.empty?
29
+ # @param data_file Location of task data file on local drive.
30
+ def initialize(data_file)
31
+
32
+ unless File.exist? data_file
33
+ bootstrap_db(data_file)
34
+ puts "day.rb created new config file " + CONFIG_FILE
35
+ end
36
+
37
+ if File.exist? data_file
38
+ loaded_data = Psych.safe_load_file(data_file, permitted_classes: [Time, Symbol])
39
+ @context = loaded_data[:context]
40
+ @entry_time = loaded_data[:entry_time]
41
+ @tasks = loaded_data[:tasks]
42
+ else
43
+ puts "Error creating / loading config file"
44
+ end
34
45
  end
35
46
 
36
47
  # Interface to save_task which decomposes opts hash.
@@ -45,15 +56,15 @@ class Configuration
45
56
  #
46
57
  # @param next_key [String] the name of the task to switch to.
47
58
  def switch_to(next_key)
48
- cap_current_fulfillment if @data['context']
49
- @data['context'] = next_key if @data['tasks'].has_key?(next_key)
50
- @data['entry_time'] = Time.now.getutc
59
+ cap_current_fulfillment if @context
60
+ @context = next_key if @tasks.has_key?(next_key)
61
+ @entry_time = Time.now.getutc
51
62
  end
52
63
 
53
64
  # Exit context without switching to a new one.
54
65
  def clear_context()
55
66
  cap_current_fulfillment
56
- @data['context'], @data['entry_time'] = nil, nil
67
+ @context, @entry_time = nil, nil
57
68
  end
58
69
 
59
70
  # Clear fulfillment for one or all tasks.
@@ -63,7 +74,7 @@ class Configuration
63
74
  if task
64
75
  clear_fulfillment_for task
65
76
  else
66
- @data['tasks'].each do |task, task_data|
77
+ @tasks.each do |task, task_data|
67
78
  clear_fulfillment_for task
68
79
  end
69
80
  end
@@ -76,20 +87,26 @@ class Configuration
76
87
  #
77
88
  # @param task_key [String] Valid task name to delete.
78
89
  def delete(task_key)
79
- @data['tasks'].delete task_key
90
+ @tasks.delete task_key
80
91
  end
81
92
 
82
93
  # Reload class objects from config data.
83
94
  # (Used during testing.)
84
95
  def reload()
85
- @context = @data['context']
86
- @entry_time = @data['entry_time']
96
+ @context = @context
97
+ @entry_time = @entry_time
87
98
 
88
99
  end
89
100
 
90
- # To be called at the very end of the script to write data back into YAML::DBM
91
- def save()
92
- @db.replace(@data)
101
+ # To be called at the very end of the script to write data back into YAML
102
+ def save(data_file)
103
+ data = {
104
+ context: @context,
105
+ entry_time: @entry_time,
106
+ tasks: @tasks }
107
+ File.open(data_file, 'w') do |file|
108
+ file.write(Psych.dump(data))
109
+ end
93
110
  end
94
111
 
95
112
  # Used to verify that a task actually exists and to cross-reference indices to names
@@ -97,9 +114,9 @@ class Configuration
97
114
  # @param task [String] name or index reference to task
98
115
  def lookup_task(task)
99
116
  if task.number?
100
- @data['tasks'].keys[task.to_i]
117
+ @tasks.keys[task.to_i]
101
118
  else
102
- task if @data['tasks'].has_key? task
119
+ task if @tasks.has_key? task
103
120
  end
104
121
  end
105
122
 
@@ -113,28 +130,33 @@ class Configuration
113
130
  # @param estimate [String] a time estimate in integer minutes.
114
131
  def save_task(task, description, valid_days, estimate)
115
132
  if task
116
- @data['tasks'][task] = {'description' => description, 'valid_days' => valid_days,
133
+ @tasks[task] = {'description' => description, 'valid_days' => valid_days,
117
134
  'estimate' => estimate, 'fulfillment' => nil}
118
135
  end
119
136
  end
120
137
 
121
138
  # Builds initial structure for the database file.
122
- def bootstrap_db
123
- @data['context'] = nil
124
- @data['entry_time'] = nil
125
- @data['tasks'] = {}
139
+ def bootstrap_db(data_file)
140
+ data = {
141
+ context: nil,
142
+ entry_time: nil,
143
+ tasks: {} }
144
+
145
+ File.open(data_file, 'w') do |file|
146
+ file.write(Psych.dump(data))
147
+ end
126
148
  end
127
149
 
128
150
  # Add the elapsed time since entering a context. (Used when exiting that context.)
129
151
  def cap_current_fulfillment
130
- @data['tasks'][@data['context']]['fulfillment'] ||= 0
131
- @data['tasks'][@data['context']]['fulfillment'] += Time.now - @data['entry_time']
152
+ @tasks[@context]['fulfillment'] ||= 0
153
+ @tasks[@context]['fulfillment'] += Time.now - @entry_time
132
154
  end
133
155
 
134
156
  # Actually modify fulfillment data for a task.
135
157
  #
136
158
  # @param task [String] Valid task name to verify data for.
137
159
  def clear_fulfillment_for(task)
138
- @data['tasks'][task]['fulfillment'] = nil
160
+ @tasks[task]['fulfillment'] = nil
139
161
  end
140
162
  end
data/lib/day/parser.rb CHANGED
@@ -51,7 +51,7 @@ module Parser
51
51
  demand_second_argument
52
52
  when :switch
53
53
  task = lookup_task(ARGV.first)
54
- if task && @config.data['context'] == task
54
+ if task && @config.context == task
55
55
  opts[:operation] = :leave
56
56
  nil
57
57
  elsif task
data/lib/day/tasklist.rb CHANGED
@@ -14,7 +14,7 @@ class Tasklist
14
14
 
15
15
  def initialize(config)
16
16
  @config = config
17
- @all_tasks = load_tasks(config.data['tasks'])
17
+ @all_tasks = load_tasks(config.tasks)
18
18
  today = Time.new.strftime("%A").downcase.to_sym
19
19
  @valid_tasks = @all_tasks.select do |task_name, task_object|
20
20
  if task_object.valid_days
data/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  day.rb
2
2
  ======
3
- (Version 2.0.4 -- March 2015)
3
+ (Version 2.0.5 -- March 2024)
4
4
 
5
5
  A command-line to-do & time-tracking application.
6
6
 
@@ -9,7 +9,7 @@ A command-line to-do & time-tracking application.
9
9
 
10
10
  Requirements:
11
11
  -------------
12
- * Ruby (Tested with 2.1.2)
12
+ * Ruby (Tested with 3.2.5)
13
13
 
14
14
  Installation:
15
15
  -------------
@@ -66,6 +66,8 @@ Examples
66
66
  # Note 'vim' can be changed to any editor atop day.rb file.
67
67
  day.rb my_new_task vim
68
68
 
69
- Copyright 2015 - Cameron Carroll
69
+
70
+
71
+ Copyright 2024 - Cam Carroll
70
72
 
71
73
  License: MIT
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dayrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
- - Cameron Carroll
8
- autorequire:
7
+ - Cam Carroll
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-22 00:00:00.000000000 Z
11
+ date: 2024-09-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Create and track time on tasks via command-line.
14
14
  email: ckcarroll4@gmail.com
@@ -32,11 +32,11 @@ files:
32
32
  - spec/configuration_spec.rb
33
33
  - spec/parser_spec.rb
34
34
  - spec/spec_helper.rb
35
- homepage: http://github.com/sanarothe/day
35
+ homepage: http://github.com/CameronCarroll/day
36
36
  licenses:
37
37
  - MIT
38
38
  metadata: {}
39
- post_install_message:
39
+ post_install_message:
40
40
  rdoc_options: []
41
41
  require_paths:
42
42
  - lib
@@ -51,9 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubyforge_project:
55
- rubygems_version: 2.4.5
56
- signing_key:
54
+ rubygems_version: 3.5.19
55
+ signing_key:
57
56
  specification_version: 4
58
57
  summary: To-do & Time-Tracking CLI App
59
58
  test_files: