Sha256: 505cb84d74963d85884856363c10e53942ab3b0ef6f7c5ee6516de489a4bb6aa

Contents?: true

Size: 788 Bytes

Versions: 3

Compression:

Stored size: 788 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

3 entries across 3 versions & 1 rubygems

Version Path
at_coder_friends-0.3.3 lib/at_coder_friends/verifier.rb
at_coder_friends-0.3.2 lib/at_coder_friends/verifier.rb
at_coder_friends-0.3.1 lib/at_coder_friends/verifier.rb