Class: AtCoderFriends::Verifier

Inherits:
Object
  • Object
show all
Includes:
PathUtil
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

Methods included from PathUtil

#makedirs_unless

Constructor Details

#initialize(ctx) ⇒ Verifier

Returns a new instance of Verifier.



12
13
14
15
16
# File 'lib/at_coder_friends/verifier.rb', line 12

def initialize(ctx)
  @path, _dir, @file = ctx.path_info.components
  @vdir = ctx.path_info.tmp_dir
  @vpath = File.join(vdir, "#{file}.verified")
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#vdirObject (readonly)

Returns the value of attribute vdir.



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

def vdir
  @vdir
end

#vpathObject (readonly)

Returns the value of attribute vpath.



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

def vpath
  @vpath
end

Instance Method Details

#unverifyObject



25
26
27
28
29
# File 'lib/at_coder_friends/verifier.rb', line 25

def unverify
  return unless File.exist?(vpath)

  File.delete(vpath)
end

#verified?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'lib/at_coder_friends/verifier.rb', line 31

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

  true
end

#verifyObject



18
19
20
21
22
23
# File 'lib/at_coder_friends/verifier.rb', line 18

def verify
  return unless File.exist?(path)

  makedirs_unless(vdir)
  FileUtils.touch(vpath)
end