Module: Autowow::Features::Fs
- Includes:
- ReflectionUtils::CreateModuleFunctions
- Defined in:
- lib/autowow/features/fs.rb
Instance Method Summary collapse
- #for_dirs(dirs) ⇒ Object
- #git_folder_present ⇒ Object
- #in_place_or_subdirs(in_place) ⇒ Object
- #latest(files) ⇒ Object
- #ls_dirs ⇒ Object
- #older_than(files, quantity, unit) ⇒ Object
Instance Method Details
#for_dirs(dirs) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/autowow/features/fs.rb', line 22 def for_dirs(dirs) dirs.each do |working_dir| # TODO: add handling of directories via extra param to popen3 # https://stackoverflow.com/a/10148084/2771889 Dir.chdir(working_dir) do yield working_dir end end end |
#git_folder_present ⇒ Object
42 43 44 |
# File 'lib/autowow/features/fs.rb', line 42 def git_folder_present File.exist?(".git") end |
#in_place_or_subdirs(in_place) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/autowow/features/fs.rb', line 32 def in_place_or_subdirs(in_place) if in_place yield else for_dirs(ls_dirs) do yield end end end |
#latest(files) ⇒ Object
12 13 14 |
# File 'lib/autowow/features/fs.rb', line 12 def latest(files) files.sort_by { |f| File.mtime(f) }.reverse!.first end |
#ls_dirs ⇒ Object
8 9 10 |
# File 'lib/autowow/features/fs.rb', line 8 def ls_dirs Dir.glob(File.("./*/")).select { |f| File.directory? f } end |
#older_than(files, quantity, unit) ⇒ Object
16 17 18 19 20 |
# File 'lib/autowow/features/fs.rb', line 16 def older_than(files, quantity, unit) files.select do |dir| TimeDifference.between(File.mtime(dir), Time.now).public_send("in_#{unit}") > quantity end end |