Class: GodOfWar::Payloads

Inherits:
Object
  • Object
show all
Defined in:
lib/godofwar/payloads.rb

Overview

All war internal operations

Defined Under Namespace

Classes: Payload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePayloads

Returns a new instance of Payloads.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/godofwar/payloads.rb', line 26

def initialize
  @payloads_home =
      File.absolute_path(
          File.join('..', '..', '..', 'payloads'), __FILE__
      )
  @payloads_db   =
      JSON.parse(
          File.read(
              File.absolute_path(
                  File.join(@payloads_home, 'payloads_info.json')
              )
          )
      )
end

Instance Attribute Details

#[Array] payloads([Array]) ⇒ Object (readonly)

array of available payloads



21
# File 'lib/godofwar/payloads.rb', line 21

attr_reader :payloads_home, :payloads_db, :payloads, :info

#[Hash] info([Hash]) ⇒ Object (readonly)

of information of the current payload



21
# File 'lib/godofwar/payloads.rb', line 21

attr_reader :payloads_home, :payloads_db, :payloads, :info

#[Hash] payloads_db([Hash]) ⇒ Object (readonly)

parsed content of ‘payloads_info.json’ which full information about available payloads



21
# File 'lib/godofwar/payloads.rb', line 21

attr_reader :payloads_home, :payloads_db, :payloads, :info

#[String] payloads_home([String]) ⇒ Object (readonly)

full path of the payloads home



21
# File 'lib/godofwar/payloads.rb', line 21

attr_reader :payloads_home, :payloads_db, :payloads, :info

#infoObject (readonly)

Returns the value of attribute info.



21
22
23
# File 'lib/godofwar/payloads.rb', line 21

def info
  @info
end

#payloadObject

Returns the value of attribute payload.



24
25
26
# File 'lib/godofwar/payloads.rb', line 24

def payload
  @payload
end

#payload [String]([String]) ⇒ Object

the current payload name



24
# File 'lib/godofwar/payloads.rb', line 24

attr_accessor :payload

#payloadsObject (readonly)

Returns the value of attribute payloads.



21
22
23
# File 'lib/godofwar/payloads.rb', line 21

def payloads
  @payloads
end

#payloads_dbObject (readonly)

Returns the value of attribute payloads_db.



21
22
23
# File 'lib/godofwar/payloads.rb', line 21

def payloads_db
  @payloads_db
end

#payloads_homeObject (readonly)

Returns the value of attribute payloads_home.



21
22
23
# File 'lib/godofwar/payloads.rb', line 21

def payloads_home
  @payloads_home
end

Instance Method Details

#find_payload(payload) ⇒ Payload

Finds the payload from @payloads_db

Parameters:

  • payload (String)

    payload name

Returns:



63
64
65
# File 'lib/godofwar/payloads.rb', line 63

def find_payload(payload)
  payloads_parse.find{|pay| pay.name == payload}
end

#list_treeArray

list_tree List all available payloads using folder name conversion

Returns:

  • (Array)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/godofwar/payloads.rb', line 72

def list_tree
  payloads_parse.map do |payload|
    if payload.conf.empty?
      payload.conf = 'No Settings required!'
    else
      payload.conf
    end

    "├── " + "#{payload.name}\n".bold            +
    "│   └── Information:\n"                     +
    "│       ├── Description: #{payload.desc}\n" +
    "│       ├── OS:          #{payload.os}\n"   +
    "│       ├── Settings:    #{payload.conf}\n" +
    "│       ├── Usage:       #{payload.url}\n"  +
    "│       ├── References:  #{payload.ref}\n"  +
    "│       └── Local Path:  #{payload.path}"
  end
end

#payloads_parseArray<Payload>

payloads_parse lists all payloads as [Payload] objects

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/godofwar/payloads.rb', line 44

def payloads_parse
  @payloads_db.map do |payload, info|
    name = payload
    desc = info["desc"]
    os   = info["os"]
    conf = info["conf"]
    url  = info["url"]
    ref  = info["ref"]
    path = File.absolute_path(File.join(@payloads_home, payload))
    Payload.new(name, desc, os, conf, url, ref, path)
  end
end