deriving_license 0.2.6 → 0.2.7

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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'deriving_license'
3
- s.version = '0.2.6'
3
+ s.version = '0.2.7'
4
4
  s.summary = "Deriving Licence finds the license agreements for all gems in your Gemfile"
5
5
  s.description = "Deriving Licence finds the license agreements for all gems in your Gemfile if included in your project, or in a Gemfile passed to the included binary"
6
6
  s.authors = ["Tom Allen"]
@@ -90,6 +90,9 @@ class DerivingLicense
90
90
  end
91
91
  end
92
92
  end
93
+ if detected_licenses["custom"].empty?
94
+ detected_licenses.delete("custom")
95
+ end
93
96
  detected_licenses
94
97
  end
95
98
 
@@ -118,7 +121,7 @@ class DerivingLicense
118
121
  unless unrecognized.empty?
119
122
  puts "There #{unrecognized.count==1 ? "is" : "are"} also #{unrecognized.count} unrecognized license#{unrecognized.count==1 ? "" : "s"}: #{unrecognized.join(', ')}"
120
123
  end
121
- unless licenses["custom"].empty?
124
+ if licenses["custom"] and !licenses["custom"].empty?
122
125
  puts "The following dependencies have custom licenses: #{licenses["custom"].join(', ')}"
123
126
  end
124
127
  end
@@ -155,6 +158,37 @@ class DerivingLicense
155
158
  `rm #{gem_filename}` # Remove fetched gem.
156
159
  end
157
160
 
161
+ def self.search_in_paths(paths)
162
+ licenses = []
163
+ paths.each do |p|
164
+ if File.exist?(p)
165
+ File.open(p).each_line do |l|
166
+ if /license/.match(l)
167
+ # Found the word "license", so now look for known license names.
168
+ (@@license_details.keys + @@license_aliases.keys).each do |n|
169
+ if /#{n}/.match(l)
170
+ licenses << n
171
+ break
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
178
+ licenses
179
+ end
180
+
181
+ def self.search_in_content(content)
182
+ licenses = []
183
+ (@@license_details.keys + @@license_aliases.keys).each do |n|
184
+ if /#{n}/.match(content)
185
+ licenses << n
186
+ return licenses
187
+ end
188
+ end
189
+ licenses
190
+ end
191
+
158
192
  ##############
159
193
  # STRATEGIES #
160
194
  ##############
@@ -177,31 +211,13 @@ class DerivingLicense
177
211
  # Found filename with the word "license", so now look for known license
178
212
  # names in the rest of this filename.
179
213
  license_file_paths.each do |p|
180
- (@@license_details.keys + @@license_aliases.keys).each do |n|
181
- if /#{n}/.match(p)
182
- licenses << n
183
- break
184
- end
185
- end
214
+ licenses = search_in_content(p)
215
+ break unless licenses.empty?
186
216
  end
187
217
 
188
218
  if licenses.empty?
189
219
  # Failing that, open each file and check the content in a similar manner.
190
- license_file_paths.each do |p|
191
- if File.exist?(p)
192
- File.open(p).each_line do |l|
193
- if /license/.match(l)
194
- # Found the word "license", so now look for known license names.
195
- (@@license_details.keys + @@license_aliases.keys).each do |n|
196
- if /#{n}/.match(l)
197
- licenses << n
198
- break
199
- end
200
- end
201
- end
202
- end
203
- end
204
- end
220
+ licenses = search_in_paths(license_file_paths)
205
221
  end
206
222
 
207
223
  # Finally, if we couldn't find a known license, but a license file
@@ -229,13 +245,8 @@ class DerivingLicense
229
245
  end
230
246
  content.split('\n').each do |l|
231
247
  if /license/.match(l)
232
- # Found the word "license", so now look for known license names.
233
- (@@license_details.keys + @@license_aliases.keys).each do |n|
234
- if /#{n}/.match(l)
235
- licenses << n
236
- return licenses
237
- end
238
- end
248
+ licenses = search_in_content(l)
249
+ break unless licenses.empty?
239
250
  end
240
251
  end
241
252
  return licenses # If we didn't return early, there's no match.
@@ -253,21 +264,7 @@ class DerivingLicense
253
264
  break unless readme_file_paths
254
265
 
255
266
  # Open each readme file and check the content.
256
- readme_file_paths.each do |p|
257
- if File.exist?(p)
258
- File.open(p).each_line do |l|
259
- if /license/.match(l)
260
- # Found the word "license", so now look for known license names.
261
- (@@license_details.keys + @@license_aliases.keys).each do |n|
262
- if /#{n}/.match(l)
263
- licenses << n
264
- break
265
- end
266
- end
267
- end
268
- end
269
- end
270
- end
267
+ licenses = search_in_paths(readme_file_paths)
271
268
 
272
269
  end # end of call to yield_gem_source_directory
273
270
  return licenses
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deriving_license
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-02 00:00:00.000000000 Z
12
+ date: 2013-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gemnasium-parser