Class: Locd::Pattern::Label

Inherits:
Locd::Pattern show all
Defined in:
lib/locd/pattern.rb

Overview

A Locd::Pattern that matches against Agent labels with "glob-style" matching (like the lunchy gem).

Right now only handles the * wildcard!

Instance Attribute Summary collapse

Attributes inherited from Locd::Pattern

#source

Instance Method Summary collapse

Methods inherited from Locd::Pattern

from

Constructor Details

#initialize(source, full: false, ignore_case: false) ⇒ Label

Instantiate a new Locd::Pattern::Label.

Parameters:

  • source (String)

    "Glob-style" pattern to search for in Agent#label strings.

  • full: (Boolean) (defaults to: false)

    When true, pattern must match entire label.

    When false (default), may match any portion.

  • ignore_case: (Boolean) (defaults to: false)

    Perform case-insensitive matching.



137
138
139
140
141
142
# File 'lib/locd/pattern.rb', line 137

def initialize source, full: false, ignore_case: false
  super source
  @regexp = Locd::Label.regexp_for_glob source,
                                        full: full,
                                        ignore_case: ignore_case
end

Instance Attribute Details

#regexpRegexp (readonly)

Label Regexp used by #match?

Returns:

  • (Regexp)


121
122
123
# File 'lib/locd/pattern.rb', line 121

def regexp
  @regexp
end

#stringattr_type (readonly)

TODO document string attribute.

Returns:

  • (attr_type)


114
115
116
# File 'lib/locd/pattern.rb', line 114

def string
  @string
end

Instance Method Details

#match?(agent) ⇒ Boolean

See if this patten matches an agent.

Parameters:

Returns:

  • (Boolean)

    true if this pattern matches the agent Agent#label.



153
154
155
# File 'lib/locd/pattern.rb', line 153

def match? agent
  agent.label =~ regexp
end