class Synapse::Mapping::Mapping
Represents a mapping between a payload type and a handler method or block
Mappings are ordered by the depth of the payload type that they handle. Mappings that are for a more specific class are preferred over mappings for an abstract class.
Attributes
@return [Object] Either a method symbol or block
@return [Hash] Options specific to the component being mapped
@return [Class] The type of payload that a handler is being mapped to
Public Class Methods
@param [Class] type @param [Hash] options @param [Object] handler Either a method symbol or block @return [undefined]
# File lib/synapse/mapping/mapping.rb, line 21 def initialize(type, options, handler) @type = type @options = options @handler = handler end
Public Instance Methods
@param [Mapping] other @return [Integer]
# File lib/synapse/mapping/mapping.rb, line 46 def <=>(other) (@type <=> other.type) or 0 end
@param [Mapping] other @return [Boolean]
# File lib/synapse/mapping/mapping.rb, line 52 def ==(other) self.class === other and @type == other.type end
TODO Is this a good hash function? Probs not @return [Integer]
# File lib/synapse/mapping/mapping.rb, line 61 def hash @type.hash end
@param [Object] target @param [Object…] args @return [Object] The result of the handler invocation
# File lib/synapse/mapping/mapping.rb, line 30 def invoke(target, *args) if @handler.is_a? Symbol method = target.method @handler if method.arity > args.size || method.arity == 0 raise ArgumentError, 'Method signature is invalid' end method.call(*args.slice(0, method.arity)) else target.instance_exec *args, &@handler end end