diff options
author | Duana Saskia <starkcoffee@users.noreply.github.com> | 2018-07-25 14:01:10 +0300 |
---|---|---|
committer | Duana Saskia <starkcoffee@users.noreply.github.com> | 2018-08-13 14:36:22 +0300 |
commit | c322976032e45f02b60701ebf244a8a876063078 (patch) | |
tree | b5e959931ee397e368b679fb5c0f16976141a619 /app/models/concerns/protected_ref.rb | |
parent | ece6a1ea6ecffdbde5ff7d663f1ad1eb74f78aa6 (diff) |
Refactor ProtectedRefMatcher to be more generic
Diffstat (limited to 'app/models/concerns/protected_ref.rb')
-rw-r--r-- | app/models/concerns/protected_ref.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/concerns/protected_ref.rb b/app/models/concerns/protected_ref.rb index e62e680af6e..af387c99f3d 100644 --- a/app/models/concerns/protected_ref.rb +++ b/app/models/concerns/protected_ref.rb @@ -50,14 +50,20 @@ module ProtectedRef .map(&:"#{action}_access_levels").flatten end + # Returns all protected refs that match the given ref name. + # This checks all records from the scope built up so far, and does + # _not_ return a relation. + # + # This method optionally takes in a list of `protected_refs` to search + # through, to avoid calling out to the database. def matching(ref_name, protected_refs: nil) - ProtectedRefMatcher.matching(self, ref_name, protected_refs: protected_refs) + (protected_refs || self.all).select { |protected_ref| protected_ref.matches?(ref_name) } end end private def ref_matcher - @ref_matcher ||= ProtectedRefMatcher.new(self) + @ref_matcher ||= RefMatcher.new(self.name) end end |