Class: Locd::Pattern::Workdir

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

Overview

A Locd::Pattern that matches against Agent workdir.

Instance Attribute Summary collapse

Attributes inherited from Locd::Pattern

#source

Instance Method Summary collapse

Methods inherited from Locd::Pattern

from

Constructor Details

#initialize(source, recursive: false, cwd: Pathname.getwd) ⇒ Workdir

Instantiate a new Locd::Pattern::Workdir.

Parameters:

  • raw_path (String)

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

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

    Additionally match agents with workdir in subdirectories.

    See #recursive.

  • cwd: (String | Pathname) (defaults to: Pathname.getwd)

    Directory to expand relative paths against.



200
201
202
203
204
205
# 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

Instance Attribute Details

#cwdPathname (readonly)

"Current" absolute directory path that a relative #raw_path would have been expanded against.

Returns:

  • (Pathname)


169
170
171
# File 'lib/locd/pattern.rb', line 169

def cwd
  @cwd
end

#pathPathname (readonly)

Expanded absolute path to test Agent#workdir against.

Returns:

  • (Pathname)


184
185
186
# File 'lib/locd/pattern.rb', line 184

def path
  @path
end

#recursiveBoolean (readonly)

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

Returns:

  • (Boolean)


177
178
179
# File 'lib/locd/pattern.rb', line 177

def recursive
  @recursive
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.



216
217
218
219
220
221
222
# 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