class Locd::Pattern::Workdir

A {Locd::Pattern} that matches against {Locd::Agent} workdir.

Attributes

cwd[R]

“Current” absolute directory path that a relative {#raw_path} would have been expanded against.

@return [Pathname]

path[R]

Expanded absolute path to test {Locd::Agent#workdir} against.

@return [Pathname]

recursive[R]

When `true`, pattern will additionally match any agents who's {Locd::Agent#workdir} is a subdirectory of the {#path}.

@return [Boolean]

Public Class Methods

new(source, recursive: false, cwd: Pathname.getwd) click to toggle source

Instantiate a new `Locd::Pattern::Workdir`.

@param [String] raw_path

Path to construct for, which may be relative to `cwd`.

@param [Boolean] recursive:

Additionally match agents with `workdir` in subdirectories.

See {#recursive}.

@param [String | Pathname] cwd:

Directory to expand relative paths against.
Calls superclass method Locd::Pattern::new
# File lib/locd/pattern.rb, line 200
def initialize source, recursive: false, cwd: Pathname.getwd
  super source
  @cwd = cwd.to_pn
  @recursive = recursive
  @path = Pathname.new( source ).expand_path @cwd
end

Public Instance Methods

match?(agent) click to toggle source

See if this patten matches an agent.

@param [Locd::Agent] agent

Agent to test against.

@return [Boolean]

`true` if this pattern matches the `agent` {Locd::Agent#label}.
# File lib/locd/pattern.rb, line 216
def match? agent
  if recursive
    agent.workdir.to_s.start_with?( path.to_s + '/' )
  else
    agent.workdir == path
  end
end