Class: Cohere::Transcribe::State::DirectoryBinding

Inherits:
Data
  • Object
show all
Defined in:
lib/cohere/transcribe/state/io.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_pathObject (readonly)

Returns the value of attribute access_path

Returns:

  • (Object)

    the current value of access_path



20
21
22
# File 'lib/cohere/transcribe/state/io.rb', line 20

def access_path
  @access_path
end

#canonical_pathObject (readonly)

Returns the value of attribute canonical_path

Returns:

  • (Object)

    the current value of canonical_path



20
21
22
# File 'lib/cohere/transcribe/state/io.rb', line 20

def canonical_path
  @canonical_path
end

#deviceObject (readonly)

Returns the value of attribute device

Returns:

  • (Object)

    the current value of device



20
21
22
# File 'lib/cohere/transcribe/state/io.rb', line 20

def device
  @device
end

#inodeObject (readonly)

Returns the value of attribute inode

Returns:

  • (Object)

    the current value of inode



20
21
22
# File 'lib/cohere/transcribe/state/io.rb', line 20

def inode
  @inode
end

Class Method Details

.capture(path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cohere/transcribe/state/io.rb', line 26

def self.capture(path)
  access_path = Pathname(path).expand_path.cleanpath
  canonical_path = access_path.realpath
  stat = canonical_path.lstat
  unless stat.directory? && !stat.symlink?
    raise TranscriptionRuntimeError, "Publication parent is not a real directory: #{access_path}"
  end

  new(
    access_path: access_path.freeze,
    canonical_path: canonical_path.freeze,
    device: stat.dev,
    inode: stat.ino
  )
rescue SystemCallError, ArgumentError => e
  raise TranscriptionRuntimeError,
        "Cannot bind publication parent #{path}: #{e.message}"
end

Instance Method Details

#verify!Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cohere/transcribe/state/io.rb', line 45

def verify!
  resolved = access_path.realpath
  stat = canonical_path.lstat
  valid = resolved == canonical_path && stat.directory? && !stat.symlink? &&
          stat.dev == device && stat.ino == inode
  return self if valid

  raise TranscriptionRuntimeError,
        "Publication parent changed after planning: #{access_path}"
rescue SystemCallError, ArgumentError => e
  raise TranscriptionRuntimeError,
        "Publication parent changed after planning: #{access_path} (#{e.message})"
end