fewald-worklog 0.2.14 → 0.2.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: 81ae390a529cac702e93988d280c29ada0a2b899d602981663d0c6bf7386a892
4
- data.tar.gz: 40c570f2e79185946bfa8d2aa567ceb81e487ac1babcbffffbbcb50e890c499d
3
+ metadata.gz: d406551a4b3ab8ab4845636c440e4d1cc82e5ac6fc0c188328ed8a5b8608c893
4
+ data.tar.gz: 0170211e2a62fecfd26b58d8d6d8eeff9e0b55412ac9715a79fe67066887430f
5
5
  SHA512:
6
- metadata.gz: eb070059289ac74060eae38e893e2792732a786412c93c75bdb5b284fb1663b576ebc242e51d732c0ef3dbe67b3f0ebfe1d3c5840ba5d0ae5485c0034e0a00ba
7
- data.tar.gz: 3754d8ff695a472761253f26905a05f825c4f56a07a50ad6b398bbd2b436049fe91c7764ff0f7dcbbaa3422adc1dbeae6e30b4c667e818229d941c30546e7757
6
+ metadata.gz: 222b26f794ceae4b3dfd33be51cd300b07fa0dc594811f30aa6bb66b4d71f79cf985e62663f33fb6305fd0a88d098c9dd91f62e250ef2cbdc416e9673673dc6d
7
+ data.tar.gz: ec0c33c3041dfe1e3f1d73f2b2b3a3175c7a414beda395f6590af8350a66cdd3d79aaf03143daea1684b0571fff0787bcd5ebd32c7a543f34aadeb78b29ecd75
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.14
1
+ 0.2.16
data/lib/project.rb CHANGED
@@ -3,8 +3,24 @@
3
3
  module Worklog
4
4
  # Represents a project. A project is a longer running task or initiative.
5
5
  # Single log entries can be associated with a project.
6
+ # @!attribute [rw] key
7
+ # @return [String] Unique identifier for the project, used in log entries.
8
+ # @!attribute [rw] name
9
+ # @return [String] The human-readable name of the project.
10
+ # @!attribute [rw] description
11
+ # @return [String, nil] A description of the project, can be nil
12
+ # @!attribute [rw] start_date
13
+ # @return [Date, nil] The start date of the project, can be nil
14
+ # @!attribute [rw] end_date
15
+ # @return [Date, nil] The end date of the project, can be nil
16
+ # @!attribute [rw] status
17
+ # @return [String, nil] The status of the project, can be nil
18
+ # Possible values: 'active', 'completed', 'archived', etc.
19
+ # Indicates the current state of the project.
20
+ # @!attribute [rw] last_activity
21
+ # @return [Date, nil] The last activity date or nil if not set.
6
22
  class Project
7
- attr_accessor :key, :name, :description, :start_date, :end_date, :status
23
+ attr_accessor :key, :name, :description, :start_date, :end_date, :status, :last_activity
8
24
 
9
25
  # Creates a new Project instance from a hash of attributes.
10
26
  # @param hash [Hash] A hash containing project attributes
@@ -10,6 +10,8 @@ module Worklog
10
10
 
11
11
  # ProjectStorage is responsible for loading and managing project data.
12
12
  # It provides methods to load projects from a YAML file and check if a project exists.
13
+ # @!attribute [w] projects
14
+ # @return [Hash<String, Project>] A hash of projects keyed by their project keys.
13
15
  #
14
16
  # @see Project
15
17
  # @see Configuration
@@ -17,6 +19,11 @@ module Worklog
17
19
  class ProjectStorage
18
20
  attr_writer :projects
19
21
 
22
+ # The name of the YAML file where projects are stored.
23
+ FILE_NAME = 'projects.yaml'
24
+
25
+ # The template for the projects YAML file.
26
+ # This template is used to create a new projects file if it does not exist.
20
27
  PROJECT_TEMPLATE = <<~YAML
21
28
  # Each project is defined by the following attributes:
22
29
  # - key: <project_key>
@@ -44,7 +51,7 @@ module Worklog
44
51
  def load_projects
45
52
  create_template unless file_exist?
46
53
 
47
- file_path = File.join(@configuration.storage_path, 'projects.yml')
54
+ file_path = File.join(@configuration.storage_path, FILE_NAME)
48
55
  projects = {}
49
56
  YAML.load_file(file_path, permitted_classes: [Date])&.each do |project_hash|
50
57
  project = Project.from_hash(project_hash)
@@ -54,12 +61,14 @@ module Worklog
54
61
  projects
55
62
  end
56
63
 
57
- # Check if a project with a given handle exists.
58
- # @param handle [String] The handle of the project to check.
64
+ # Check if a project with a given key exists.
65
+ # @param key [String] The key of the project to check.
59
66
  # @return [Boolean] Returns true if the project exists, false otherwise.
60
- def exist?(handle)
67
+ # @note This method loads the projects from disk if they are not already loaded.
68
+ # @see load_projects
69
+ def exist?(key)
61
70
  projects = load_projects
62
- projects.key?(handle)
71
+ projects.key?(key)
63
72
  end
64
73
 
65
74
  private
@@ -67,12 +76,20 @@ module Worklog
67
76
  # Check whether projects.yaml exists in the project_dir
68
77
  # @return [Boolean] Returns true if the project YAML file exists, false otherwise
69
78
  def file_exist?
70
- file_path = File.join(@configuration.storage_path, 'projects.yml')
79
+ file_path = File.join(@configuration.storage_path, FILE_NAME)
71
80
  File.exist?(file_path)
72
81
  end
73
82
 
83
+ # Creates a template for the projects YAML file if it does not exist.
84
+ # This method writes a predefined template to the projects.yml file.
85
+ # @return [void]
86
+ # @note This method will overwrite any existing projects.yml file.
87
+ # @see PROJECT_TEMPLATE for the structure of the template.
74
88
  def create_template
75
- File.write(File.join(@configuration.storage_path, 'projects.yml'), PROJECT_TEMPLATE)
89
+ return unless @configuration.storage_path_exist?
90
+
91
+ File.write(File.join(@configuration.storage_path, FILE_NAME), PROJECT_TEMPLATE)
92
+ nil
76
93
  end
77
94
  end
78
95
  end
data/lib/storage.rb CHANGED
@@ -13,6 +13,9 @@ class Storage
13
13
 
14
14
  FILE_SUFFIX = '.yaml'
15
15
 
16
+ # Regular expression to match daily log file names
17
+ LOG_PATTERN = /\d{4}-\d{2}-\d{2}#{FILE_SUFFIX}\z/
18
+
16
19
  def initialize(config)
17
20
  @config = config
18
21
  end
@@ -28,7 +31,7 @@ class Storage
28
31
 
29
32
  logs = []
30
33
  Dir.glob(File.join(@config.storage_path, "*#{FILE_SUFFIX}")).map do |file|
31
- next if file.end_with?('people.yaml')
34
+ next unless file.match?(LOG_PATTERN)
32
35
 
33
36
  logs << load_log(file)
34
37
  end
@@ -90,8 +93,6 @@ class Storage
90
93
  # Create file for a new day if it does not exist
91
94
  # @param [Date] date The date, used as the file name.
92
95
  def create_file_skeleton(date)
93
- create_folder
94
-
95
96
  File.write(filepath(date), YAML.dump(DailyLog.new(date:, entries: []))) unless File.exist?(filepath(date))
96
97
  end
97
98
 
@@ -116,8 +117,6 @@ class Storage
116
117
  end
117
118
 
118
119
  def write_log(file, daily_log)
119
- create_folder
120
-
121
120
  WorkLogger.debug "Writing to file #{file}"
122
121
 
123
122
  File.open(file, 'w') do |f|
@@ -159,8 +158,6 @@ class Storage
159
158
  # Write people to the people file
160
159
  # @param [Array<Person>] people List of people
161
160
  def write_people!(people)
162
- create_folder
163
-
164
161
  people_file = File.join(@config.storage_path, 'people.yaml')
165
162
  File.open(people_file, 'w') do |f|
166
163
  f.puts people.to_yaml
@@ -168,7 +165,10 @@ class Storage
168
165
  end
169
166
 
170
167
  # Create folder if not exists already.
171
- def create_folder
168
+ def create_default_folder
169
+ # Do nothing if the storage path is not the default path
170
+ return unless @config.default_storage_path?
171
+
172
172
  Dir.mkdir(@config.storage_path) unless Dir.exist?(@config.storage_path)
173
173
  end
174
174
 
data/lib/worklog.rb CHANGED
@@ -22,6 +22,22 @@ module Worklog
22
22
  # Main class providing all worklog functionality.
23
23
  # This class is the main entry point for the application.
24
24
  # It handles command line arguments, configuration, and logging.
25
+ # @!attribute [r] config
26
+ # @return [Configuration] The configuration object containing settings for the application.
27
+ # @!attribute [r] storage
28
+ # @return [Storage] The storage object for managing file operations.
29
+ #
30
+ # @see Configuration
31
+ # @see Storage
32
+ # @see ProjectStorage
33
+ #
34
+ # @example
35
+ # worklog = Worklog.new
36
+ # worklog.add('Worked on feature X',
37
+ # date: '2023-10-01',
38
+ # time: '10:00:00',
39
+ # tags: ['feature', 'x'],
40
+ # ticket: 'TICKET-123')
25
41
  class Worklog
26
42
  include StringHelper
27
43
  attr_reader :config, :storage
@@ -31,6 +47,13 @@ module Worklog
31
47
  @storage = Storage.new(@config)
32
48
 
33
49
  WorkLogger.level = @config.log_level == :debug ? Logger::Severity::DEBUG : Logger::Severity::INFO
50
+
51
+ bootstrap
52
+ end
53
+
54
+ # Bootstrap the worklog application.
55
+ def bootstrap
56
+ @storage.create_default_folder
34
57
  end
35
58
 
36
59
  # Add new entry to the work log.
@@ -326,6 +349,15 @@ module Worklog
326
349
  [start_date, end_date]
327
350
  end
328
351
 
352
+ # Validate that the project exists in the project storage if a project key is provided.
353
+ #
354
+ # @param project_key [String] the project key to validate
355
+ # @raise [ProjectNotFoundError] if the project does not exist
356
+ #
357
+ # @return [void]
358
+ #
359
+ # @example
360
+ # validate_projects!('P001')
329
361
  def validate_projects!(project_key)
330
362
  project_storage = ProjectStorage.new(@config)
331
363
  begin
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fewald-worklog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald