fewald-worklog 0.2.25 → 0.2.26

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/lib/person.rb +31 -0
  4. data/lib/storage.rb +7 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7412052ae6f6e4ff3fab0cc85cc061a3370aa144a5ae0d720e8b4c18771f71b5
4
- data.tar.gz: 347ca8cf68c1170c1ccbf2a0d939bc2507257a33c9ae3bdd4cdf8cd46acb1d74
3
+ metadata.gz: 36b9165b88874b753ed10bbb1a337626257db5de478fc56c15a475212836879a
4
+ data.tar.gz: fe0e5c279c1fb166876892e9642f85761bc6fdbd7d6e24c14b707bd34bd99668
5
5
  SHA512:
6
- metadata.gz: 8e31310232c8c15e9215adefefcd160cf42dac279c3a5e72cea7b7b1193abf9ed1ce15540237ba90c3f16c719b7c170dd27dd628b1082eef857354b1611e5f9a
7
- data.tar.gz: b581a94567bbc30cce66f634d9d8c6879c8f0cc82b27867972a0c9c81927516ee2065803347d9e071ddd2e112bf3a2d633c712aec2df188cbeb1c717738fbb37
6
+ metadata.gz: 5a9fafe519688f3b9258aa9b5d433dbec01ea6259fc199e3e302791acfb64a3c2159081b4d749ad86b118da0c5fbca990170c9b42dc986ef0e8bf22ec9e81ddf
7
+ data.tar.gz: a15669d9d071af3ef4124f0c60de3d41a47fb6c1684b90a523c35cfe53576ef9eca9030bed21f8c2b095279327ed84b6e1bde062beb428225bae888f65fc65f7
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.25
1
+ 0.2.26
data/lib/person.rb CHANGED
@@ -1,6 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Represents a person at work.
4
+ #
5
+ # !attribute [r] handle
6
+ # @return [String] The person's handle (username)
7
+ # !attribute [r] name
8
+ # @return [String] The person's full name
9
+ # !attribute [r] email
10
+ # @return [String, nil] The person's email address, can be nil
11
+ # !attribute [r] team
12
+ # @return [String, nil] The team the person belongs to, can be nil
13
+ # !attribute [r] notes
14
+ # @return [Array<String>] An array of notes about the person
4
15
  class Person
5
16
  attr_reader :handle, :name, :email, :team, :notes
6
17
 
@@ -12,6 +23,26 @@ class Person
12
23
  @notes = notes
13
24
  end
14
25
 
26
+ # Creates a new Person instance from a hash of attributes.
27
+ # @param hash [Hash] A hash containing person attributes
28
+ # @option hash [String] :handle The person's handle (username)
29
+ # @option hash [String] :name The person's full name
30
+ # @option hash [String, nil] :email The person's email address, can be nil
31
+ # @option hash [String, nil] :team The team the person belongs to, can be nil
32
+ # @option hash [Array<String>] :notes An array of notes about the person
33
+ # @return [Person] A new Person instance
34
+ def self.from_hash(hash)
35
+ raise ArgumentError, 'Person handle is required' unless hash[:handle] || hash['handle']
36
+ raise ArgumentError, 'Person name is required' unless hash[:name] || hash['name']
37
+
38
+ handle = hash[:handle] || hash['handle']
39
+ name = hash[:name] || hash['name']
40
+ email = hash[:email] || hash['email']
41
+ team = hash[:team] || hash['team']
42
+ notes = hash[:notes] || hash['notes'] || []
43
+ Person.new(handle, name, email, team, notes)
44
+ end
45
+
15
46
  def to_s
16
47
  return "#{name} (~#{handle})" if @email.nil?
17
48
 
data/lib/storage.rb CHANGED
@@ -157,7 +157,13 @@ module Worklog
157
157
  people_file = File.join(@config.storage_path, 'people.yaml')
158
158
  return [] unless File.exist?(people_file)
159
159
 
160
- YAML.load_file(people_file, permitted_classes: [Person])
160
+ yamltext = File.read(people_file)
161
+ if yamltext != yamltext.gsub(/^- !.*$/, '-')
162
+ WorkLogger.debug 'The people.yaml file contains deprecated syntax. Migrating now.'
163
+ yamltext.gsub!(/^- !.*$/, '-')
164
+ File.write(people_file, yamltext)
165
+ end
166
+ YAML.load(yamltext, permitted_classes: []).map { |person_hash| Person.from_hash(person_hash) }
161
167
  end
162
168
 
163
169
  # Write people to the people file
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.25
4
+ version: 0.2.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald