Class: BitBroker::Metadata::FileInfo
- Inherits:
-
Object
- Object
- BitBroker::Metadata::FileInfo
- Defined in:
- lib/bitbroker/metadata.rb
Constant Summary collapse
- STATUS_REMOVED =
describes file status
1 << 0
Instance Attribute Summary collapse
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(dirpath, filepath) ⇒ FileInfo
constructor
A new instance of FileInfo.
- #remove ⇒ Object
- #removed? ⇒ Boolean
- #to_h ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(dirpath, filepath) ⇒ FileInfo
Returns a new instance of FileInfo.
88 89 90 91 92 93 94 |
# File 'lib/bitbroker/metadata.rb', line 88 def initialize(dirpath, filepath) @fpath = "#{dirpath}/#{filepath}" @path = filepath @status = 0 self.update end |
Instance Attribute Details
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
83 84 85 |
# File 'lib/bitbroker/metadata.rb', line 83 def mtime @mtime end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
83 84 85 |
# File 'lib/bitbroker/metadata.rb', line 83 def path @path end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
83 84 85 |
# File 'lib/bitbroker/metadata.rb', line 83 def size @size end |
Instance Method Details
#remove ⇒ Object
109 110 111 |
# File 'lib/bitbroker/metadata.rb', line 109 def remove @status |= STATUS_REMOVED end |
#removed? ⇒ Boolean
106 107 108 |
# File 'lib/bitbroker/metadata.rb', line 106 def removed? @status & STATUS_REMOVED > 0 end |
#to_h ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/bitbroker/metadata.rb', line 112 def to_h { 'path' => @path, 'status' => @status, 'size' => @size, 'mtime' => @mtime.to_s, } end |
#update ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/bitbroker/metadata.rb', line 95 def update if FileTest.exist? @fpath file = File.new(@fpath) @size = file.size @mtime = file.mtime else @size = 0 @mtime = Time.new(0) end end |