2020-01-31 16:08:52 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Entities
|
2020-12-17 07:09:57 -05:00
|
|
|
class Snippet < BasicSnippet
|
2020-01-31 16:08:52 -05:00
|
|
|
expose :author, using: Entities::UserBasic
|
2020-04-21 11:21:10 -04:00
|
|
|
expose :file_name do |snippet|
|
2021-06-11 11:09:58 -04:00
|
|
|
snippet_files.first || snippet.file_name
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
2020-10-06 14:08:49 -04:00
|
|
|
expose :files do |snippet, options|
|
2021-06-11 11:09:58 -04:00
|
|
|
snippet_files.map do |file|
|
2020-07-01 11:08:45 -04:00
|
|
|
{
|
|
|
|
path: file,
|
|
|
|
raw_url: Gitlab::UrlBuilder.build(snippet, file: file, ref: snippet.repository.root_ref)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2021-06-11 11:09:58 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def snippet_files
|
|
|
|
@snippet_files ||= object.list_files
|
|
|
|
end
|
2020-01-31 16:08:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|