Class: OCFL::StorageRoot

Inherits:
Object
  • Object
show all
Defined in:
lib/ocfl/storage_root.rb

Overview

An OCFL Storage Root is the base directory of an OCFL storage layout. ocfl.io/1.1/spec/#storage-root

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_directory:) ⇒ StorageRoot

Returns a new instance of StorageRoot.



11
12
13
14
# File 'lib/ocfl/storage_root.rb', line 11

def initialize(base_directory:)
  @base_directory = Pathname.new(base_directory)
  @layout = Layouts::DruidTree
end

Instance Attribute Details

#base_directoryObject (readonly)

Returns the value of attribute base_directory.



7
8
9
# File 'lib/ocfl/storage_root.rb', line 7

def base_directory
  @base_directory
end

#layoutObject (readonly)

Returns the value of attribute layout.



7
8
9
# File 'lib/ocfl/storage_root.rb', line 7

def layout
  @layout
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/ocfl/storage_root.rb', line 16

def exists?
  base_directory.directory?
end

#object(identifier, content_directory = nil) ⇒ Object



34
35
36
37
38
# File 'lib/ocfl/storage_root.rb', line 34

def object(identifier, content_directory = nil)
  root = base_directory / path_to(identifier)

  Object.new(identifier:, root:, content_directory:)
end

#saveObject



24
25
26
27
28
29
30
31
32
# File 'lib/ocfl/storage_root.rb', line 24

def save
  # TODO: optionally write the OCFL 1.1 spec
  # TODO: optionally write any given extensions (like the TBD druid-tree layout)
  return if exists? && valid?

  FileUtils.mkdir_p(base_directory)
  FileUtils.touch(namaste_file)
  true
end

#valid?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ocfl/storage_root.rb', line 20

def valid?
  namaste_file.exist?
end