Sha256: 170b9b49c432c38088aeb48dd9c9e963600695c9e574810f20e92e788fbdb3f3

Contents?: true

Size: 1.09 KB

Versions: 7

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

7 entries across 7 versions & 1 rubygems

Version Path
autowow-0.8.0 lib/autowow/features/fs.rb
autowow-0.7.0 lib/autowow/features/fs.rb
autowow-0.6.3 lib/autowow/features/fs.rb
autowow-0.6.0 lib/autowow/features/fs.rb
autowow-0.5.0 lib/autowow/features/fs.rb
autowow-0.4.1 lib/autowow/features/fs.rb
autowow-0.4.0 lib/autowow/features/fs.rb