Class: BitBroker::Metadata::FileInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbroker/metadata.rb

Constant Summary collapse

STATUS_REMOVED =

describes file status

1 << 0

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#mtimeObject (readonly)

Returns the value of attribute mtime.



83
84
85
# File 'lib/bitbroker/metadata.rb', line 83

def mtime
  @mtime
end

#pathObject (readonly)

Returns the value of attribute path.



83
84
85
# File 'lib/bitbroker/metadata.rb', line 83

def path
  @path
end

#sizeObject (readonly)

Returns the value of attribute size.



83
84
85
# File 'lib/bitbroker/metadata.rb', line 83

def size
  @size
end

Instance Method Details

#removeObject



109
110
111
# File 'lib/bitbroker/metadata.rb', line 109

def remove
  @status |= STATUS_REMOVED
end

#removed?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/bitbroker/metadata.rb', line 106

def removed?
  @status & STATUS_REMOVED > 0
end

#to_hObject



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

#updateObject



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