fewald-worklog 0.2.12 → 0.2.14

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: f232d29f26e76923bd942e3c88ce4abb93641ba63ee57771e68650d87ce7657e
4
- data.tar.gz: a711d57e3c7f06089163db0e75037710f98b68a974a96ebea1305d5b9f65c88c
3
+ metadata.gz: 81ae390a529cac702e93988d280c29ada0a2b899d602981663d0c6bf7386a892
4
+ data.tar.gz: 40c570f2e79185946bfa8d2aa567ceb81e487ac1babcbffffbbcb50e890c499d
5
5
  SHA512:
6
- metadata.gz: '069dd04794012e835eb6600d311547003f03a9355a78e4df834066b011588779bdbb42319d2e0f41edf7153174a92fbab8ac9215aec55ce8046c8c5a7a8ab736'
7
- data.tar.gz: de2ab21ac664879e3397740ed5d1d510e76bd0b7bc5173330006f033a48ce4b0e1b9b7f07ae507a68632d3e1762c40d0ac40b5fb46b320d335f454f9621c36a0
6
+ metadata.gz: eb070059289ac74060eae38e893e2792732a786412c93c75bdb5b284fb1663b576ebc242e51d732c0ef3dbe67b3f0ebfe1d3c5840ba5d0ae5485c0034e0a00ba
7
+ data.tar.gz: 3754d8ff695a472761253f26905a05f825c4f56a07a50ad6b398bbd2b436049fe91c7764ff0f7dcbbaa3422adc1dbeae6e30b4c667e818229d941c30546e7757
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.12
1
+ 0.2.14
data/lib/cli.rb CHANGED
@@ -30,7 +30,7 @@ class WorklogCLI < Thor
30
30
 
31
31
  # Initialize the CLI with the given arguments, options, and configuration
32
32
  def initialize(args = [], options = {}, config = {})
33
- @config = load_configuration
33
+ @config = Worklog::Configuration.load
34
34
  @storage = Storage.new(@config)
35
35
  super
36
36
  end
data/lib/configuration.rb CHANGED
@@ -3,32 +3,57 @@
3
3
  require 'worklogger'
4
4
  require 'yaml'
5
5
 
6
- # Configuration class for the application.
7
- class Configuration
8
- attr_accessor :storage_path, :log_level, :webserver_port
6
+ module Worklog
7
+ # Configuration class for the application.
8
+ # @!attribute [rw] storage_path
9
+ # @return [String] The path where the application stores its data.
10
+ # @!attribute [rw] log_level
11
+ # @return [Symbol] The logging level for the application.
12
+ # Possible values: :debug, :info, :warn, :error, :fatal
13
+ # @!attribute [rw] webserver_port
14
+ # @return [Integer] The port on which the web server runs.
15
+ # Default is 3000.
16
+ class Configuration
17
+ attr_accessor :storage_path, :log_level, :webserver_port
9
18
 
10
- def initialize(&block)
11
- block.call(self) if block_given?
19
+ def initialize(&block)
20
+ block.call(self) if block_given?
12
21
 
13
- # Set default values if not set
14
- @storage_path ||= File.join(Dir.home, '.worklog')
15
- @log_level ||= :info
16
- @webserver_port ||= 3000
17
- end
18
- end
22
+ # Set default values if not set
23
+ @storage_path ||= File.join(Dir.home, '.worklog')
24
+ @log_level = log_level || :info
25
+ @log_level = @log_level.to_sym if @log_level.is_a?(String)
26
+ @webserver_port ||= 3000
27
+ end
28
+
29
+ # Load configuration from a YAML file in the user's home directory.
30
+ # If the file does not exist, it will use default values.
31
+ # @return [Configuration] the loaded configuration
32
+ def self.load
33
+ file_path = File.join(Dir.home, '.worklog.yaml')
34
+ config = Configuration.new
35
+ if File.exist?(file_path)
36
+ file_cfg = YAML.load_file(file_path)
37
+ config.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
38
+ config.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
39
+ config.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']
40
+ else
41
+ WorkLogger.debug "Configuration file does not exist in #{file_path}, using defaults."
42
+ end
43
+
44
+ config
45
+ end
46
+
47
+ # Check if the storage path exists.
48
+ # @return [Boolean] true if the storage path exists, false otherwise
49
+ def storage_path_exist?
50
+ File.exist?(@storage_path)
51
+ end
19
52
 
20
- # Load configuration from a YAML file.
21
- # The file should be located at ~/.worklog.yaml.
22
- def load_configuration
23
- file_path = File.join(Dir.home, '.worklog.yaml')
24
- if File.exist?(file_path)
25
- file_cfg = YAML.load_file(file_path)
26
- Configuration.new do |cfg|
27
- cfg.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
28
- cfg.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
29
- cfg.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']
53
+ # Check if the storage path is the default path.
54
+ # @return [Boolean] true if the storage path is the default, false otherwise
55
+ def default_storage_path?
56
+ @storage_path == File.join(Dir.home, '.worklog')
30
57
  end
31
- else
32
- WorkLogger.debug "Configuration file does not exist in #{file_path}"
33
58
  end
34
59
  end
data/lib/editor.rb CHANGED
@@ -7,7 +7,7 @@ require 'tempfile'
7
7
  module Editor
8
8
  EDITOR_PREAMBLE = ERB.new <<~README
9
9
  # Edit the content below, then save the file and quit the editor.
10
- # The update content will be saved. The content MUST be valid YAML
10
+ # The updated content will be saved. The content MUST be valid YAML
11
11
  # in order for the application to be able to update the records.
12
12
 
13
13
  <%= content %>
data/lib/worklog.rb CHANGED
@@ -5,6 +5,7 @@ require 'optparse'
5
5
  require 'rainbow'
6
6
  require 'yaml'
7
7
 
8
+ require 'configuration'
8
9
  require 'hash'
9
10
  require 'daily_log'
10
11
  require 'date_parser'
@@ -332,6 +333,7 @@ module Worklog
332
333
  rescue Errno::ENOENT
333
334
  raise ProjectNotFoundError, 'No projects found. Please create a project first.'
334
335
  end
336
+ WorkLogger.debug "Project with key '#{project_key}' exists."
335
337
  return if projects.key?(project_key)
336
338
 
337
339
  raise ProjectNotFoundError, "Project with key '#{project_key}' does not exist."
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.12
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald