Module: Wpxf::Cli::Loot
- Included in:
- Console
- Defined in:
- lib/wpxf/cli/loot.rb
Overview
A mixin to provide functions to interact with loot stored in the database.
Instance Method Summary collapse
- #build_loot_table ⇒ Object
- #delete_loot(id) ⇒ Object
- #find_loot_item(id) ⇒ Object
- #home_directory ⇒ Object
- #list_loot ⇒ Object
- #loot(*args) ⇒ Object
- #print_loot_item(id) ⇒ Object
Instance Method Details
#build_loot_table ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wpxf/cli/loot.rb', line 11 def build_loot_table rows = [] rows.push( id: 'ID', host: 'Host', filename: 'Filename', notes: 'Notes', type: 'Type' ) Wpxf::Models::LootItem.where(workspace: active_workspace).each do |item| rows.push( id: item.id, host: "#{item.host}:#{item.port}", filename: File.basename(item.path), notes: item.notes, type: item.type ) end rows end |
#delete_loot(id) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/wpxf/cli/loot.rb', line 51 def delete_loot(id) item = find_loot_item(id) return if item.nil? item.destroy print_good "Deleted item #{id}" end |
#find_loot_item(id) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/wpxf/cli/loot.rb', line 41 def find_loot_item(id) item = Wpxf::Models::LootItem.first( id: id.to_i, workspace: active_workspace ) return item unless item.nil? print_bad "Could not find loot item #{id} in the current workspace" end |
#home_directory ⇒ Object
7 8 9 |
# File 'lib/wpxf/cli/loot.rb', line 7 def home_directory File.join(Dir.home, '.wpxf') end |
#list_loot ⇒ Object
34 35 36 37 38 39 |
# File 'lib/wpxf/cli/loot.rb', line 34 def list_loot rows = build_loot_table print_table rows puts print_std "All filenames are relative to #{File.join(home_directory, 'loot')}".yellow end |
#loot(*args) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wpxf/cli/loot.rb', line 67 def loot(*args) return list_loot if args.length.zero? case args[0] when '-d' delete_loot(args[1]) when '-p' print_loot_item(args[1]) else print_warning 'Invalid option for "loot"' end end |
#print_loot_item(id) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/wpxf/cli/loot.rb', line 59 def print_loot_item(id) item = find_loot_item(id) return if item.nil? content = File.read(item.path) puts content end |