Class: AtCoderFriends::Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/at_coder_friends/verifier.rb

Overview

marks and checks if the source has been verified.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Verifier



9
10
11
12
13
14
# File 'lib/at_coder_friends/verifier.rb', line 9

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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



8
9
10
# File 'lib/at_coder_friends/verifier.rb', line 8

def file
  @file
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/at_coder_friends/verifier.rb', line 8

def path
  @path
end

#vdirObject (readonly)

Returns the value of attribute vdir.



8
9
10
# File 'lib/at_coder_friends/verifier.rb', line 8

def vdir
  @vdir
end

#vpathObject (readonly)

Returns the value of attribute vpath.



8
9
10
# File 'lib/at_coder_friends/verifier.rb', line 8

def vpath
  @vpath
end

Instance Method Details

#unverifyObject



23
24
25
26
27
# File 'lib/at_coder_friends/verifier.rb', line 23

def unverify
  return unless File.exist?(vpath)

  File.delete(vpath)
end

#verified?Boolean



29
30
31
32
33
34
# File 'lib/at_coder_friends/verifier.rb', line 29

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

  true
end

#verifyObject



16
17
18
19
20
21
# File 'lib/at_coder_friends/verifier.rb', line 16

def verify
  return unless File.exist?(path)

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