class RaptorIO::Protocol::HTTP::Request::Manipulator

Base manipulator class, all manipulator components should inherit from it.

@author Tasos Laskos <tasos_laskos@rapid7.com> @abstract

Attributes

client[R]

@return [HTTP::Client] Current HTTP client instance.

options[R]

@return [Hash] Manipulator options.

request[R]

@return [HTTP::Request] Request to manipulate.

Public Class Methods

inherited( manipulator_klass ) click to toggle source

Registers manipulators which inherit from this class.

@see Request::Manipulators#register

# File lib/raptor-io/protocol/http/request/manipulator.rb, line 106
def inherited( manipulator_klass )
  Request::Manipulators.register(
      Request::Manipulators.path_to_name( caller.first.split( ':' ).first ),
      manipulator_klass
  )
end
new( client, request, options = {} ) click to toggle source

@param [HTTP::Client] client

HTTP client which will handle the request.

@param [HTTP::Request] request

Request to process.
# File lib/raptor-io/protocol/http/request/manipulator.rb, line 42
def initialize( client, request, options = {} )
  @client  = client
  @request = request
  @options = options
end
shortname() click to toggle source

@return [String] Shortname of ‘self`.

# File lib/raptor-io/protocol/http/request/manipulator.rb, line 99
def shortname
  @shortname ||= Request::Manipulators.class_to_name( self )
end
validate_options( &block ) click to toggle source

@return [Hash{Symbol=>Array<String>}]

Option names keys for and error messages for values.
# File lib/raptor-io/protocol/http/request/manipulator.rb, line 81
def validate_options( &block )
  fail ArgumentError, 'Missing block.' if !block_given?
  @validator = block
end
validate_options!( options, client ) click to toggle source

@param [Hash] options Manipulator options. @param [HTTP::Client] client Applicable client.

@return [Hash{Symbol=>Array<String>}]

Option names keys for and error messages for values.

@abstract

# File lib/raptor-io/protocol/http/request/manipulator.rb, line 94
def validate_options!( options, client )
  @validator ? @validator.call( options, client ) : {}
end

Public Instance Methods

datastore() click to toggle source

@return [Hash] Persistent storage – per {HTTP::Client} instance.

# File lib/raptor-io/protocol/http/request/manipulator.rb, line 62
def datastore
  client.datastore[shortname]
end
delegate( manipulator, opts = options ) click to toggle source

Delegates the work to another manipulator.

@param [Symbol] manipulator Manipulator to run. @param [Hash] opts Manipulator options.

# File lib/raptor-io/protocol/http/request/manipulator.rb, line 57
def delegate( manipulator, opts = options )
  Request::Manipulators.process( manipulator, client, request, opts )
end
run() click to toggle source

Delivers the manipulator’s payload. @abstract

# File lib/raptor-io/protocol/http/request/manipulator.rb, line 50
def run
end
shortname() click to toggle source

@return [String] Shortname of ‘self`.

# File lib/raptor-io/protocol/http/request/manipulator.rb, line 67
def shortname
  self.class.shortname
end
validate_options() click to toggle source

@return [Hash{Symbol=>Array<String>}]

Option names keys for and error messages for values.
# File lib/raptor-io/protocol/http/request/manipulator.rb, line 73
def validate_options
  self.class.validate_options!( options, client )
end