plansheet 0.26.0 → 0.27.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: e4064aa7163d4ad0b941b17a4b3f10541fde5188d2b84e1c5b8fe43fd82eadbb
4
- data.tar.gz: a67509fae6401fd25e42ab35ef810a0bba0f82f73173ab2a5061206b2e4d9f62
3
+ metadata.gz: e590a914b9d074b7ce833d04aac6e5320684c15a398c1c88d5774ae884cad297
4
+ data.tar.gz: 7e7d5004b022e6286e0e7792b9392b95c1536c398c7915a2534ead4dbf364080
5
5
  SHA512:
6
- metadata.gz: b4d07c885342474b0205fceec3e625fc000dd92b164987eaab1603ce453d1e7473c3281a30047470d8c15f7e4dce9e587f1c19365a0d7a56a12b93478f038024
7
- data.tar.gz: 7ab35b12fcdc63e00d0dd6e2b2b54e4d27634d1b950c2298c55886b3f8c461cc272bbb507404edfad156ff646148802f099d3c1a054bd000284622f1f1e9ce72
6
+ metadata.gz: 4f03c2eaa802dd20a82180ab4a3ad2b23b2a3b69d6e7536f81a42305a3aab486175e18c767a9cb5b919a7c8d5d7e5a22032253e19b95d47d19c64a4583fd150f
7
+ data.tar.gz: 6a1923c54d08ba01d33dbfb8d0c76b813fb57b65edba8d79fd002db43b9c63299a301c763acb5084ab5d1e9a773af24be12b15d5f5c2d4fad3b009f820939cfa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plansheet (0.26.0)
4
+ plansheet (0.27.0)
5
5
  dc-kwalify (~> 1.0)
6
6
  diffy (= 3.4.2)
7
7
  rgl (= 0.5.8)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
3
4
  require "rgl/adjacency"
4
5
  require "rgl/topsort"
5
6
 
@@ -23,7 +24,6 @@ module Plansheet
23
24
  def initialize(config, debug: false)
24
25
  @projects_dir = config[:projects_dir]
25
26
  @sort_order = config[:sort_order]
26
- # @completed_projects_dir = config(:completed_projects_dir)
27
27
 
28
28
  # This bit of trickiness is because we don't know what the sort order is
29
29
  # until runtime. I'm sure this design decision definitely won't bite me
@@ -77,6 +77,25 @@ module Plansheet
77
77
  @projects.sort!
78
78
  end
79
79
 
80
+ def archive_projects
81
+ archive_dir = "#{@projects_dir}/archive/"
82
+ Dir.mkdir archive_dir unless Dir.exist? archive_dir
83
+
84
+ # NOTE: It would save writes if we sorted and did all month/namespaces
85
+ # writes only once, but as the normal case only sees a few projects
86
+ # archived at a time, I'll leave that for someone else to implement ;-)
87
+ projects_to_archive = @projects.select(&:archivable?)
88
+ projects_to_archive.each do |project|
89
+ path = Pathname.new "#{archive_dir}/#{project.completed_on_month}/#{project.namespace}.yml"
90
+ Dir.mkdir path.dirname unless path.dirname.exist?
91
+ pyf = ProjectYAMLFile.new path
92
+ pyf.append_project project
93
+ end
94
+
95
+ # Now that the projects have been archived, remove them from the pool
96
+ @projects.reject!(&:archivable?)
97
+ end
98
+
80
99
  def project_namespaces
81
100
  @projects.collect(&:namespace).uniq.sort
82
101
  end
@@ -86,12 +105,16 @@ module Plansheet
86
105
  end
87
106
 
88
107
  def write_projects
89
- # TODO: This leaves potential for duplicate projects where empty files
90
- # are involved once completed project directories are a thing - will need
91
- # to keep a list of project files to delete
92
- project_namespaces.each do |ns|
108
+ # Collect the namespaces *before* archiving is done, for the case where
109
+ # all active projects in a namespace have been completed and archived
110
+ namespaces_before_archiving = project_namespaces
111
+
112
+ archive_projects
113
+
114
+ namespaces_before_archiving.each do |ns|
115
+ projects = projects_in_namespace(ns)
93
116
  pyf = ProjectYAMLFile.new "#{@projects_dir}/#{ns}.yml"
94
- pyf.compare_and_write projects_in_namespace(ns)
117
+ pyf.compare_and_write projects
95
118
  end
96
119
  end
97
120
 
@@ -4,6 +4,7 @@ require "yaml"
4
4
  require "date"
5
5
  require "pathname"
6
6
 
7
+ require "diffy"
7
8
  require "kwalify"
8
9
 
9
10
  module Plansheet
@@ -152,7 +153,13 @@ module Plansheet
152
153
  # TODO: this won't GC, inline validation instead?
153
154
  end
154
155
 
156
+ def stub_file
157
+ File.write @path, YAML.dump([])
158
+ end
159
+
155
160
  def load_file
161
+ stub_file unless File.exist? @path
162
+
156
163
  # Handle pre-Ruby 3.1 psych versions (this is brittle)
157
164
  @raw = if Psych::VERSION.split(".")[0].to_i >= 4
158
165
  YAML.load_file(@path, permitted_classes: [Date])
@@ -189,16 +196,22 @@ module Plansheet
189
196
  @projects.sort!
190
197
  end
191
198
 
199
+ def append_project(project)
200
+ load_file
201
+ compare_and_write(@projects.append(project))
202
+ end
203
+
192
204
  def compare_and_write(projects)
205
+ load_file
206
+ orig_string = yaml_dump(@projects)
193
207
  updated_projects_string = yaml_dump(projects)
194
208
 
195
209
  # Compare the existing file to the newly generated one - we only want a
196
210
  # write if something has changed
197
- return if updated_projects_string == yaml_dump(load_file)
211
+ return if updated_projects_string == orig_string
198
212
 
199
213
  puts "#{@path} has changed, writing"
200
- require "diffy"
201
- puts Diffy::Diff.new(yaml_dump(load_file), updated_projects_string).to_s(:color)
214
+ puts Diffy::Diff.new(orig_string, updated_projects_string).to_s(:color)
202
215
  File.write @path, updated_projects_string
203
216
  end
204
217
 
@@ -155,6 +155,10 @@ module Plansheet
155
155
  end
156
156
  end
157
157
 
158
+ def completed_on_month
159
+ @completed_on&.strftime("%Y-%m")
160
+ end
161
+
158
162
  def yearly_minutes_saved
159
163
  if @daily_time_roi
160
164
  Plansheet.parse_time_duration(@daily_time_roi) * 365
@@ -354,6 +358,10 @@ module Plansheet
354
358
  status == "done"
355
359
  end
356
360
 
361
+ def archivable?
362
+ !recurring? && @completed_on
363
+ end
364
+
357
365
  def self.task_time_estimate(str)
358
366
  Plansheet.parse_time_duration(Regexp.last_match(1)) if str.match(TIME_EST_REGEX)
359
367
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plansheet
4
- VERSION = "0.26.0"
4
+ VERSION = "0.27.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plansheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 0.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Crosby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-13 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dc-kwalify