Module: Ronin::DB::CLI::Deletable Private

Defined in:
lib/ronin/db/cli/deletable.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Allows a ModelCommand to delete a single record or all records.

Since:

  • 0.2.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds the --delete and --delete-all options to the command.

Parameters:

Since:

  • 0.2.0



36
37
38
39
40
41
42
43
44
# File 'lib/ronin/db/cli/deletable.rb', line 36

def self.included(command)
  command.option :delete, value: {
                            type: String,
                            usage: 'VALUE'
                          },
                          desc: 'Deletes a value from the database'

  command.option :delete_all, desc: 'Deletes all values from the database'
end

Instance Method Details

#delete(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deletes a value from the database.

Parameters:

  • value (String)

    The value to lookup and delete.

Since:

  • 0.2.0



67
68
69
70
71
72
73
74
# File 'lib/ronin/db/cli/deletable.rb', line 67

def delete(value)
  if (record = model.lookup(value))
    record.destroy
  else
    print_error "value does not exist in the database: #{value}"
    exit(-1)
  end
end

#delete_allObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deletes all values from the database.

Since:

  • 0.2.0



79
80
81
# File 'lib/ronin/db/cli/deletable.rb', line 79

def delete_all
  model.destroy_all
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the command.

Since:

  • 0.2.0



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ronin/db/cli/deletable.rb', line 49

def run
  if options[:delete]
    db_connect
    delete(options[:delete])
  elsif options[:delete_all]
    db_connect
    delete_all
  else
    super
  end
end