Sha256: 32d87409ce0094abeb83a1cca2f8a9613eb3bc1ecaecd21be8ac5ba80a64de89
Contents?: true
Size: 1.98 KB
Versions: 1
Compression:
Stored size: 1.98 KB
Contents
=begin This file is part of the Arachni-RPC project and may be subject to redistribution and commercial restrictions. Please see the Arachni-RPC web site for more information on licensing and terms of use. =end require File.join( File.expand_path( File.dirname( __FILE__ ) ), '../', 'rpc' ) module Arachni module RPC # # Represents an RPC message, serves as the basis for {Request} and {Response}. # # @author: Tasos "Zapotek" Laskos # <tasos.laskos@gmail.com> # <zapotek@segfault.gr> # @version: 0.1 # class Message # # @param [Hash] opts sets instance attributes # def initialize( opts = {} ) opts.each_pair { |k, v| instance_variable_set( "@#{k}".to_sym, v ) } end # # Merges the attributes of another message with self. # # (The param doesn't *really* have to be a message, any object will do.) # # @param [Message] message # def merge!( message ) message.instance_variables.each { |var| val = message.instance_variable_get( var ) instance_variable_set( var, val ) } end # # 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. # # @return [Hash] # def prepare_for_tx hash = {} instance_variables.each { |k| next if !transmit?( k ) hash[normalize( k )] = instance_variable_get( k ) } return hash end # # Decides which attributes should be skipped by {#prepare_for_tx}. # # @param [Symbol] attr attribute symbol (i.e. :@token) # def transmit?( attr ) return true end private def normalize( attr ) attr.to_s.gsub( '@', '' ) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arachni-rpc-0.1.1 | lib/arachni/rpc/message.rb |