summaryrefslogtreecommitdiff
path: root/app/models/blob_viewer/package_json.rb
blob: 46cd2f04f4d36c3c2524de79f25540de43e22d28 (plain)
1
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
module BlobViewer
  class PackageJson < DependencyManager
    include ServerSide

    self.file_types = %i(package_json)

    def manager_name
      'npm'
    end

    def manager_url
      'https://www.npmjs.com/'
    end

    def package_name
      @package_name ||= package_name_from_json('name')
    end

    def package_type
      private? ? 'private package' : super
    end

    def package_url
      private? ? homepage : npm_url
    end

    private

    def private?
      !!json_data['private']
    end

    def homepage
      json_data['homepage']
    end

    def npm_url
      "https://www.npmjs.com/package/#{package_name}"
    end
  end
end