Sha256: e3ae6198e06c356340e62d3897a6afa90ff449f975caaa04f60cb4eb06131ec0

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Adrian
  class FileItem < QueueItem
    attr_accessor :logger

    def initialize(value)
      @value      = value
      created_at
      updated_at
    end

    def path
      value
    end

    def name
      File.basename(path)
    end

    def ==(other)
      other.respond_to?(:name) &&
        name == other.name
    end

    def move(destination)
      destination_path = File.join(destination, File.basename(path))
      logger.info("Moving #{path} to #{destination_path}") if logger
      File.rename(path, destination_path)
      @value = destination_path
    end

    def atime
      File.atime(path).utc
    rescue Errno::ENOENT
      nil
    end

    def mtime
      File.mtime(path).utc
    rescue Errno::ENOENT
      nil
    end

    def updated_at
      @updated_at ||= atime
    end

    def created_at
      @created_at ||= mtime
    end

    def touch(updated_at = Time.new)
      @updated_at = updated_at.utc
      File.utime(updated_at, created_at, path)
    end

    def exist?
      File.exist?(path)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
adrian-1.3.2 lib/adrian/file_item.rb