Class: Owners::Subscription
- Inherits:
-
Object
- Object
- Owners::Subscription
- Includes:
- Comparable
- Defined in:
- lib/owners/subscription.rb
Overview
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.
Constant Summary collapse
- COMMENT =
/^\s*\/\//
- WILDCARD =
/.*/
Instance Attribute Summary collapse
- #file ⇒ Object readonly
- #line ⇒ Object readonly
- #root ⇒ Object readonly
- #subscription ⇒ Object readonly
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #filter ⇒ Object
-
#initialize(subscription, line, config) ⇒ Subscription
constructor
A new instance of Subscription.
- #location ⇒ Object
- #metadata? ⇒ Boolean
- #source ⇒ Object
- #subscribed?(path) ⇒ Boolean
- #subscribers ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(subscription, line, config) ⇒ Subscription
Returns a new instance of Subscription.
17 18 19 20 21 22 23 |
# File 'lib/owners/subscription.rb', line 17 def initialize(subscription, line, config) @subscribers, @filter = subscription.split(/\s+/, 2) @subscription = subscription @line = line @file = config.file.sub("./", "") @root = config.root end |
Instance Attribute Details
#file ⇒ Object (readonly)
15 16 17 |
# File 'lib/owners/subscription.rb', line 15 def file @file end |
#line ⇒ Object (readonly)
15 16 17 |
# File 'lib/owners/subscription.rb', line 15 def line @line end |
#subscription ⇒ Object (readonly)
15 16 17 |
# File 'lib/owners/subscription.rb', line 15 def subscription @subscription end |
Instance Method Details
#<=>(other) ⇒ Object
25 26 27 |
# File 'lib/owners/subscription.rb', line 25 def <=>(other) location <=> other.location end |
#filter ⇒ Object
29 30 31 |
# File 'lib/owners/subscription.rb', line 29 def filter Regexp.new(@filter || WILDCARD) end |
#location ⇒ Object
33 34 35 |
# File 'lib/owners/subscription.rb', line 33 def location [file, line].join(":") end |
#metadata? ⇒ Boolean
37 38 39 |
# File 'lib/owners/subscription.rb', line 37 def comment? || empty? end |
#source ⇒ Object
41 42 43 |
# File 'lib/owners/subscription.rb', line 41 def source filter.source end |
#subscribed?(path) ⇒ Boolean
45 46 47 |
# File 'lib/owners/subscription.rb', line 45 def subscribed?(path) path =~ prefix && relative(path) =~ filter end |
#subscribers ⇒ Object
49 50 51 |
# File 'lib/owners/subscription.rb', line 49 def subscribers @subscribers.split(",").reject(&:empty?) end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/owners/subscription.rb', line 53 def to_s [source, location].join(" ") end |