plansheet 0.13.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76e5120430c540166b342a58cf0a0c07dfaf773d0a46b1dcd05614be677fe1a6
4
- data.tar.gz: 83eb24c7811f8e1e49d8f7f79a059c1451673907460203d95a5c28e98fbc74c2
3
+ metadata.gz: f121593269dc11059fe547d8b72d58c2ad1a6685ae4826ac39daaff8b33f7c9a
4
+ data.tar.gz: 4020dab046e837f02b64cfc975408240d472b04a26bc6f40e7e552d915d77336
5
5
  SHA512:
6
- metadata.gz: 71d3b9dad2c16601ef4472805c282cbfced288e0fc1cee42b0b2e6cb508c5aa255a688c3301fbdee38ae5188f36a2d65cbee2ebc9aa3290771a8f2a2f84854ac
7
- data.tar.gz: bc7d994b5d320c0c9f7ed53ca625afb6f586f228a48f16e2e9f1b2f392cae4cb1e1cef45ddc305069fb06a59a8e1fa9cf2324c1dc4a322e411f801d5802c41fe
6
+ metadata.gz: ae82c5c2df93d55e520262754cc1c6e8b1b80a9a2fe230c09d00bd7ed4a38790c71b0dfcde5ac178e38112a26284219f21a8d99e48212601bbbcfae98607c0d1
7
+ data.tar.gz: 6ca757244abd515dcd86bbedb5a31590a53fbc8720e35167549bfe326c1f96673acef49b0dd1044a0e92f43253ef1442d126872859cebfa0f1185bb06612da59
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plansheet (0.13.2)
4
+ plansheet (0.15.0)
5
5
  dc-kwalify (~> 1.0)
6
6
 
7
7
  GEM
data/exe/plansheet CHANGED
@@ -25,18 +25,17 @@ options = {}
25
25
  parser.parse!(into: options)
26
26
 
27
27
  config = Plansheet.load_config
28
+ pool = Plansheet::Pool.new({ projects_dir: config["projects_dir"] })
28
29
 
29
30
  if options[:sheet] || options.empty?
30
- project_arr = Plansheet.load_projects_dir config["projects_dir"]
31
-
32
31
  Dir.mkdir config["output_dir"] unless Dir.exist? config["output_dir"]
33
-
34
- Plansheet::Sheet.new("#{config["output_dir"]}/projects.md", project_arr)
32
+ Plansheet::Sheet.new("#{config["output_dir"]}/projects.md", pool.projects)
35
33
  elsif options[:sort]
36
- Plansheet.resort_projects_in_dir config["projects_dir"]
34
+ # Pool sorts projects, this now just matches old behaviour
35
+ pool.write_projects
37
36
  elsif options[:cli]
38
- project_arr = Plansheet.load_projects_dir config["projects_dir"]
39
- project_arr.sort!
37
+ # TODO: add a project filter method
38
+ project_arr = pool.projects
40
39
  project_arr.delete_if { |x| x.status == "dropped" || x.status == "done" }
41
40
  project_arr.select! { |x| x.location == options[:location_filter] } if options[:location_filter]
42
41
  project_arr.each do |proj|
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plansheet
4
+ # The "pool" is the aggregated collection of projects, calendar events, etc.
5
+ class Pool
6
+ attr_accessor :projects
7
+
8
+ def initialize(config)
9
+ @projects_dir = config[:projects_dir]
10
+ # @completed_projects_dir = config(:completed_projects_dir)
11
+
12
+ load_projects_dir(@projects_dir)
13
+ # TODO: Slurp all files
14
+ sort_projects
15
+ end
16
+
17
+ def sort_projects
18
+ @projects.sort!
19
+ end
20
+
21
+ def project_namespaces
22
+ @projects.collect(&:namespace).uniq.sort
23
+ end
24
+
25
+ def projects_in_namespace(namespace)
26
+ @projects.select { |x| x.namespace == namespace }
27
+ end
28
+
29
+ def write_projects
30
+ # TODO: This leaves potential for duplicate projects where empty files
31
+ # are involved once completed project directories are a thing - will need
32
+ # to keep a list of project files to delete
33
+ project_namespaces.each do |ns|
34
+ # TODO: move this to ProjectYAMLFile
35
+ #
36
+ f = "#{@projects_dir}/#{ns}.yml"
37
+ pyf = ProjectYAMLFile.new f
38
+ pyf.projects = projects_in_namespace(ns)
39
+ pyf.write
40
+ end
41
+ end
42
+
43
+ def load_projects_dir(dir)
44
+ project_arr = []
45
+ projects = Dir.glob("*yml", base: dir)
46
+ projects.each do |l|
47
+ project_arr << ProjectYAMLFile.new(File.join(dir, l)).load_file
48
+ end
49
+
50
+ @projects = project_arr.flatten!
51
+ end
52
+ end
53
+ end
@@ -4,7 +4,9 @@ module Plansheet
4
4
  class Project
5
5
  def to_s
6
6
  str = String.new
7
- str << "# #{@name}\n"
7
+ str << "# "
8
+ str << "#{@namespace} - " if @namespace
9
+ str << "#{@name}\n"
8
10
  STRING_PROPERTIES.each do |o|
9
11
  str << stringify_string_property(o)
10
12
  end
@@ -16,11 +16,9 @@ module Plansheet
16
16
  "project":
17
17
  desc: Project name
18
18
  type: str
19
- required: yes
20
19
  "namespace":
21
- desc: Namespace of a group of projects (for organizing)
20
+ desc: Project name
22
21
  type: str
23
- required: yes
24
22
  "priority":
25
23
  desc: Project priority
26
24
  type: str
@@ -114,17 +112,19 @@ module Plansheet
114
112
  PROJECT_SCHEMA = YAML.safe_load(PROJECT_YAML_SCHEMA)
115
113
 
116
114
  class ProjectYAMLFile
117
- attr_reader :projects
115
+ attr_accessor :projects
118
116
 
119
117
  def initialize(path)
120
118
  @path = path
121
119
  # TODO: this won't GC, inline validation instead?
120
+ end
122
121
 
122
+ def load_file
123
123
  # Handle pre-Ruby 3.1 psych versions (this is brittle)
124
124
  @raw = if Psych::VERSION.split(".")[0].to_i >= 4
125
- YAML.load_file(path, permitted_classes: [Date])
125
+ YAML.load_file(@path, permitted_classes: [Date])
126
126
  else
127
- YAML.load_file(path)
127
+ YAML.load_file(@path)
128
128
  end
129
129
 
130
130
  validate_schema
@@ -133,6 +133,7 @@ module Plansheet
133
133
  proj["namespace"] = namespace
134
134
  Project.new proj
135
135
  end
136
+ @projects
136
137
  end
137
138
 
138
139
  def namespace
@@ -155,8 +156,12 @@ module Plansheet
155
156
  @projects.sort!
156
157
  end
157
158
 
159
+ def write
160
+ File.write @path, yaml_dump
161
+ end
162
+
158
163
  def yaml_dump
159
- YAML.dump(@projects.map(&:to_h))
164
+ YAML.dump(@projects.map { |x| x.to_h.except("namespace") })
160
165
  end
161
166
  end
162
167
  end
@@ -49,16 +49,18 @@ module Plansheet
49
49
  ].map { |x| "compare_#{x}".to_sym }.freeze
50
50
  # NOTE: The order of these affects presentation!
51
51
  # namespace is derived from file name
52
- STRING_PROPERTIES = %w[namespace priority status location notes time_estimate frequency lead_time].freeze
52
+ STRING_PROPERTIES = %w[priority status location notes time_estimate frequency lead_time].freeze
53
53
  DATE_PROPERTIES = %w[due defer completed_on created_on starts_on last_done last_reviewed].freeze
54
54
  ARRAY_PROPERTIES = %w[dependencies externals urls tasks done tags].freeze
55
55
 
56
56
  ALL_PROPERTIES = STRING_PROPERTIES + DATE_PROPERTIES + ARRAY_PROPERTIES
57
57
 
58
58
  attr_reader :name, *ALL_PROPERTIES
59
+ attr_accessor :namespace
59
60
 
60
61
  def initialize(options)
61
62
  @name = options["project"]
63
+ @namespace = options["namespace"]
62
64
 
63
65
  ALL_PROPERTIES.each do |o|
64
66
  instance_variable_set("@#{o}", options[o]) if options[o]
@@ -220,7 +222,7 @@ module Plansheet
220
222
  end
221
223
 
222
224
  def to_h
223
- h = { "project" => @name }
225
+ h = { "project" => @name, "namespace" => @namespace }
224
226
  ALL_PROPERTIES.each do |prop|
225
227
  h[prop] = instance_variable_get("@#{prop}") if instance_variable_defined?("@#{prop}")
226
228
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plansheet
4
- VERSION = "0.13.2"
4
+ VERSION = "0.15.0"
5
5
  end
data/lib/plansheet.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "plansheet/version"
4
4
  require_relative "plansheet/project"
5
+ require_relative "plansheet/pool"
5
6
  require_relative "plansheet/sheet"
6
7
  require "yaml"
7
8
  require "kwalify"
@@ -9,28 +10,10 @@ require "kwalify"
9
10
  module Plansheet
10
11
  class Error < StandardError; end
11
12
 
13
+ # TODO: config schema validation
12
14
  def self.load_config
13
15
  YAML.load_file "#{Dir.home}/.plansheet.yml"
14
16
  rescue StandardError
15
17
  abort "unable to load plansheet config file"
16
18
  end
17
-
18
- def self.resort_projects_in_dir(dir)
19
- project_files = Dir.glob("#{dir}/*yml")
20
- project_files.each do |f|
21
- pyf = ProjectYAMLFile.new(f)
22
- pyf.sort!
23
- File.write(f, pyf.yaml_dump)
24
- end
25
- end
26
-
27
- def self.load_projects_dir(dir)
28
- project_arr = []
29
- projects = Dir.glob("*yml", base: dir)
30
- projects.each do |l|
31
- project_arr << ProjectYAMLFile.new(File.join(dir, l)).projects
32
- end
33
-
34
- project_arr.flatten!
35
- end
36
19
  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.13.2
4
+ version: 0.15.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-06-08 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dc-kwalify
@@ -43,6 +43,7 @@ files:
43
43
  - examples/backpack.yml
44
44
  - exe/plansheet
45
45
  - lib/plansheet.rb
46
+ - lib/plansheet/pool.rb
46
47
  - lib/plansheet/project.rb
47
48
  - lib/plansheet/project/stringify.rb
48
49
  - lib/plansheet/project/yaml.rb