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 || {}
|
@data = metadata || {}
|
||||||
end
|
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
|
def filename
|
||||||
@data[:name]
|
@data[:name]
|
||||||
end
|
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
|
def possible_matchers
|
||||||
raise 'Not implemented'
|
raise 'Not implemented'
|
||||||
|
@ -64,7 +78,6 @@ module Licensee
|
||||||
end
|
end
|
||||||
|
|
||||||
alias match license
|
alias match license
|
||||||
alias path filename
|
|
||||||
|
|
||||||
def matched_license
|
def matched_license
|
||||||
license.spdx_id if license
|
license.spdx_id if license
|
||||||
|
|
|
@ -59,9 +59,12 @@ module Licensee
|
||||||
# :name - the file's path relative to the repo root
|
# :name - the file's path relative to the repo root
|
||||||
# :oid - the file's OID
|
# :oid - the file's OID
|
||||||
def files
|
def files
|
||||||
@files ||= commit.tree.map do |entry|
|
@files ||= files_from_tree(commit.tree)
|
||||||
next unless entry[:type] == :blob
|
end
|
||||||
{ name: entry[:name], oid: entry[:oid] }
|
|
||||||
|
def files_from_tree(tree, dir = '.')
|
||||||
|
tree.select { |e| e[:type] == :blob }.map do |entry|
|
||||||
|
entry.merge(dir: dir)
|
||||||
end.compact
|
end.compact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -156,5 +156,13 @@ module Licensee
|
||||||
def load_file(_file)
|
def load_file(_file)
|
||||||
raise 'Not implemented'
|
raise 'Not implemented'
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue