mirror of https://github.com/licensee/licensee.git
Merge branch 'master' into coc
This commit is contained in:
commit
a5df638985
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue