Class: Longleaf::FileRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/longleaf/models/file_record.rb

Overview

Record for an individual file and its associated information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, storage_location, metadata_record = nil, physical_path = nil) ⇒ FileRecord

Returns a new instance of FileRecord.

Parameters:

  • file_path (String)

    path to the file

  • storage_location (StorageLocation)

    storage location containing the file

  • metadata_record (MetadataRecord) (defaults to: nil)

    metadata record for this file object. Optional.

  • physical_path (String) (defaults to: nil)

    physical path where the file is located. Defaults to the file_path.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
# File 'lib/longleaf/models/file_record.rb', line 12

def initialize(file_path, storage_location,  = nil, physical_path = nil)
  raise ArgumentError.new("FileRecord requires a path") if file_path.nil?
  raise ArgumentError.new("FileRecord requires a storage_location") if storage_location.nil?

  @path = file_path
  @storage_location = storage_location
  @metadata_record = 
  @physical_path = physical_path
end

Instance Attribute Details

#metadata_recordObject

Returns the value of attribute metadata_record.



4
5
6
# File 'lib/longleaf/models/file_record.rb', line 4

def 
  @metadata_record
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/longleaf/models/file_record.rb', line 6

def path
  @path
end

#storage_locationObject (readonly)

Returns the value of attribute storage_location.



5
6
7
# File 'lib/longleaf/models/file_record.rb', line 5

def storage_location
  @storage_location
end

Instance Method Details

#==(other_obj) ⇒ Object



43
44
45
46
# File 'lib/longleaf/models/file_record.rb', line 43

def ==(other_obj)
  return false unless other_obj.is_a?(FileRecord)
  path == other_obj.path
end

#metadata_pathString

Returns path for the metadata file for this file.

Returns:

  • (String)

    path for the metadata file for this file



23
24
25
26
# File 'lib/longleaf/models/file_record.rb', line 23

def 
  @metadata_path = @storage_location.(path) if @metadata_path.nil?
  @metadata_path
end

#metadata_present?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/longleaf/models/file_record.rb', line 39

def 
  File.exist?()
end

#physical_pathObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/longleaf/models/file_record.rb', line 28

def physical_path
  if @physical_path.nil?
    if @metadata_record.nil? || @metadata_record.physical_path.nil?
      @physical_path = @path
    else
      @physical_path = @metadata_record.physical_path
    end
  end
  @physical_path
end