Class: AtCoderFriends::Verifier
- Inherits:
-
Object
- Object
- AtCoderFriends::Verifier
- 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(path) ⇒ Verifier
constructor
A new instance of Verifier.
- #unverify ⇒ Object
- #verified? ⇒ Boolean
- #verify ⇒ Object
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.(path) @file = File.basename(@path) @vdir = File.join(File.dirname(@path), '.tmp') @vpath = File.join(@vdir, "#{@file}.verified") end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/at_coder_friends/verifier.rb', line 8 def file @file end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/at_coder_friends/verifier.rb', line 8 def path @path end |
#vdir ⇒ Object (readonly)
Returns the value of attribute vdir.
8 9 10 |
# File 'lib/at_coder_friends/verifier.rb', line 8 def vdir @vdir end |
#vpath ⇒ Object (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
#unverify ⇒ Object
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 |
#verify ⇒ Object
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 |