Class: Ronin::DB::CLI::ResourcesCommand
- Inherits:
-
ModelCommand
- Object
- Core::CLI::Command
- Command
- DatabaseCommand
- ModelCommand
- Ronin::DB::CLI::ResourcesCommand
- Defined in:
- lib/ronin/db/cli/resources_command.rb
Overview
A base-command class for listing Database Resources.
Constant Summary
Constants included from URIMethods
Instance Attribute Summary
Attributes inherited from ModelCommand
Class Method Summary collapse
-
.model(model = nil) ⇒ Object
Sets the model used by the command.
Instance Method Summary collapse
-
#execute ⇒ Object
Default method performs the query and prints the found resources.
-
#print_resource(resource) ⇒ Object
Default method which will print every queried resource.
-
#print_resources(resources) ⇒ Object
Prints multiple resources.
Methods inherited from ModelCommand
#connect, #initialize, #list, #load_model, #model, model_file, model_name, #print_record, #query, #run
Methods inherited from DatabaseCommand
Methods included from URIMethods
#normalize_adapter, #normalize_sqlite3_path, #parse_uri
Constructor Details
This class inherits a constructor from Ronin::DB::CLI::ModelCommand
Class Method Details
.model(model = nil) ⇒ Object
Sets the model used by the command.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ronin/db/cli/resources_command.rb', line 70 def self.model(model=nil) if (model && model < Model::Importable) option :import, type: String, flag: '-i', usage: 'FILE', description: 'The file to import' end return super(model) end |
Instance Method Details
#execute ⇒ Object
Default method performs the query and prints the found resources.
53 54 55 56 57 58 59 60 61 |
# File 'lib/ronin/db/cli/resources_command.rb', line 53 def execute if @import self.class.model.import(@import) do |resource| print_info "Imported #{resource}" end else print_resources(query) end end |
#print_resource(resource) ⇒ Object
Default method which will print every queried resource.
91 92 93 |
# File 'lib/ronin/db/cli/resources_command.rb', line 91 def print_resource(resource) puts resource end |
#print_resources(resources) ⇒ Object
Prints multiple resources.
105 106 107 108 109 110 111 112 113 |
# File 'lib/ronin/db/cli/resources_command.rb', line 105 def print_resources(resources) if csv? then puts resources.to_csv elsif xml? then puts resources.to_xml elsif yaml? then puts resources.to_yaml elsif json? then puts resources.to_json else resources.each { |resource| print_resource(resource) } end end |