class Owners::Subscription

Represents a single line of an OWNERS file.

It contains some useful methods for inspecting the subscriptions themselves like the file, line, and filter, and subscribers.

@api public

Constants

COMMENT
WILDCARD

Attributes

file[R]
line[R]
root[R]
subscription[R]

Public Class Methods

new(subscription, line, config) click to toggle source
   # File lib/owners/subscription.rb
17 def initialize(subscription, line, config)
18   @subscribers, @filter = subscription.split(/\s+/, 2)
19   @subscription = subscription
20   @line = line
21   @file = config.file.sub("./", "")
22   @root = config.root
23 end

Public Instance Methods

<=>(other) click to toggle source
   # File lib/owners/subscription.rb
25 def <=>(other)
26   location <=> other.location
27 end
filter() click to toggle source
   # File lib/owners/subscription.rb
29 def filter
30   Regexp.new(@filter || WILDCARD)
31 end
location() click to toggle source
   # File lib/owners/subscription.rb
33 def location
34   [file, line].join(":")
35 end
metadata?() click to toggle source
   # File lib/owners/subscription.rb
37 def metadata?
38   comment? || empty?
39 end
source() click to toggle source
   # File lib/owners/subscription.rb
41 def source
42   filter.source
43 end
subscribed?(path) click to toggle source
   # File lib/owners/subscription.rb
45 def subscribed?(path)
46   path =~ prefix && relative(path) =~ filter
47 end
subscribers() click to toggle source
   # File lib/owners/subscription.rb
49 def subscribers
50   @subscribers.split(",").reject(&:empty?)
51 end
to_s() click to toggle source
   # File lib/owners/subscription.rb
53 def to_s
54   [source, location].join(" ")
55 end

Private Instance Methods

comment?() click to toggle source
   # File lib/owners/subscription.rb
59 def comment?
60   subscription =~ COMMENT
61 end
empty?() click to toggle source
   # File lib/owners/subscription.rb
63 def empty?
64   subscription.strip.empty?
65 end
prefix() click to toggle source
   # File lib/owners/subscription.rb
67 def prefix
68   /\.?\/?#{root}\//
69 end
relative(path) click to toggle source
   # File lib/owners/subscription.rb
71 def relative(path)
72   path.sub(prefix, "")
73 end