Class: Moab::FileInstance

Inherits:
Serializer::Serializable 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

Methods inherited from Serializer::Serializable

#array_to_hash, deep_diff, #diff, #key, #key_name, #summary, #to_hash, #to_json, #to_yaml, #variable_names, #variables

Constructor Details

#initialize(opts = {}) ⇒ FileInstance

Returns a new instance of FileInstance.



22
23
24
# File 'lib/moab/file_instance.rb', line 22

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

Instance Attribute Details

#datetimeString

Returns gsub(/n/,‘ ’).

Returns:

  • (String)

    gsub(/n/,‘ ’)



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

attribute :datetime, String

#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



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

attribute :path, String, :key => true

Instance Method Details

#==(other) ⇒ Object

(see #eql?)



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

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.



55
56
57
58
59
# File 'lib/moab/file_instance.rb', line 55

def eql?(other)
  return false unless other.respond_to?(:path) # Cannot equal an incomparable type!

  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.



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

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



46
47
48
49
50
# File 'lib/moab/file_instance.rb', line 46

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