Class: StoreAgent::Workspace

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Validator
Defined in:
lib/store_agent/workspace.rb

Overview

ワークスペース

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#initialize(current_user: nil, namespace: nil) ⇒ Workspace

:nodoc:



26
27
28
29
30
31
32
33
# File 'lib/store_agent/workspace.rb', line 26

def initialize(current_user: nil, namespace: nil) # :nodoc:
  @current_user = current_user
  @namespace = namespace
  validates_to_be_not_nil_value!(:current_user)
  validates_to_be_string_or_symbol!(@namespace)
  validates_to_be_excluded_slash!(@namespace)
  @version_manager = StoreAgent.config.version_manager.new(workspace: self)
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



23
24
25
# File 'lib/store_agent/workspace.rb', line 23

def current_user
  @current_user
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



23
24
25
# File 'lib/store_agent/workspace.rb', line 23

def namespace
  @namespace
end

#version_managerObject (readonly)

Returns the value of attribute version_manager.



23
24
25
# File 'lib/store_agent/workspace.rb', line 23

def version_manager
  @version_manager
end

Class Method Details

.name_listObject

全ワークスペース名の一覧を配列で返す



79
80
81
82
83
84
85
86
# File 'lib/store_agent/workspace.rb', line 79

def self.name_list
  if !File.exists?(StoreAgent.config.storage_root)
    FileUtils.mkdir_p(StoreAgent.config.storage_root)
  end
  FileUtils.cd(StoreAgent.config.storage_root) do
    return Dir.glob("*", File::FNM_DOTMATCH) - StoreAgent.reserved_filenames
  end
end

Instance Method Details

#createObject

ワークスペースを新規作成する



36
37
38
39
40
41
42
43
# File 'lib/store_agent/workspace.rb', line 36

def create
  if exists?
    raise InvalidPathError, "workspace #{@namespace} is already exists"
  end
  FileUtils.mkdir_p(namespace_dirname)
  @version_manager.init
  root.create
end

#deleteObject

ワークスペースを削除する



46
47
48
49
50
51
# File 'lib/store_agent/workspace.rb', line 46

def delete
  if !exists?
    raise InvalidPathError, "workspace #{@namespace} not found"
  end
  FileUtils.remove_dir(namespace_dirname)
end

#metadata_dirnameObject

メタデータの保存に使用する領域の絶対パス



69
70
71
# File 'lib/store_agent/workspace.rb', line 69

def 
  File.absolute_path("#{namespace_dirname}/#{StoreAgent.config.}")
end

#namespace_dirnameObject

ワークスペースの絶対パス



59
60
61
# File 'lib/store_agent/workspace.rb', line 59

def namespace_dirname
  File.absolute_path("#{StoreAgent.config.storage_root}/#{@namespace}")
end

#permission_dirnameObject

権限情報の保存に使用する領域の絶対パス



74
75
76
# File 'lib/store_agent/workspace.rb', line 74

def permission_dirname
  File.absolute_path("#{namespace_dirname}/#{StoreAgent.config.permission_dirname}")
end

#rootObject

ワークスペースのファイルツリーの最上位ノード



54
55
56
# File 'lib/store_agent/workspace.rb', line 54

def root
  @root ||= StoreAgent::Node::DirectoryObject.new(workspace: self, path: "/")
end

#storage_dirnameObject

ストレージとして使用する領域の絶対パス



64
65
66
# File 'lib/store_agent/workspace.rb', line 64

def storage_dirname
  File.absolute_path("#{namespace_dirname}/#{StoreAgent.config.storage_dirname}")
end