Class: AtCoderFriends::Verifier
- Inherits:
-
Object
- Object
- AtCoderFriends::Verifier
- Includes:
- PathUtil
- Defined in:
- lib/at_coder_friends/verifier.rb
Overview
marks and checks if the source has been verified.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#vdir ⇒ Object
readonly
Returns the value of attribute vdir.
-
#vpath ⇒ Object
readonly
Returns the value of attribute vpath.
Instance Method Summary collapse
-
#initialize(ctx) ⇒ Verifier
constructor
A new instance of Verifier.
- #unverify ⇒ Object
- #verified? ⇒ Boolean
- #verify ⇒ Object
Methods included from PathUtil
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
#file ⇒ Object (readonly)
Returns the value of attribute file.
10 11 12 |
# File 'lib/at_coder_friends/verifier.rb', line 10 def file @file end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/at_coder_friends/verifier.rb', line 10 def path @path end |
#vdir ⇒ Object (readonly)
Returns the value of attribute vdir.
10 11 12 |
# File 'lib/at_coder_friends/verifier.rb', line 10 def vdir @vdir end |
#vpath ⇒ Object (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
#unverify ⇒ Object
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
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 |
#verify ⇒ Object
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 |