coconductor 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coconductor/code_of_conduct.rb +19 -9
- data/lib/coconductor/field.rb +1 -0
- data/lib/coconductor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1be21e8deb74888989e29a404c993dc58fc5c51a4bf9fbb1ae5e7e254653cbc
|
4
|
+
data.tar.gz: a7b3d870c12b0e7967ecddd7148076f4a25e795f48ed983028b40ec87aae0776
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df79aab295420223f9465e148a591e0f309b20f7dbc39b2244d19d9cee1880328c8aa21d3942c079162d5bbba8c6dd4fa8fb83e3f6eb8f529be5daf3e963de65
|
7
|
+
data.tar.gz: cf2ae15c68c899420be508a6235e237a0b2e9fab32c3fc793840bc827b981f93a25a4996bead5452e81af155f827f01db4b9fa935871dbb49b27908307a67f56
|
@@ -81,7 +81,9 @@ module Coconductor
|
|
81
81
|
def language
|
82
82
|
@language ||= begin
|
83
83
|
parts = key.split('/')
|
84
|
-
if
|
84
|
+
if other?
|
85
|
+
nil
|
86
|
+
elsif parts.last =~ /^[a-z-]{2,5}$/
|
85
87
|
parts.last
|
86
88
|
else
|
87
89
|
DEFAULT_LANGUAGE
|
@@ -105,7 +107,9 @@ module Coconductor
|
|
105
107
|
|
106
108
|
def content
|
107
109
|
# See https://github.com/stumpsyn/policies/pull/21
|
108
|
-
@content ||= if
|
110
|
+
@content ||= if parts.nil?
|
111
|
+
nil
|
112
|
+
elsif citizen_code_of_conduct?
|
109
113
|
fields = %w[COMMUNITY_NAME GOVERNING_BODY]
|
110
114
|
parts.last.gsub(/ (#{Regexp.union(fields)}) /, ' [\1] ')
|
111
115
|
else
|
@@ -134,6 +138,10 @@ module Coconductor
|
|
134
138
|
family == 'no-code-of-conduct'
|
135
139
|
end
|
136
140
|
|
141
|
+
def other?
|
142
|
+
key == 'other'
|
143
|
+
end
|
144
|
+
|
137
145
|
def fields
|
138
146
|
@fields ||= Field.from_code_of_conduct(self)
|
139
147
|
end
|
@@ -153,26 +161,28 @@ module Coconductor
|
|
153
161
|
filename << '.md'
|
154
162
|
end
|
155
163
|
|
156
|
-
def
|
164
|
+
def filepath
|
165
|
+
return @filepath if defined? @filepath
|
157
166
|
parts = key.split('/')
|
158
167
|
parts.pop unless default_language?
|
159
168
|
path = File.join(*parts[0...5], filename)
|
160
169
|
path = File.expand_path path, self.class.vendor_dir
|
161
|
-
Pathname.new(path)
|
170
|
+
@filepath = Pathname.new(path)
|
162
171
|
end
|
163
172
|
|
164
173
|
# Raw content of code of conduct file, including TOML front matter
|
165
174
|
def raw_content
|
166
|
-
|
175
|
+
return if other?
|
176
|
+
unless File.exist?(filepath)
|
167
177
|
msg = "'#{key}' is not a valid code of conduct key"
|
168
178
|
raise Coconductor::InvalidCodeOfConduct, msg
|
169
179
|
end
|
170
|
-
@raw_content ||= File.read(
|
180
|
+
@raw_content ||= File.read(filepath, encoding: 'utf-8')
|
171
181
|
end
|
172
182
|
|
173
183
|
def toml
|
174
184
|
@toml ||= begin
|
175
|
-
if parts.length == 3
|
185
|
+
if parts && parts.length == 3
|
176
186
|
TOML::Parser.new(parts[1]).parsed
|
177
187
|
else
|
178
188
|
{}
|
@@ -181,11 +191,11 @@ module Coconductor
|
|
181
191
|
end
|
182
192
|
|
183
193
|
def parts
|
184
|
-
@parts ||= raw_content.split('+++')
|
194
|
+
@parts ||= raw_content.split('+++') if raw_content
|
185
195
|
end
|
186
196
|
|
187
197
|
def default_language?
|
188
|
-
language == DEFAULT_LANGUAGE
|
198
|
+
other? || language == DEFAULT_LANGUAGE
|
189
199
|
end
|
190
200
|
end
|
191
201
|
end
|
data/lib/coconductor/field.rb
CHANGED
@@ -18,6 +18,7 @@ module Coconductor
|
|
18
18
|
# Returns an array of Fields for the given code of conduct
|
19
19
|
def from_code_of_conduct(code_of_conduct)
|
20
20
|
matches = []
|
21
|
+
return [] unless code_of_conduct && code_of_conduct.content
|
21
22
|
|
22
23
|
code_of_conduct.content.scan(REGEX) do |_m|
|
23
24
|
matches << Regexp.last_match
|
data/lib/coconductor/version.rb
CHANGED