Class: Released::Goals::FileExists
Instance Method Summary
collapse
#assessable?, #effectful?
Constructor Details
#initialize(config) ⇒ FileExists
Returns a new instance of FileExists.
6
7
8
9
|
# File 'lib/released/goals/file_exists.rb', line 6
def initialize(config)
@filename = config.fetch('filename')
@contents = config.fetch('contents')
end
|
Instance Method Details
#achieved? ⇒ Boolean
19
20
21
|
# File 'lib/released/goals/file_exists.rb', line 19
def achieved?
File.file?(@filename) && File.read(@filename) == @contents
end
|
#failure_reason ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/released/goals/file_exists.rb', line 23
def failure_reason
if !File.file?(@filename)
"file `#{@filename}` does not exist"
elsif File.read(@filename) != @contents
"file `#{@filename}` does not have the expected contents"
else
'unknown reason'
end
end
|
#to_s ⇒ Object
11
12
13
|
# File 'lib/released/goals/file_exists.rb', line 11
def to_s
"file exists (#{@filename})"
end
|
#try_achieve ⇒ Object
15
16
17
|
# File 'lib/released/goals/file_exists.rb', line 15
def try_achieve
File.write(@filename, @contents)
end
|