Merge branch 'master' into coc

This commit is contained in:
Ben Balter 2018-08-23 15:21:23 -04:00 committed by GitHub
commit a5df638985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View File

@ -42,9 +42,23 @@ module Licensee
@data = metadata || {}
end
# TODO: In the next major release, filename should be the basename
# and path should be either the absolute path or the relative path to
# the project root, but maintaining the alias for backward compatability
def filename
@data[:name]
end
alias path filename
def directory
@data[:dir] || '.'
end
alias dir directory
def path_relative_to_root
File.join(directory, filename)
end
alias relative_path path_relative_to_root
def possible_matchers
raise 'Not implemented'
@ -64,7 +78,6 @@ module Licensee
end
alias match license
alias path filename
def matched_license
license.spdx_id if license

View File

@ -59,9 +59,12 @@ module Licensee
# :name - the file's path relative to the repo root
# :oid - the file's OID
def files
@files ||= commit.tree.map do |entry|
next unless entry[:type] == :blob
{ name: entry[:name], oid: entry[:oid] }
@files ||= files_from_tree(commit.tree)
end
def files_from_tree(tree, dir = '.')
tree.select { |e| e[:type] == :blob }.map do |entry|
entry.merge(dir: dir)
end.compact
end
end

View File

@ -156,5 +156,13 @@ module Licensee
def load_file(_file)
raise 'Not implemented'
end
def path_relative_to_root(path)
return path if is_a?(GitProject) || path.nil?
root = Pathname.new(@dir)
path = Pathname.new(path)
path.relative_path_from(root).to_s
end
end
end