class Moab::FileInstance

The file path and last modification date properties of a file

Data Model

@note Copyright © 2012 by The Board of Trustees of the Leland Stanford Junior University.

All rights reserved.  See {file:LICENSE.rdoc} for details.

Public Class Methods

new(opts = {}) click to toggle source

(see Serializable#initialize)

Calls superclass method Serializer::Serializable::new
# File lib/moab/file_instance.rb, line 22
def initialize(opts = {})
  super(opts)
end

Public Instance Methods

==(other) click to toggle source

@api internal (see eql?)

# File lib/moab/file_instance.rb, line 63
def ==(other)
  eql?(other)
end
datetime() click to toggle source
# File lib/moab/file_instance.rb, line 38
def datetime
  Moab::UtcTime.output(@datetime)
end
datetime=(event_datetime) click to toggle source
# File lib/moab/file_instance.rb, line 34
def datetime=(event_datetime)
  @datetime = Moab::UtcTime.input(event_datetime)
end
eql?(other) click to toggle source

@api internal @param other [FileInstance] The other file instance being compared to this instance @return [Boolean] Returns true if self and other have the same path.

# 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
hash() click to toggle source

@api internal @return [Fixnum] Compute a hash-code for the path string. Two file instances with the same relative path will have the same hash code (and will compare using eql?). @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
* {http://www.paulbutcher.com/2007/10/navigating-the-equality-maze/}
* {http://techbot.me/2011/05/ruby-basics-equality-operators-ruby/}
Also overriden is {#==} so that equality tests in other contexts will also return the expected result.
# File lib/moab/file_instance.rb, line 75
def hash
  path.hash
end
instance_from_file(pathname, base_directory) click to toggle source

@api internal @param pathname [Pathname] The location of the physical file @param base_directory [Pathname] The full path used as the basis of the relative paths reported @return [FileInstance] Returns a file instance containing a physical file’s’ properties

# 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