Class: Released::Goals::FileExists

Inherits:
Released::Goal show all
Defined in:
lib/released/goals/file_exists.rb

Instance Method Summary collapse

Methods inherited from Released::Goal

#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

Returns:

  • (Boolean)


19
20
21
# File 'lib/released/goals/file_exists.rb', line 19

def achieved?
  File.file?(@filename) && File.read(@filename) == @contents
end

#failure_reasonObject



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_sObject



11
12
13
# File 'lib/released/goals/file_exists.rb', line 11

def to_s
  "file exists (#{@filename})"
end

#try_achieveObject



15
16
17
# File 'lib/released/goals/file_exists.rb', line 15

def try_achieve
  File.write(@filename, @contents)
end