class Adrian::FileItem

Attributes

logger[RW]

Public Class Methods

new(value) click to toggle source
# File lib/adrian/file_item.rb, line 5
def initialize(value)
  @value = value
  stat
end

Public Instance Methods

==(other) click to toggle source
# File lib/adrian/file_item.rb, line 18
def ==(other)
  other.respond_to?(:name) &&
    name == other.name
end
atime() click to toggle source
# File lib/adrian/file_item.rb, line 36
def atime
  stat ? stat.atime.utc : nil
end
created_at() click to toggle source
# File lib/adrian/file_item.rb, line 48
def created_at
  @created_at ||= mtime
end
exist?() click to toggle source
# File lib/adrian/file_item.rb, line 57
def exist?
  File.exist?(path)
end
move(destination) click to toggle source
# File lib/adrian/file_item.rb, line 23
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
mtime() click to toggle source
# File lib/adrian/file_item.rb, line 40
def mtime
  stat ? stat.mtime.utc : nil
end
name() click to toggle source
# File lib/adrian/file_item.rb, line 14
def name
  File.basename(path)
end
path() click to toggle source
# File lib/adrian/file_item.rb, line 10
def path
  value
end
stat() click to toggle source
# File lib/adrian/file_item.rb, line 30
def stat
  @stat ||= File.stat(path)
rescue Errno::ENOENT
  nil
end
touch(updated_at = Time.now) click to toggle source
# File lib/adrian/file_item.rb, line 52
def touch(updated_at = Time.now)
  @updated_at = updated_at.utc
  File.utime(updated_at, created_at, path)
end
updated_at() click to toggle source
# File lib/adrian/file_item.rb, line 44
def updated_at
  @updated_at ||= atime
end