Module: API::Helpers::SnippetsHelpers

Extended by:
Grape::API::Helpers
Defined in:
lib/api/helpers/snippets_helpers.rb

Instance Method Summary collapse

Instance Method Details

#content_for(snippet) ⇒ Object


48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/api/helpers/snippets_helpers.rb', line 48

def content_for(snippet)
  if snippet.empty_repo?
    env['api.format'] = :txt
    content_type 'text/plain'
    header['Content-Disposition'] = 'attachment'

    snippet.content
  else
    blob = snippet.blobs.first

    send_git_blob(blob.repository, blob)
  end
end

#file_content_for(snippet) ⇒ Object


62
63
64
65
66
67
68
69
70
71
# File 'lib/api/helpers/snippets_helpers.rb', line 62

def file_content_for(snippet)
  repo = snippet.repository
  commit = repo.commit(params[:ref])
  not_found!('Reference') unless commit

  blob = repo.blob_at(commit.sha, params[:file_path])
  not_found!('File') unless blob

  send_git_blob(repo, blob)
end