Module: Machinery::ScopeFileAccessFlat

Defined in:
lib/scope_file_access_flat.rb

Instance Method Summary collapse

Instance Method Details

#binary?(system_file) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/scope_file_access_flat.rb', line 29

def binary?(system_file)
  path = system_file.scope.file_path(system_file)
  return false if File.zero?(path)

  Machinery.content_is_binary?(File.read(path, 4096))
end

#file_content(system_file) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/scope_file_access_flat.rb', line 20

def file_content(system_file)
  unless extracted
    raise Machinery::Errors::FileUtilsError, "The requested file '#{system_file.name}' is" \
      " not available because files for scope '#{scope_name}' were not extracted."
  end

  File.read(file_path(system_file))
end

#file_path(system_file) ⇒ Object



14
15
16
17
18
# File 'lib/scope_file_access_flat.rb', line 14

def file_path(system_file)
  raise Machinery::Errors::FileUtilsError, "Not a file" unless system_file.file?

  File.join(scope_file_store.path, system_file.name)
end

#has_file?(name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/scope_file_access_flat.rb', line 36

def has_file?(name)
  return true if any? { |file| file.name == name }
end

#retrieve_files_from_system(system, paths) ⇒ Object



2
3
4
# File 'lib/scope_file_access_flat.rb', line 2

def retrieve_files_from_system(system, paths)
  system.retrieve_files(paths, scope_file_store.path)
end

#write_file(system_file, target) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/scope_file_access_flat.rb', line 6

def write_file(system_file, target)
  raise Machinery::Errors::FileUtilsError, "Not a file" unless system_file.file?

  target_path = File.join(target, system_file.name)
  FileUtils.mkdir_p(File.dirname(target_path))
  FileUtils.cp(file_path(system_file), target_path)
end