class VirtFS::Stat
File Stat
, contains attributes common to files on all files systems
Constants
- ATTR_ACCESSORS
Specified File Attributes supported by
VirtFS
(auto converted to symbols)
Public Class Methods
iv_name(name)
click to toggle source
Helper to convert attribute name to instance variable name
@param name [String] string name @return [String] string instance variable name
# File lib/virtfs/stat.rb, line 55 def self.iv_name(name) name = name.to_s.chomp('?') if name.to_s.end_with?('?') "@#{name}" end
new(obj)
click to toggle source
Attribute intializer, accepts Stat
or Hash containing attributes
@param obj [Stat,Hash] instance of object containing stat info to initialize
# File lib/virtfs/stat.rb, line 65 def initialize(obj) if obj.is_a?(VfsRealFile::Stat) stat_init(obj) else hash_init(obj) end end
Public Instance Methods
<=>(other)
click to toggle source
Sort file stats by modify time
# File lib/virtfs/stat.rb, line 74 def <=>(other) return -1 if mtime < other.mtime return 1 if mtime > other.mtime 0 end
Private Instance Methods
hash_init(obj)
click to toggle source
# File lib/virtfs/stat.rb, line 89 def hash_init(obj) ATTR_ACCESSORS.each do |aa| next unless obj.key?(aa) instance_variable_set(iv_name(aa), obj[aa]) end end
iv_name(name)
click to toggle source
# File lib/virtfs/stat.rb, line 96 def iv_name(name) self.class.iv_name(name) end
stat_init(obj)
click to toggle source
# File lib/virtfs/stat.rb, line 82 def stat_init(obj) ATTR_ACCESSORS.each do |aa| next unless obj.respond_to?(aa) instance_variable_set(iv_name(aa), obj.send(aa)) end end