Class: Adrian::FileItem
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Attributes inherited from QueueItem
Instance Method Summary collapse
- #==(other) ⇒ Object
- #atime ⇒ Object
- #created_at ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(value) ⇒ FileItem
constructor
A new instance of FileItem.
- #move(destination) ⇒ Object
- #mtime ⇒ Object
- #name ⇒ Object
- #path ⇒ Object
- #stat ⇒ Object
- #touch(updated_at = Time.now) ⇒ Object
- #updated_at ⇒ Object
Methods inherited from QueueItem
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
#logger ⇒ Object
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 |
#atime ⇒ Object
36 37 38 |
# File 'lib/adrian/file_item.rb', line 36 def atime stat ? stat.atime.utc : nil end |
#created_at ⇒ Object
48 49 50 |
# File 'lib/adrian/file_item.rb', line 48 def created_at @created_at ||= mtime end |
#exist? ⇒ 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 |
#mtime ⇒ Object
40 41 42 |
# File 'lib/adrian/file_item.rb', line 40 def mtime stat ? stat.mtime.utc : nil end |
#name ⇒ Object
14 15 16 |
# File 'lib/adrian/file_item.rb', line 14 def name File.basename(path) end |
#path ⇒ Object
10 11 12 |
# File 'lib/adrian/file_item.rb', line 10 def path value end |
#stat ⇒ Object
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_at ⇒ Object
44 45 46 |
# File 'lib/adrian/file_item.rb', line 44 def updated_at @updated_at ||= atime end |