Class: Api::DocsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/api/docs_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/api/docs_controller.rb', line 2

def index
  @cache_version = 'v1.1'
  @api_key = logged_in? ? current_user.api_key : 'YOUR_API_KEY'
  @project = Project.platform('npm').find_by_name('grunt') || Project.platform('rubygems').first

  @version = @project.versions.newest_first.first

  dependencies = @version.dependencies || []

  deps = dependencies.map do |dependency|
    {
      project_name: dependency.project_name,
      name: dependency.project_name,
      platform: dependency.platform,
      requirements: dependency.requirements,
      latest_stable: dependency.try(:project).try(:latest_stable_release_number),
      latest: dependency.try(:project).try(:latest_release_number),
      deprecated: dependency.try(:project).try(:is_deprecated?),
      outdated: dependency.outdated?
    }
  end

  @dependencies = @project.as_json(only: Project::API_FIELDS, methods: [:package_manager_url, :stars, :keywords])
  @dependencies[:dependencies] = deps

  @github_repository = GithubRepository.find_by_full_name('gruntjs/grunt') || GithubRepository.first

  @repo_dependencies = []

  dependencies = @github_repository.repository_dependencies || []

  deps = dependencies.map do |dependency|
    {
      project_name: dependency.project_name,
      name: dependency.project_name,
      platform: dependency.platform,
      requirements: dependency.requirements,
      latest_stable: dependency.try(:project).try(:latest_stable_release_number),
      latest: dependency.try(:project).try(:latest_release_number),
      deprecated: dependency.try(:project).try(:is_deprecated?),
      outdated: dependency.outdated?
    }
  end

  @repo_dependencies = @github_repository.as_json({
    except: [:id, :github_organisation_id, :owner_id]
  })
  @repo_dependencies[:dependencies] = deps

  @search = Project.search('grunt').records
end