class RainforestCli::Deleter

Attributes

remote_tests[R]
test_files[R]

Public Class Methods

new(options) click to toggle source
# File lib/rainforest_cli/deleter.rb, line 7
def initialize(options)
  @file_name = options.file_name
  @test_files = RainforestCli::TestFiles.new(options)
  @remote_tests = RainforestCli::RemoteTests.new(options)
end

Public Instance Methods

delete() click to toggle source
# File lib/rainforest_cli/deleter.rb, line 13
def delete
  validate_file_extension
  delete_remote_test(test_file)
  delete_local_file(test_file.file_name)
  logger.info 'Test successfully deleted.'
end

Private Instance Methods

delete_local_file(path_to_file) click to toggle source
# File lib/rainforest_cli/deleter.rb, line 34
def delete_local_file(path_to_file)
  File.delete(path_to_file)
end
delete_remote_test(rfml_test) click to toggle source
# File lib/rainforest_cli/deleter.rb, line 38
def delete_remote_test(rfml_test)
  Rainforest::Test.delete(primary_key_dictionary[rfml_test.rfml_id])
rescue Exception => e
  logger.fatal "Unable to delete remote rfml test"
  exit 2
end
logger() click to toggle source
# File lib/rainforest_cli/deleter.rb, line 59
def logger
  RainforestCli.logger
end
primary_key_dictionary() click to toggle source
# File lib/rainforest_cli/deleter.rb, line 55
def primary_key_dictionary
  @primary_key_dictionary ||= remote_tests.primary_key_dictionary
end
rfml_extension?() click to toggle source
# File lib/rainforest_cli/deleter.rb, line 29
def rfml_extension?
  extname = File.extname(@file_name)
  RainforestCli::TestFiles::FILE_EXTENSION == extname
end
rfml_tests() click to toggle source
# File lib/rainforest_cli/deleter.rb, line 51
def rfml_tests
  @rfml_tests ||= test_files.test_data
end
test_file() click to toggle source
# File lib/rainforest_cli/deleter.rb, line 45
def test_file
  @test_file ||= rfml_tests.detect do |rfml_test|
    rfml_test.file_name == @file_name
  end
end
validate_file_extension() click to toggle source
# File lib/rainforest_cli/deleter.rb, line 22
def validate_file_extension
  if !rfml_extension?
    logger.fatal "Error: file extension must be .rfml"
    exit 2
  end
end