Class: Moab::FileInstance
- Inherits:
-
Serializer::Serializable
- Object
- Serializer::Serializable
- Moab::FileInstance
- Includes:
- HappyMapper
- Defined in:
- lib/moab/file_instance.rb
Overview
Copyright (c) 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
- FileManifestation [1..*] = snapshot of a file's filesystem characteristics
- FileGroup [1..*] = subset allow segregation of content and metadata files
Instance Attribute Summary collapse
-
#datetime ⇒ String
Gsub(/\n/,' ').
-
#path ⇒ String
The id is the filename path, relative to the file group's base directory.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(see #eql?).
-
#eql?(other) ⇒ Boolean
Returns true if self and other have the same path.
-
#hash ⇒ Fixnum
Two file instances with the same relative path will have the same hash code (and will compare using eql?).
-
#initialize(opts = {}) ⇒ FileInstance
constructor
A new instance of FileInstance.
-
#instance_from_file(pathname, base_directory) ⇒ FileInstance
Returns a file instance containing a physical file's' properties.
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
#datetime ⇒ String
Returns gsub(/\n/,' ').
32 |
# File 'lib/moab/file_instance.rb', line 32 attribute :datetime, String |
#path ⇒ String
Returns 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.
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 |
#hash ⇒ Fixnum
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.
Two file instances with the same relative path will have the same hash code (and will compare using eql?).
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
46 47 48 49 50 |
# File 'lib/moab/file_instance.rb', line 46 def instance_from_file(pathname, base_directory) @path = pathname..relative_path_from(base_directory.).to_s @datetime = pathname.mtime.iso8601 self end |