Class: ReliableMsg::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/reliable-msg/selector.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Constant, Deferred, Header

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Selector

Returns a new instance of Selector.



25
26
27
28
# File 'lib/reliable-msg/selector.rb', line 25

def initialize &block
    # Call the block and hold the deferred value.
    @value = self.instance_eval &block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/reliable-msg/selector.rb', line 30

def method_missing symbol, *args
    if symbol == :__evaluate__
        # Evaluate the selector with the headers passed in the argument.
        @value.is_a?(Deferred) ? @value.__evaluate__(*args) : @value
    else
        # Create a deferred value for the missing method (a header).
        raise ArgumentError, "Can't pass arguments to header" unless args.empty?
        Header.new symbol
    end
end