Module: CleanerUpper

Included in:
Brine
Defined in:
lib/brine/cleaner_upper.rb

Overview

A mixin which provides resource cleanup.

Exposes methods to keep a stack of DeleteCommands corresponding to each created resource which are then popped and invoked to perform the cleanup.

The LIFO behavior is adopted as it is more likely to preserve integrity, such as removing children added to parents or similar dependencies.

Instance Method Summary collapse

Instance Method Details

#cleanup_created_resourcesObject

Clean recorded resources (normally after a test run).



84
85
86
# File 'lib/brine/cleaner_upper.rb', line 84

def cleanup_created_resources
  created_resources.reverse.each{|it| it.cleanup}
end

#set_cleaning_client(client) ⇒ Object

Set the Faraday HTTP client object used to issue DELETE calls.

The client provided will be subsequently used to create DeleteCommands. This can be called multiple times where each DeleteCommand will use the most recently set value. In most use cases this will also be the client used to issue the creation requests and could therefore be passed to this method prior to use.

Parameters:

  • client
    • The client to use to DELETE subsequently tracked resources.



70
71
72
# File 'lib/brine/cleaner_upper.rb', line 70

def set_cleaning_client(client)
  @client = client
end

#track_created_resource(path) ⇒ Object

Record resource to be later cleaned (pushes a DeleteCommand).

Parameters:

  • path
    • The path for the created resource, will be issued a DELETE.



78
79
80
# File 'lib/brine/cleaner_upper.rb', line 78

def track_created_resource(path)
  created_resources << DeleteCommand.new(@client, path)
end