Class: Arachni::RPC::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/arachni/rpc/message.rb

Overview

Represents an RPC message, serves as the basis for Request and Response.

Author:

Direct Known Subclasses

Request, Response

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Message

Returns a new instance of Message.

Parameters:

  • opts (Hash) (defaults to: {})

    Sets instance attributes.



19
20
21
# File 'lib/arachni/rpc/message.rb', line 19

def initialize( opts = {} )
    opts.each_pair { |k, v| send( "#{k}=".to_sym, v ) }
end

Instance Method Details

#merge!(message) ⇒ Object

Merges the attributes of another message with self.

(The param doesn’t really have to be a message, any object will do.)

Parameters:



28
29
30
31
32
33
# File 'lib/arachni/rpc/message.rb', line 28

def merge!( message )
    message.instance_variables.each do |var|
        val = message.instance_variable_get( var )
        instance_variable_set( var, val )
    end
end

#prepare_for_txHash

Prepares the message for transmission (i.e. converts the message to a ‘Hash`).

Attributes that should not be included can be skipped by implementing #transmit? and returning the appropriate value.

Returns:

  • (Hash)


41
42
43
44
45
46
# File 'lib/arachni/rpc/message.rb', line 41

def prepare_for_tx
    instance_variables.inject({}) do |h, k|
        h[normalize( k )] = instance_variable_get( k ) if transmit?( k )
        h
    end
end

#transmit?(attr) ⇒ Boolean

Decides which attributes should be skipped by #prepare_for_tx.

Parameters:

  • attr (Symbol)

    Instance variable symbol (i.e. ‘:@token`).

Returns:

  • (Boolean)


52
53
54
# File 'lib/arachni/rpc/message.rb', line 52

def transmit?( attr )
    true
end