Module: Brine::CleaningUp

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

Overview

Provide resource cleanup.

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

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

Defined Under Namespace

Classes: DeleteCommand

Instance Method Summary collapse

Instance Method Details

#cleanup_created_resourcesBoolean

Clean recorded resources (normally after a test run).

Returns:

  • (Boolean)

    Return true if all commands succeeded successfully, otherwise false.



96
97
98
99
# File 'lib/brine/cleaning_up.rb', line 96

def cleanup_created_resources
  # Avoid the use of any short circuiting folds.
  cleanup_commands.reverse.inject(true) { |accum, x| accum && x.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 (Faraday::Connection, #delete)

    Provide the client to DELETE subsequently tracked resources.



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

def set_cleaning_client(client)
  @client = client
end

#track_created_resource(path) ⇒ Object

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

Parameters:

  • path (String)

    Specify the path for the created resource: will be issued a DELETE.



87
88
89
# File 'lib/brine/cleaning_up.rb', line 87

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