Class: OSC::Machete::JobDir
- Inherits:
-
Object
- Object
- OSC::Machete::JobDir
- Defined in:
- lib/osc/machete/job_dir.rb
Overview
helper class to create job directories
Instance Method Summary collapse
-
#initialize(parent_directory) ⇒ JobDir
constructor
A new instance of JobDir.
-
#jobdir?(path) ⇒ Boolean
return true if Pathname is a job directory FIXME: this is not used anywhere; remove it?.
-
#jobdir_name?(name) ⇒ Boolean
return true if the string is a job dir name.
-
#jobdirs ⇒ Object
get a list of all job directories FIXME: this is not used anywhere; remove it?.
-
#new_jobdir ⇒ String
Returns a unique path for a job.
-
#targetdirs ⇒ Object
get a list of directories in the target directory FIXME: this is not used anywhere; remove it?.
-
#unique_dir ⇒ Object
find the next unique integer name for a job directory.
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?
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
17 18 19 |
# File 'lib/osc/machete/job_dir.rb', line 17 def jobdir_name?(name) name[/^\d+$/] end |
#jobdirs ⇒ Object
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_jobdir ⇒ String
Returns a unique path for a job
10 11 12 |
# File 'lib/osc/machete/job_dir.rb', line 10 def new_jobdir @target + unique_dir end |
#targetdirs ⇒ Object
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_dir ⇒ Object
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 |