class StoreAgent::Node::Object

ファイルやディレクトリなど、オブジェクトの雛形となるクラス
実際にはファイルやディレクトリなど、このクラスを継承したクラスを使用する

Attributes

path[R]
workspace[R]

Public Instance Methods

chown(*, identifier: nil, **_) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 127
def chown(*, identifier: nil, **_)
  workspace.version_manager.transaction("change_owner #{path}") do
    yield
    metadata.owner = identifier
    metadata.save
  end
end
copy(dest_path = nil) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 105
def copy(dest_path = nil)
  workspace.version_manager.transaction("copy #{path} to #{dest_path}") do
    yield
  end
end
create(*) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 66
def create(*)
  workspace.version_manager.transaction("created #{path}") do
    yield
    metadata.create
    permission.create
  end
  self
end
delete(*) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 86
def delete(*)
  workspace.version_manager.transaction("deleted #{path}") do
    yield
    metadata.delete
    permission.delete
  end
  true
end
directory?() click to toggle source

true を返す場合、ディレクトリとして認識される

# File lib/store_agent/node/object.rb, line 194
def directory?
  false
end
exists?() click to toggle source

オブジェクトが存在するなら true を返す

# File lib/store_agent/node/object.rb, line 162
def exists?
  File.exists?(storage_object_path)
end
file?() click to toggle source

true を返す場合、ファイルとして認識される

# File lib/store_agent/node/object.rb, line 199
def file?
  false
end
filetype() click to toggle source

ファイルの種類。file、directory など

# File lib/store_agent/node/object.rb, line 167
def filetype
  File.ftype(storage_object_path)
end
metadata() click to toggle source

オブジェクトに紐づくメタデータのインスタンス

# File lib/store_agent/node/object.rb, line 39
def metadata
  @metadata ||= StoreAgent::Node::Metadata.new(object: self)
end
move(dest_path = nil) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 111
def move(dest_path = nil)
  workspace.version_manager.transaction("move #{path} to #{dest_path}") do
    yield
  end
end
parent_directory() click to toggle source

親階層のディレクトリオブジェクトを返す

# File lib/store_agent/node/object.rb, line 150
def parent_directory
  if !root?
    @parent_directory ||= StoreAgent::Node::DirectoryObject.new(workspace: @workspace, path: File.dirname(@path))
  end
end
permission() click to toggle source

オブジェクトに紐づく権限情報のインスタンス

# File lib/store_agent/node/object.rb, line 44
def permission
  @permission ||= StoreAgent::Node::Permission.new(object: self)
end
read(*) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 75
def read(*)
  yield
end
revisions() click to toggle source

バージョン管理をしている場合、変更があったリビジョンの一覧を返す

# File lib/store_agent/node/object.rb, line 157
def revisions
  workspace.version_manager.revisions("storage#{path}")
end
root?() click to toggle source

true を返す場合、ファイルツリーの最上位ディレクトリとして認識される

# File lib/store_agent/node/object.rb, line 189
def root?
  @path == "/"
end
set_permission(identifier: nil, permission_values: {}, **_) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 135
def set_permission(identifier: nil, permission_values: {}, **_)
  workspace.version_manager.transaction("add_permission #{path}") do
    permission.set!(identifier: identifier, permission_values: permission_values)
    yield
  end
end
storage_object_path() click to toggle source

オブジェクトの絶対パス

# File lib/store_agent/node/object.rb, line 204
def storage_object_path
  "#{@workspace.storage_dirname}#{@path}"
end
touch(*) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 95
def touch(*)
  workspace.version_manager.transaction("touch #{path}") do
    metadata.reload
    yield
    metadata.updated_at = Time.now
    metadata.save
    workspace.version_manager.add(permission.file_path)
  end
end
unset_permission(identifier: nil, permission_names: [], **_) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 142
def unset_permission(identifier: nil, permission_names: [], **_)
  workspace.version_manager.transaction("remove_permission #{path}") do
    permission.unset!(identifier: identifier, permission_names: permission_names)
    yield
  end
end
update(*) { || ... } click to toggle source
# File lib/store_agent/node/object.rb, line 79
def update(*)
  workspace.version_manager.transaction("updated #{path}") do
    yield
  end
  true
end

Private Instance Methods

initial_bytesize() click to toggle source
# File lib/store_agent/node/object.rb, line 218
def initial_bytesize
  0
end
owner?() click to toggle source
# File lib/store_agent/node/object.rb, line 214
def owner?
  metadata["owner"] == current_user.identifier
end
sanitize_path(path) click to toggle source
# File lib/store_agent/node/object.rb, line 210
def sanitize_path(path)
  File.absolute_path("/./#{path}")
end
updated_at() click to toggle source
# File lib/store_agent/node/object.rb, line 222
def updated_at
  File.mtime(storage_object_path)
end