Class: DeleteCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/brine/cleaner_upper.rb

Overview

cleaner_upper.rb – clean up resources created during test run

Will issue DELETE call for all tracked URLs which will normally be triggered in a hook.

The present approach for this is to explicitly track created resources to which DELETE calls will be sent. Cleaning up of resources will be given some further attention in the future, but this functionality should be preserved.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, path, oks: [200,204], attempts: 3) ⇒ DeleteCommand

Returns a new instance of DeleteCommand.



12
13
14
15
16
17
18
19
# File 'lib/brine/cleaner_upper.rb', line 12

def initialize(client, path,
               oks:[200,204],
               attempts: 3)
  @client = client
  @path = path
  @oks = oks
  @attempts = attempts
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



10
11
12
# File 'lib/brine/cleaner_upper.rb', line 10

def client
  @client
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/brine/cleaner_upper.rb', line 10

def path
  @path
end

Instance Method Details

#cleanupObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/brine/cleaner_upper.rb', line 21

def cleanup
  while @attempts > 0
    begin
      resp=@client.delete(@path)
      return true if @oks.include?(resp.status)
    rescue ex
      puts "WARNING: #{ex}"
    end
    @attempts -= 1
  end
  puts "ERROR: Could not DELETE #{@path}"
  false
end