Class: OSC::Machete::JobDir

Inherits:
Object
  • Object
show all
Defined in:
lib/osc/machete/job_dir.rb

Overview

helper class to create job directories

Instance Method Summary collapse

Constructor Details

#initialize(parent_directory) ⇒ JobDir

Returns a new instance of JobDir.



3
4
5
# File 'lib/osc/machete/job_dir.rb', line 3

def initialize(parent_directory)
  @target = Pathname.new(parent_directory).cleanpath
end

Instance Method Details

#jobdir?(path) ⇒ Boolean

return true if Pathname is a job directory FIXME: this is not used anywhere; remove it?

Returns:

  • (Boolean)


23
24
25
# File 'lib/osc/machete/job_dir.rb', line 23

def jobdir?(path)
  jobdir_name?(path.basename.to_s) && path.directory?
end

#jobdir_name?(name) ⇒ Boolean

return true if the string is a job dir name

Returns:

  • (Boolean)


17
18
19
# File 'lib/osc/machete/job_dir.rb', line 17

def jobdir_name?(name)
  name[/^\d+$/]
end

#jobdirsObject

get a list of all job directories FIXME: this is not used anywhere; remove it?



29
30
31
# File 'lib/osc/machete/job_dir.rb', line 29

def jobdirs
  @target.exist? ? @target.children.select { |i| jobdir?(i) } : []
end

#new_jobdirString

Returns a unique path for a job

Returns:

  • (String)

    A path of a unique job directory as string.



10
11
12
# File 'lib/osc/machete/job_dir.rb', line 10

def new_jobdir
  @target + unique_dir
end

#targetdirsObject

get a list of directories in the target directory FIXME: this is not used anywhere; remove it?



36
37
38
# File 'lib/osc/machete/job_dir.rb', line 36

def targetdirs
  @target.exist? ? @target.children.select(&:directory?) : []
end

#unique_dirObject

find the next unique integer name for a job directory



41
42
43
44
# File 'lib/osc/machete/job_dir.rb', line 41

def unique_dir
  taken_ints = taken_paths.map { |path| path.basename.to_s.to_i }
  (taken_ints.count > 0) ? (taken_ints.max + 1).to_s : 1.to_s
end