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



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/api/helpers/snippets_helpers.rb', line 52

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



66
67
68
69
70
71
72
73
74
75
# File 'lib/api/helpers/snippets_helpers.rb', line 66

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