Sha256: d1357e22aa8e2a004578b071ea45a8485d5e79fd467b619f03d72b8a0a460ed8

Contents?: true

Size: 907 Bytes

Versions: 3

Compression:

Stored size: 907 Bytes

Contents

module Adrian
  class FileItem < QueueItem
    attr_accessor :logger

    def initialize(value, created_at = Time.now)
      @value      = value
      @created_at = 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 updated_at
      @updated_at ||= File.mtime(path).utc
    rescue Errno::ENOENT
      nil
    end

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

    def exist?
      File.exist?(path)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adrian-1.3.1 lib/adrian/file_item.rb
adrian-1.3.0 lib/adrian/file_item.rb
adrian-1.2.0 lib/adrian/file_item.rb