Class: Locd::Pattern
- Inherits:
-
Object
- Object
- Locd::Pattern
- Defined in:
- lib/locd/pattern.rb
Overview
Abstract base class for patterns used to match Agent instances.
Defined Under Namespace
Instance Attribute Summary collapse
-
#source ⇒ String
readonly
Raw source string provided at initialization.
Class Method Summary collapse
-
.from(object, **options) ⇒ Locd::Pattern::Label | Locd::Pattern::Workdir
Factory method to construct the correct concrete subclass.
Instance Method Summary collapse
-
#initialize(source) ⇒ Pattern
constructor
Construct a new pattern.
- #match?(agent) ⇒ Boolean
Constructor Details
#initialize(source) ⇒ Pattern
Construct a new pattern. Should only be called via super
.
85 86 87 |
# File 'lib/locd/pattern.rb', line 85 def initialize source @source = source end |
Instance Attribute Details
#source ⇒ String (readonly)
Raw source string provided at initialization.
77 78 79 |
# File 'lib/locd/pattern.rb', line 77 def source @source end |
Class Method Details
.from(object, **options) ⇒ Locd::Pattern::Label | Locd::Pattern::Workdir
Factory method to construct the correct concrete subclass.
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 |
# File 'lib/locd/pattern.rb', line 42 def self.from object, ** case object when String string = object case string when '' raise ArgumentError, "Empty string is not a valid pattern" when /\A[\.\~\/]/ Locd::Pattern::Workdir.new string, ** else Locd::Pattern::Label.new string, ** end when Locd::Pattern object else raise TypeError.new binding.erb <<-END Expected `object` to be {String} or {Locd::Pattern}, found <%= object.class %> `object` (first argument): <%= object.pretty_inspect %> Options: <%= options.pretty_inspect %> END end end |
Instance Method Details
#match?(agent) ⇒ Boolean
93 94 95 |
# File 'lib/locd/pattern.rb', line 93 def match? agent raise NRSER::AbstractMethodError.new( self, __method__ ) end |