Class: StoreAgent::Node::Metadata
- Inherits:
-
Attachment
- Object
- Attachment
- StoreAgent::Node::Metadata
- Defined in:
- lib/store_agent/node/attachment/metadata.rb
Overview
ファイルサイズ、作成者、更新日時などの情報
Direct Known Subclasses
Defined Under Namespace
Classes: SuperRootMetadata
Instance Attribute Summary
Attributes inherited from Attachment
Class Method Summary collapse
-
.datasize_format(size) ⇒ Object
ディスク使用量をバイトからキロバイトなどの単位に変換するメソッド.
Instance Method Summary collapse
-
#base_path ⇒ Object
:nodoc:.
- #create ⇒ Object
- #delete ⇒ Object
- #disk_usage ⇒ Object
- #disk_usage=(usage) ⇒ Object
-
#file_path ⇒ Object
オブジェクトのメタデータを保存しているファイルの絶対パス.
- #owner=(identifier) ⇒ Object
- #update(disk_usage: 0, directory_file_count: 0, tree_file_count: 0, recursive: false) ⇒ Object
- #updated_at=(time) ⇒ Object
Methods inherited from Attachment
#data, #initialize, #inspect, #load, #reload, #save
Methods included from Validator
#validates_to_be_excluded_slash!, #validates_to_be_not_guest_identifier!, #validates_to_be_not_nil_value!, #validates_to_be_not_superuser_identifier!, #validates_to_be_string_or_symbol!
Constructor Details
This class inherits a constructor from StoreAgent::Node::Attachment
Class Method Details
.datasize_format(size) ⇒ Object
ディスク使用量をバイトからキロバイトなどの単位に変換するメソッド
55 56 57 58 59 60 61 62 63 64 |
# 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 |
Instance Method Details
#base_path ⇒ Object
:nodoc:
45 46 47 |
# File 'lib/store_agent/node/attachment/metadata.rb', line 45 def base_path # :nodoc: "#{@object.workspace.}#{@object.path}" end |
#create ⇒ Object
23 24 25 26 |
# 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 ⇒ Object
40 41 42 43 |
# 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 ⇒ Object
66 67 68 69 70 71 72 |
# 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) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# 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 ⇒ Object
オブジェクトのメタデータを保存しているファイルの絶対パス
50 51 52 |
# File 'lib/store_agent/node/attachment/metadata.rb', line 50 def file_path "#{base_path}#{StoreAgent.config.}" end |
#owner=(identifier) ⇒ Object
85 86 87 |
# 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) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
89 90 91 92 |
# 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 |