Class: Giteaucrat::Author
- Inherits:
-
Object
- Object
- Giteaucrat::Author
show all
- Includes:
- Common
- Defined in:
- lib/giteaucrat/author.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Common
#assign_attributes, #initialize
Instance Attribute Details
#ignored ⇒ Boolean
50
51
52
|
# File 'lib/giteaucrat/author.rb', line 50
def ignored
@ignored
end
|
Class Method Details
.all ⇒ Object
29
30
31
|
# File 'lib/giteaucrat/author.rb', line 29
def self.all
@all ||= Set.new
end
|
.check_multiple_emails! ⇒ Object
39
40
41
42
43
|
# File 'lib/giteaucrat/author.rb', line 39
def self.check_multiple_emails!
all.each do |_, author|
author && author.check_multiple_emails!
end
end
|
.find_by_git_person(grit_author) ⇒ Author
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/giteaucrat/author.rb', line 18
def self.find_by_git_person(grit_author)
name = grit_author.name.force_encoding('utf-8')
email = grit_author.email.force_encoding('utf-8')
author = all.find do |author|
author.has_name?(name) || author.has_email?(email)
end || new(name: name, email: email)
author.names << name
author.emails << email
author
end
|
.new(attributes = {}) ⇒ Object
33
34
35
36
37
|
# File 'lib/giteaucrat/author.rb', line 33
def self.new(attributes = {})
author = super(attributes)
all << author
author
end
|
.to_yaml ⇒ Object
45
46
47
|
# File 'lib/giteaucrat/author.rb', line 45
def self.to_yaml
all.map(&:to_hash).sort { |a, b| a[:name] <=> b[:name] }.to_yaml
end
|
Instance Method Details
#check_multiple_emails! ⇒ Object
57
58
59
60
61
|
# File 'lib/giteaucrat/author.rb', line 57
def check_multiple_emails!
if emails.count > 1 && !instance_variable_defined?(:@email)
STDERR.puts "#{name} has multiple emails:\n#{emails.map { |e| "* #{e}" }.join("\n")}\nPlease set right one in your giteaucrat.yml\n"
end
end
|
#email ⇒ String
106
107
108
|
# File 'lib/giteaucrat/author.rb', line 106
def email
@email || emails.first
end
|
#email=(email) ⇒ String
112
113
114
115
116
|
# File 'lib/giteaucrat/author.rb', line 112
def email=(email)
email = email.force_encoding('utf-8')
emails << email
@email = email
end
|
#emails ⇒ Set<String>
94
95
96
|
# File 'lib/giteaucrat/author.rb', line 94
def emails
@emails ||= Set.new
end
|
#emails=(emails) ⇒ Set<String>
100
101
102
103
|
# File 'lib/giteaucrat/author.rb', line 100
def emails=(emails)
emails.each { |email| self.emails << email.force_encoding('utf-8') }
self.emails
end
|
#has_email?(email) ⇒ Boolean
120
121
122
|
# File 'lib/giteaucrat/author.rb', line 120
def has_email?(email)
emails.include?(email.force_encoding('utf-8'))
end
|
#has_name?(name) ⇒ Boolean
89
90
91
|
# File 'lib/giteaucrat/author.rb', line 89
def has_name?(name)
names.include?(name.force_encoding('utf-8'))
end
|
#identifier ⇒ String
125
126
127
|
# File 'lib/giteaucrat/author.rb', line 125
def identifier
%(#{name} <#{email}>).force_encoding('utf-8')
end
|
#ignored? ⇒ Boolean
53
54
55
|
# File 'lib/giteaucrat/author.rb', line 53
def ignored?
!!@ignored
end
|
#name ⇒ String
76
77
78
|
# File 'lib/giteaucrat/author.rb', line 76
def name
@name || names.first
end
|
#name=(name) ⇒ Object
81
82
83
84
85
|
# File 'lib/giteaucrat/author.rb', line 81
def name=(name)
name = name.force_encoding('utf-8')
names << name
@name = name
end
|
#names ⇒ Set<String>
64
65
66
|
# File 'lib/giteaucrat/author.rb', line 64
def names
@names ||= Set.new
end
|
#names=(names) ⇒ Set<String>
70
71
72
73
|
# File 'lib/giteaucrat/author.rb', line 70
def names=(names)
names.each { |name| self.names << name.force_encoding('utf-8') }
self.names
end
|
#to_hash ⇒ Hash
130
131
132
133
134
135
136
|
# File 'lib/giteaucrat/author.rb', line 130
def to_hash
hash = { 'name' => name.to_s, 'email' => email.to_s }
hash['names'] = names.to_a - [name] if names.size > 1
hash['emails'] = emails.to_a - [email] if emails.size > 1
hash['ignored'] = true if ignored?
hash
end
|
#to_s ⇒ String
139
140
141
|
# File 'lib/giteaucrat/author.rb', line 139
def to_s
identifier
end
|