Class: Adrian::FileItem

Inherits:
QueueItem show all
Defined in:
lib/adrian/file_item.rb

Instance Attribute Summary collapse

Attributes inherited from QueueItem

#queue, #value

Instance Method Summary collapse

Methods inherited from QueueItem

#age

Constructor Details

#initialize(value) ⇒ FileItem

Returns a new instance of FileItem.



5
6
7
8
# File 'lib/adrian/file_item.rb', line 5

def initialize(value)
  @value = value
  stat
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/adrian/file_item.rb', line 3

def logger
  @logger
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
21
# File 'lib/adrian/file_item.rb', line 18

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

#atimeObject



36
37
38
# File 'lib/adrian/file_item.rb', line 36

def atime
  stat ? stat.atime.utc : nil
end

#created_atObject



48
49
50
# File 'lib/adrian/file_item.rb', line 48

def created_at
  @created_at ||= mtime
end

#exist?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/adrian/file_item.rb', line 57

def exist?
  File.exist?(path)
end

#move(destination) ⇒ Object



23
24
25
26
27
28
# 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

#mtimeObject



40
41
42
# File 'lib/adrian/file_item.rb', line 40

def mtime
  stat ? stat.mtime.utc : nil
end

#nameObject



14
15
16
# File 'lib/adrian/file_item.rb', line 14

def name
  File.basename(path)
end

#pathObject



10
11
12
# File 'lib/adrian/file_item.rb', line 10

def path
  value
end

#statObject



30
31
32
33
34
# File 'lib/adrian/file_item.rb', line 30

def stat
  @stat ||= File.stat(path)
rescue Errno::ENOENT
  nil
end

#touch(updated_at = Time.now) ⇒ Object



52
53
54
55
# 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_atObject



44
45
46
# File 'lib/adrian/file_item.rb', line 44

def updated_at
  @updated_at ||= atime
end