Sha256: fda54b35c83defdafd275ee4ff2a79edc4d7068e84d546e70d409764ee615199

Contents?: true

Size: 773 Bytes

Versions: 1

Compression:

Stored size: 773 Bytes

Contents

# frozen_string_literal: true

require 'fileutils'

module AtCoderFriends
  # marks and checks if the source has been verified.
  class Verifier
    attr_reader :path, :file, :vdir, :vpath

    def initialize(ctx)
      @path = ctx.path
      @file = File.basename(path)
      @vdir = File.join(File.dirname(path), '.tmp')
      @vpath = File.join(vdir, "#{file}.verified")
    end

    def verify
      return unless File.exist?(path)

      FileUtils.makedirs(vdir) unless Dir.exist?(vdir)
      FileUtils.touch(vpath)
    end

    def unverify
      return unless File.exist?(vpath)

      File.delete(vpath)
    end

    def verified?
      return false unless File.exist?(vpath)
      return false if File.mtime(vpath) < File.mtime(path)

      true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
at_coder_friends-0.5.0 lib/at_coder_friends/verifier.rb