Module: SourceRank

Extended by:
ActiveSupport::Concern
Included in:
Project
Defined in:
app/models/concerns/source_rank.rb

Instance Method Summary collapse

Instance Method Details

#all_prereleases?Boolean

Returns:

  • (Boolean)

145
146
147
# File 'app/models/concerns/source_rank.rb', line 145

def all_prereleases?
  prereleases.length == versions.length
end

#any_outdated_dependencies?Boolean

Returns:

  • (Boolean)

141
142
143
# File 'app/models/concerns/source_rank.rb', line 141

def any_outdated_dependencies?
  latest_version.try(:any_outdated_dependencies?)
end

#basic_info_present?Boolean

Returns:

  • (Boolean)

111
112
113
# File 'app/models/concerns/source_rank.rb', line 111

def basic_info_present?
  [description.presence, homepage.presence, repository_url.presence, keywords_array.presence].compact.length > 1
end

#license_present?Boolean

Returns:

  • (Boolean)

123
124
125
# File 'app/models/concerns/source_rank.rb', line 123

def license_present?
  normalized_licenses.present?
end

#log_scale(number) ⇒ Object


153
154
155
156
# File 'app/models/concerns/source_rank.rb', line 153

def log_scale(number)
  return 0 if number <= 0
  Math.log10(number).round
end

#not_brand_new?Boolean

Returns:

  • (Boolean)

136
137
138
139
# File 'app/models/concerns/source_rank.rb', line 136

def not_brand_new?
  versions.any? {|v| v.published_at && v.published_at < 6.months.ago } ||
    (github_tags.published.any? {|v| v.published_at && v.published_at < 6.months.ago })
end

#one_point_oh?Boolean

Returns:

  • (Boolean)

149
150
151
# File 'app/models/concerns/source_rank.rb', line 149

def one_point_oh?
  versions.any?(&:greater_than_1?)
end

#readme_present?Boolean

Returns:

  • (Boolean)

119
120
121
# File 'app/models/concerns/source_rank.rb', line 119

def readme_present?
  github_repository.present? && github_repository.readme.present?
end

#recent_release?Boolean

Returns:

  • (Boolean)

131
132
133
134
# File 'app/models/concerns/source_rank.rb', line 131

def recent_release?
  versions.any? {|v| v.published_at && v.published_at > 6.months.ago } ||
    (github_tags.published.any? {|v| v.published_at && v.published_at > 6.months.ago })
end

#repository_present?Boolean

Returns:

  • (Boolean)

115
116
117
# File 'app/models/concerns/source_rank.rb', line 115

def repository_present?
  github_repository.present?
end

#set_source_rankObject


13
14
15
# File 'app/models/concerns/source_rank.rb', line 13

def set_source_rank
  self.rank = source_rank
end

#source_rankObject


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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/concerns/source_rank.rb', line 17

def source_rank
  r = 0
  # basic information available
  r +=1 if basic_info_present?

  # repo present
  r +=1 if repository_present?

  # readme present
  r +=1 if readme_present?

  # valid license present
  r +=1 if license_present?

  # more than one version
  r +=1 if versions_present?

  # all versions/tags are valid semver numbers
  r +=1 if follows_semver?

  # a version released within the last X months
  r +=1 if recent_release?

  # at least X months old
  r +=1 if not_brand_new?

  # has the project been marked as deprecated?
  r -=5 if is_deprecated?

  # has the project been marked as unmaintained?
  r -=5 if is_unmaintained?

  # has the project been marked as deprecated?
  r -=5 if is_removed?

  # does the latest version have any outdated dependencies
  r -=1 if any_outdated_dependencies?

  # any releases greater than or equal to 1.0.0
  r +=1 if one_point_oh?

  # every version is a prerelease?
  r -=2 if all_prereleases?

  # number of github stars
  r += log_scale(stars)

  # number of dependent projects
  r += log_scale(dependents_count) * 2

  # number of dependent repositories
  r += log_scale(dependent_repositories.open_source.length)

  # number of contributors
  r += (log_scale(github_contributions.length) / 2.0).ceil

  # number of subscribers
  r += (log_scale(subscriptions.length) / 2.0).ceil

  # more than one maintainer/owner?

  # number of downloads

  # documentation available?

  r = 0 if r < 0

  return r
end

#source_rank_breakdownObject


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/models/concerns/source_rank.rb', line 87

def source_rank_breakdown
  {
    basic_info_present:         basic_info_present? ? 1 : 0,
    repository_present:         repository_present? ? 1 : 0,
    readme_present:             readme_present? ? 1 : 0,
    license_present:            license_present? ? 1 : 0,
    versions_present:           versions_present? ? 1 : 0,
    follows_semver:             follows_semver? ? 1 : 0,
    recent_release:             recent_release? ? 1 : 0,
    not_brand_new:              not_brand_new? ? 1 : 0,
    one_point_oh:               one_point_oh? ? 1 : 0,
    dependent_projects:         log_scale(dependents_count) * 2,
    dependent_repositories:     log_scale(dependent_repositories.open_source.length),
    github_stars:               log_scale(stars),
    contributors:               (log_scale(github_contributions.length) / 2.0).ceil,
    subscribers:                (log_scale(subscriptions.length) / 2.0).ceil,
    all_prereleases:            all_prereleases? ? -2 : 0,
    any_outdated_dependencies:  any_outdated_dependencies? ? -1 : 0,
    is_deprecated:              is_deprecated? ? -5 : 0,
    is_unmaintained:            is_unmaintained? ? -5 : 0,
    is_removed:                 is_removed? ? -5 : 0
  }
end

#update_source_rankObject


4
5
6
7
# File 'app/models/concerns/source_rank.rb', line 4

def update_source_rank
  update_column :rank, source_rank
  touch
end

#update_source_rank_asyncObject


9
10
11
# File 'app/models/concerns/source_rank.rb', line 9

def update_source_rank_async
  UpdateSourceRankWorker.perform_async(self.id)
end

#versions_present?Boolean

Returns:

  • (Boolean)

127
128
129
# File 'app/models/concerns/source_rank.rb', line 127

def versions_present?
  versions_count > 1 || (github_tags.published.length > 0)
end