Skip to content

Commit b45baa2

Browse files
committed
Fix allowed scopes when disallowed is empty
1 parent 776c80d commit b45baa2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app/models/library.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ class Library < ApplicationRecord
44
scope :gem, -> { where(source: :remote_gem) }
55
scope :github, -> { where(source: :github) }
66
scope :stdlib, -> { where(source: :stdlib) }
7-
scope :allowed_gem, -> { gem.where.not("name LIKE ANY (array[?])", wildcard(Rubydoc.config.libraries.disallowed_gems)) }
8-
scope :allowed_github, -> { github.where.not("concat(owner, '/', name) LIKE ANY (array[?])", wildcard(Rubydoc.config.libraries.disallowed_projects)) }
7+
8+
scope :allowed_gem, -> do
9+
list = Rubydoc.config.libraries.disallowed_gems
10+
list.blank? ? gem : gem.where.not("name LIKE ANY (array[?])", wildcard(list))
11+
end
12+
13+
scope :allowed_github, -> do
14+
list = Rubydoc.config.libraries.disallowed_projects
15+
list.blank? ? github : github.where.not("concat(owner, '/', name) LIKE ANY (array[?])", wildcard(list))
16+
end
917

1018
def self.wildcard(list)
1119
list.map { |item| item.gsub("*", "%") }

0 commit comments

Comments
 (0)