Class: Moab::FileInstance

Inherits:
Serializable
  • Object
show all
Includes:
HappyMapper
Defined in:
lib/moab/file_instance.rb

Overview

Note:

Copyright © 2012 by The Board of Trustees of the Leland Stanford Junior University. All rights reserved. See LICENSE for details.

The file path and last modification date properties of a file

Data Model

  • FileInventory = container for recording information about a collection of related files

    • FileGroup [1..*] = subset allow segregation of content and metadata files

      • FileManifestation [1..*] = snapshot of a file’s filesystem characteristics

        • FileSignature [1] = file fixity information

        • FileInstance [1..*] = filepath and timestamp of any physical file having that signature

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ FileInstance

Returns a new instance of FileInstance.



24
25
26
# File 'lib/moab/file_instance.rb', line 24

def initialize(opts={})
  super(opts)
end

Instance Attribute Details

#datetimeTime

Returns gsub(/n/,‘ ’).

Returns:

  • (Time)

    gsub(/n/,‘ ’)



34
# File 'lib/moab/file_instance.rb', line 34

attribute :datetime, Time, :on_save => Proc.new {|t| t.to_s}

#pathString

Returns The id is the filename path, relative to the file group’s base directory.

Returns:

  • (String)

    The id is the filename path, relative to the file group’s base directory



30
# File 'lib/moab/file_instance.rb', line 30

attribute :path, String, :key => true

Instance Method Details

#==(other) ⇒ Object

(see #eql?)



64
65
66
# File 'lib/moab/file_instance.rb', line 64

def ==(other)
  eql?(other)
end

#eql?(other) ⇒ Boolean

Returns true if self and other have the same path.

Parameters:

  • other (FileInstance)

    The other file instance being compared to this instance

Returns:

  • (Boolean)

    Returns true if self and other have the same path.



58
59
60
# File 'lib/moab/file_instance.rb', line 58

def eql?(other)
  self.path == other.path
end

#hashFixnum

Note:

The hash and eql? methods override the methods inherited from Object. These methods ensure that instances of this class can be used as Hash keys. See

Also overriden is #== so that equality tests in other contexts will also return the expected result.

Two file instances with the same relative path will have the same hash code (and will compare using eql?).

Returns:

  • (Fixnum)

    Compute a hash-code for the path string.



76
77
78
# File 'lib/moab/file_instance.rb', line 76

def hash
  path.hash
end

#instance_from_file(pathname, base_directory) ⇒ FileInstance

Returns a file instance containing a physical file’s’ properties

Parameters:

  • pathname (Pathname)

    The location of the physical file

  • base_directory (Pathname)

    The full path used as the basis of the relative paths reported

Returns:

  • (FileInstance)

    Returns a file instance containing a physical file’s’ properties



49
50
51
52
53
# File 'lib/moab/file_instance.rb', line 49

def instance_from_file(pathname, base_directory)
  @path = pathname.expand_path.relative_path_from(base_directory.expand_path).to_s
  @datetime = pathname.mtime.iso8601
  self
end