class StoreAgent::Node::Metadata

ファイルサイズ、作成者、更新日時などの情報

Public Class Methods

datasize_format(size) click to toggle source

ディスク使用量をバイトからキロバイトなどの単位に変換するメソッド

# File lib/store_agent/node/attachment/metadata.rb, line 55
def self.datasize_format(size)
  byte_names = %w(KB MB GB TB PB)
  byte_length = size.abs.to_s(2).length
  if byte_length <= 10
    "#{size} bytes"
  else
    exponent = [byte_names.length, (byte_length - 1) / 10].min
    sprintf("%0.2f%s", size.to_f / (2 ** (10 * exponent)), byte_names[exponent - 1])
  end
end

Public Instance Methods

create() click to toggle source
Calls superclass method StoreAgent::Node::Attachment#create
# File lib/store_agent/node/attachment/metadata.rb, line 23
def create
  super
  parent.update(disk_usage: disk_usage, directory_file_count: 1, tree_file_count: 1, recursive: true)
end
delete() click to toggle source
Calls superclass method StoreAgent::Node::Attachment#delete
# File lib/store_agent/node/attachment/metadata.rb, line 40
def delete
  parent.update(disk_usage: -disk_usage, directory_file_count: -1, tree_file_count: -1, recursive: true)
  super
end
disk_usage() click to toggle source
# File lib/store_agent/node/attachment/metadata.rb, line 66
def disk_usage
  if directory?
    self["directory_bytes"]
  else
    self["bytes"]
  end
end
disk_usage=(usage) click to toggle source
# File lib/store_agent/node/attachment/metadata.rb, line 74
def disk_usage=(usage)
  usage_string = StoreAgent::Node::Metadata.datasize_format(usage)
  if directory?
    self["directory_size"] = usage_string
    self["directory_bytes"] = usage
  else
    self["size"] = usage_string
    self["bytes"] = usage
  end
end
file_path() click to toggle source

オブジェクトのメタデータを保存しているファイルの絶対パス

# File lib/store_agent/node/attachment/metadata.rb, line 50
def file_path
  "#{base_path}#{StoreAgent.config.metadata_extension}"
end
owner=(identifier) click to toggle source
# File lib/store_agent/node/attachment/metadata.rb, line 85
def owner=(identifier)
  self["owner"] = identifier
end
update(disk_usage: 0, directory_file_count: 0, tree_file_count: 0, recursive: false) click to toggle source
# File lib/store_agent/node/attachment/metadata.rb, line 28
def update(disk_usage: 0, directory_file_count: 0, tree_file_count: 0, recursive: false)
  if directory?
    self["directory_file_count"] += directory_file_count
    self["tree_file_count"] += tree_file_count
  end
  self.disk_usage += disk_usage
  save
  if recursive
    parent.update(disk_usage: disk_usage, tree_file_count: tree_file_count, recursive: recursive)
  end
end
updated_at=(time) click to toggle source
# File lib/store_agent/node/attachment/metadata.rb, line 89
def updated_at=(time)
  self["updated_at"] = time.to_s
  self["updated_at_unix_timestamp"] = time.to_i
end

Private Instance Methods

initial_data() click to toggle source
# File lib/store_agent/node/attachment/metadata.rb, line 104
def initial_data
  object.default_metadata
end
parent() click to toggle source
# File lib/store_agent/node/attachment/metadata.rb, line 96
def parent
  if root?
    SuperRootMetadata.new
  else
    object.parent_directory.metadata
  end
end