Sha256: 0d8623d0d25d0c0aabdb58b1f954810f21ad12e4f364286900ef892bec65c29a

Contents?: true

Size: 791 Bytes

Versions: 1

Compression:

Stored size: 791 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(path)
      @path = File.expand_path(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.4.0 lib/at_coder_friends/verifier.rb