class Filewatcher::Snapshot::SnapshotFile

Class for one file from snapshot

Attributes

mtime[R]

Public Class Methods

new(filename) click to toggle source
# File lib/filewatcher/snapshot.rb, line 57
def initialize(filename)
  @filename = filename
  self.class.stats.each do |stat|
    time = File.public_send(stat, filename) if File.exist?(filename)
    instance_variable_set :"@#{stat}", time || Time.new(0)
  end
end
populate_stats(stats) click to toggle source
Calls superclass method
# File lib/filewatcher/snapshot.rb, line 38
def populate_stats(stats)
  defined?(super) ? super(stats) : stats
end
populate_subtractions(hash) click to toggle source
Calls superclass method
# File lib/filewatcher/snapshot.rb, line 49
def populate_subtractions(hash)
  hash = super(hash) if defined?(super)
  hash
end
stats() click to toggle source
# File lib/filewatcher/snapshot.rb, line 34
def stats
  @stats ||= populate_stats %i[mtime]
end
subtractions() click to toggle source
# File lib/filewatcher/snapshot.rb, line 42
def subtractions
  @subtractions ||= populate_subtractions(
    created: ->(other) { other.nil? },
    updated: ->(other) { mtime && mtime > other.mtime }
  )
end

Public Instance Methods

-(other) click to toggle source
# File lib/filewatcher/snapshot.rb, line 65
def -(other)
  self.class.subtractions.find do |_event, block|
    instance_exec(other, &block)
  end&.first
end
inspect() click to toggle source
# File lib/filewatcher/snapshot.rb, line 71
      def inspect
        stats_string =
          self.class.stats
            .map { |stat| "#{stat}=#{public_send(stat)&.strftime('%F %T.%9N')&.inspect}" }
            .join(', ')

        <<~OUTPUT
          #<Filewatcher::Snapshot::SnapshotFile:#{object_id}
            @filename=#{@filename.inspect}, #{stats_string}
          >
        OUTPUT
      end