coconductor 0.5.6 → 0.6.0

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: 49f40e4ec5de8c38e94731f1c5a01c2f9419fe209eaa078a8b81a10afc4c2de2
4
- data.tar.gz: cc3c83a43583cb3b2efdf96d031c0412b150637aedf2ca475717e4e7a5dab5b8
3
+ metadata.gz: b1be21e8deb74888989e29a404c993dc58fc5c51a4bf9fbb1ae5e7e254653cbc
4
+ data.tar.gz: a7b3d870c12b0e7967ecddd7148076f4a25e795f48ed983028b40ec87aae0776
5
5
  SHA512:
6
- metadata.gz: b5ee4e36e33a52b2bdaeaeb5455fd3c90cf9ea951c8f46be51526204589615cdc39bf913faf2d0a5b6da3b6eadc5fdb4c46e6bb16ffbc134c72e6cda81a080aa
7
- data.tar.gz: 0231a718556b2e366ad06fffd06f7b31efd21c46b2b0a1a14222d1b6b7209f7dc80fcd8947ea0095cb146c05cc6c07a7714c11c81a52498235b5b3ed5865e73f
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 parts.last =~ /^[a-z-]{2,5}$/
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 citizen_code_of_conduct?
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 path
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
- unless File.exist?(path)
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(path, encoding: 'utf-8')
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Coconductor
2
- VERSION = '0.5.6'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coconductor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter