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.
Class Method Summary collapse
-
.included(command) ⇒ Object
private
Adds the
--delete
and--delete-all
options to the command.
Instance Method Summary collapse
-
#delete(value) ⇒ Object
private
Deletes a value from the database.
-
#delete_all ⇒ Object
private
Deletes all values from the database.
-
#run ⇒ Object
private
Runs the command.
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.
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.
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_all ⇒ 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 all values from the database.
79 80 81 |
# File 'lib/ronin/db/cli/deletable.rb', line 79 def delete_all model.destroy_all end |
#run ⇒ 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.
Runs the command.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ronin/db/cli/deletable.rb', line 49 def run if [:delete] db_connect delete([:delete]) elsif [:delete_all] db_connect delete_all else super end end |