Sha256: 1c18a82c730f301f8813fd9a17214874a829c7b0152de208252c2ee9715c72b2

Contents?: true

Size: 1.09 KB

Versions: 17

Compression:

Stored size: 1.09 KB

Contents

require_relative "../time_difference"

module Autowow
  module Features
    module Fs
      using RefinedTimeDifference

      def ls_dirs
        Dir.glob(File.expand_path("./*/")).select { |f| File.directory? f }
      end

      def latest(files)
        files.sort_by { |f| File.mtime(f) }.reverse!.first
      end

      def older_than(files, quantity, unit)
        files.select do |dir|
          TimeDifference.between(File.mtime(dir), Time.now).public_send("in_#{unit}") > quantity
        end
      end

      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

      def in_place_or_subdirs(in_place)
        if in_place
          yield
        else
          for_dirs(ls_dirs) do
            yield
          end
        end
      end

      def git_folder_present
        File.exist?(".git")
      end

      include ReflectionUtils::CreateModuleFunctions
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
autowow-0.17.1 lib/autowow/features/fs.rb
autowow-0.17.0 lib/autowow/features/fs.rb
autowow-0.16.1 lib/autowow/features/fs.rb
autowow-0.16.0 lib/autowow/features/fs.rb
autowow-0.15.0 lib/autowow/features/fs.rb
autowow-0.12.1 lib/autowow/features/fs.rb
autowow-0.12.0 lib/autowow/features/fs.rb
autowow-0.11.2 lib/autowow/features/fs.rb
autowow-0.11.1 lib/autowow/features/fs.rb
autowow-0.11.0 lib/autowow/features/fs.rb
autowow-0.10.1 lib/autowow/features/fs.rb
autowow-0.9.6 lib/autowow/features/fs.rb
autowow-0.9.5 lib/autowow/features/fs.rb
autowow-0.9.4 lib/autowow/features/fs.rb
autowow-0.9.3 lib/autowow/features/fs.rb
autowow-0.9.2 lib/autowow/features/fs.rb
autowow-0.9.1 lib/autowow/features/fs.rb