fewald-worklog 0.2.32 → 0.2.34

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: 14033d83050a174467b6159bc1fdbfb7fd3bc7ffc8883f3b04bc241dec77184b
4
- data.tar.gz: 7499e124a43649989ffb3010fcb4965f4110ea7efe7d41a8e49515a0d165e022
3
+ metadata.gz: 6325a91f9d1eb681031b23a92d66a80cc6eabe7e789305ac42a6b9264efc4ac8
4
+ data.tar.gz: d86f5ad7e2a5122a394801b3b4291dc47b3a5657469321cb231c0d60ed297e71
5
5
  SHA512:
6
- metadata.gz: 54887531704ca1ef6cc7ef0303d899b991036add0f914f81d55189a67a5b7d2254fc89dff9114cbb7237a394d69fe020dc0175cd0978a56766def700f8bb226d
7
- data.tar.gz: 1a1207af445e9074d0d66b2802943e71a1a63f7aaaa7ec06f95c10805b3529207acc06ade759a0275bdc675da26ccce6ecdf1200c292bf0817a2a98e6e278975
6
+ metadata.gz: 71e6ed726460339b93a19dfad1ce7445490c813f0c5e4e6f5db37505168daa1ba04d9fa5094393a38f91fc7270ade0b88879887c6a179dac0a822ffb87c96720
7
+ data.tar.gz: a140db08e98ffb970eb98dd3d1c28e3e3dec1d284ea1ef005e68c6c1e071195abb39a37afb5c49bdd5f02fd3e24e6d9288352aa242525231397345684cefe65d
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.32
1
+ 0.2.34
data/lib/daily_log.rb CHANGED
@@ -13,7 +13,7 @@ module Worklog
13
13
 
14
14
  def initialize(params = {})
15
15
  @date = params[:date]
16
- @entries = params[:entries]
16
+ @entries = params[:entries] || []
17
17
  end
18
18
 
19
19
  # Returns true if there are people mentioned in any entry of the current day.
@@ -62,5 +62,16 @@ module Worklog
62
62
  def ==(other)
63
63
  date == other.date && entries == other.entries
64
64
  end
65
+
66
+ # Access a log entry by its unique key.
67
+ # To safeguard against multiple entries with the same key, and future-proofing,
68
+ # an empty string will return nil.
69
+ # @param key [String] the unique key of the log entry
70
+ # @return [LogEntry, nil] the log entry with the specified key, or nil if not found
71
+ def [](key)
72
+ return nil if key.nil? || key.empty?
73
+
74
+ @entries.find { |entry| entry.key == key }
75
+ end
65
76
  end
66
77
  end
data/lib/log_entry.rb CHANGED
@@ -8,6 +8,8 @@ require 'hash'
8
8
  module Worklog
9
9
  # A single log entry in a DailyLog.
10
10
  # @see DailyLog
11
+ # @!attribute [rw] key
12
+ # @return [String] the unique key of the log entry. The key is generated based on the time and message.
11
13
  # @!attribute [rw] time
12
14
  # @return [DateTime] the date and time of the log entry.
13
15
  # @!attribute [rw] tags
@@ -27,11 +29,13 @@ module Worklog
27
29
 
28
30
  include Hashify
29
31
 
30
- attr_accessor :time, :tags, :ticket, :url, :epic, :message, :project
32
+ attr_accessor :key, :time, :tags, :ticket, :url, :epic, :message, :project
31
33
 
32
34
  attr_reader :day
33
35
 
34
36
  def initialize(params = {})
37
+ # key can be nil. This is needed for backwards compatibility with older log entries.
38
+ @key = params[:key]
35
39
  @time = params[:time]
36
40
  # If tags are nil, set to empty array.
37
41
  # This is similar to the CLI default value.
@@ -105,19 +109,12 @@ module Worklog
105
109
  end
106
110
 
107
111
  # Create a LogEntry from a hash with symbolized keys
112
+ # This is an alias for the constructor and here for consistency with other classes.
108
113
  #
109
114
  # @param hash [Hash] the hash to convert
110
115
  # @return [LogEntry] the created LogEntry object
111
116
  def self.from_hash(hash)
112
- new(
113
- time: hash[:time],
114
- tags: hash[:tags],
115
- ticket: hash[:ticket],
116
- url: hash[:url],
117
- epic: hash[:epic],
118
- message: hash[:message],
119
- project: hash[:project]
120
- )
117
+ new(**hash)
121
118
  end
122
119
 
123
120
  # Convert the log entry to YAML format.
data/lib/worklog.rb CHANGED
@@ -6,6 +6,7 @@ require 'rainbow'
6
6
  require 'yaml'
7
7
 
8
8
  require 'configuration'
9
+ require 'digest'
9
10
  require 'hash'
10
11
  require 'daily_log'
11
12
  require 'date_parser'
@@ -86,8 +87,11 @@ module Worklog
86
87
  # Validate that the project exists if provided
87
88
  validate_projects!(options[:project]) if options[:project] && !options[:project].empty?
88
89
 
90
+ # Use the first 7 characters of the SHA256 hash of message as the key
91
+ key = Digest::SHA256.hexdigest(message)[..6]
92
+
89
93
  daily_log = @storage.load_log!(@storage.filepath(date))
90
- new_entry = LogEntry.new(time:, tags: options[:tags], ticket: options[:ticket], url: options[:url],
94
+ new_entry = LogEntry.new(key:, time:, tags: options[:tags], ticket: options[:ticket], url: options[:url],
91
95
  epic: options[:epic], message:, project: options[:project])
92
96
  daily_log.entries << new_entry
93
97
 
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.32
4
+ version: 0.2.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald