Class: Mexico::FileSystem::LocalFile

Inherits:
Object
  • Object
show all
Extended by:
IdRef, StaticCollectionRef
Includes:
BoundToCorpus, Poseidon, ROXML
Defined in:
lib/mexico/file_system/local_file.rb

Overview

A LocalFile object represents a file on a local file system, with additional information

Instance Attribute Summary

Attributes included from BoundToCorpus

#corpus

Instance Method Summary collapse

Methods included from IdRef

id_ref

Methods included from StaticCollectionRef

collection_ref

Methods included from BoundToCorpus

#bind_to_corpus

Constructor Details

#initialize(opts = {}) ⇒ LocalFile

Creates a new local file object.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :identifier (String)

    The identifier of the new design (required).

  • :name (String)

    The name of the new design. (required).

  • :description (String)

    A description of the new design (optional).



58
59
60
61
62
# File 'lib/mexico/file_system/local_file.rb', line 58

def initialize(opts={})
  [:identifier,:name,:description].each do |att|
    send("#{att}=", opts[att]) if opts.has_key?(att)
  end
end

Instance Method Details

#absolute_pathString

Resolves any relative path given in the path field, and returns an absolute path suited for the current operating system.

Returns:

  • (String)

    a string containing the absolute path to the file.



67
68
69
70
71
72
# File 'lib/mexico/file_system/local_file.rb', line 67

def absolute_path
  if path.starts_with? "."
    return File.expand_path(File.join(@corpus.base_path, path))
  end
  return path
end

#after_parseObject

This method performs additional linking and cleanup after parsing a XML representation.



97
98
99
# File 'lib/mexico/file_system/local_file.rb', line 97

def after_parse
  # puts "Parsed LocalFile"
end

#file_exists?Boolean

Indicates whether the file described at the path actually exists.

Returns:

  • (Boolean)

    true if the described file exists, false otherwise.



76
77
78
79
# File 'lib/mexico/file_system/local_file.rb', line 76

def file_exists?
  return false if path.blank?
  File.exists?(absolute_path)
end

#file_handleFile

Returns a file object for this Mexico::FileSystem::LocalFile object.

Returns:

  • (File)

    a file object for the described file, or nil if there is no readable file at that location.



83
84
85
86
# File 'lib/mexico/file_system/local_file.rb', line 83

def file_handle
  return nil if path.blank?
  return File.open(absolute_path)
end

#file_sizeInteger

Returns the size of the file (in bytes).

Returns:

  • (Integer)

    the size of the file in bytes, or nil if no file can be found.



90
91
92
93
# File 'lib/mexico/file_system/local_file.rb', line 90

def file_size
  return nil if path.blank?
  return File.size(absolute_path)
end