# class GxG::Events::Message

### Public Class Methods

new(*args) click to toggle source

    # File lib/gxg/gxg_events.rb, line 7
    def initialize(*args)
      # MUST provide a hash with at least :sender message field set
      # {:sender => <some-object>, :body => <some-object>, :on_success => <some-proc>, :on_fail => <some-proc> }
      unless args[0].is_a?(::Hash)
        raise ArgumentError, "you must pass a Hash to create the message"
      end
      @data = {:sender => nil, :id => (::GxG::uuid_generate().to_s.to_sym), :subject => args[1], :body => nil, :on_success => nil, :on_fail => nil}.merge(args[0])
      unless @data[:sender]
        raise ArgumentError, "you must set the :sender key in the argument Hash"
      end
      self
    end

### Public Instance Methods

[](the_key) click to toggle source

    # File lib/gxg/gxg_events.rb, line 81
    def [](the_key)
      @data[(the_key)]
    end

[]=(the_key, the_value) click to toggle source

    # File lib/gxg/gxg_events.rb, line 84
    def []=(the_key, the_value)
      @data[(the_key)] = the_value
    end

body() click to toggle source

    # File lib/gxg/gxg_events.rb, line 36
    def body()
      @data[:body]
    end

compose_reply(&block) click to toggle source

    # File lib/gxg/gxg_events.rb, line 40
    def compose_reply(&block)
      if block.respond_to?(:call)
        reply_message = new_message({:sender => self[:to], :to => self[:sender], :context => self[:context], :subject => self[:subject], :body => self[:body]})
        block.call(reply_message)
      else
        nil
      end
    end

fail(input=nil) click to toggle source

    # File lib/gxg/gxg_events.rb, line 55
    def fail(input=nil)
      if @data[:on_fail].respond_to?(:call)
        @data[:on_fail].call(input)
      end
    end

get_at_path(*args) click to toggle source

    # File lib/gxg/gxg_events.rb, line 99
    def get_at_path(*args)
      @data.get_at_path(*args)
    end

id() click to toggle source

    # File lib/gxg/gxg_events.rb, line 24
    def id()
      @data[:id]
    end

inspect() click to toggle source

    # File lib/gxg/gxg_events.rb, line 20
    def inspect()
      @data.inspect
    end

keys() click to toggle source

Hash-like support methods:

    # File lib/gxg/gxg_events.rb, line 78
    def keys()
      @data.keys()
    end

on(event_type=nil,&block) click to toggle source

    # File lib/gxg/gxg_events.rb, line 61
    def on(event_type=nil,&block)
      if [:success, :fail].include?(event_type)
        if block.respond_to?(:call)
          case event_type
          when :success
            @data[:on_success] = block
          when :fail
            @data[:on_fail] = block
          end
        else
          raise ArgumentError, "You MUST provide a callable block."
        end
      else
        raise ArgumentError, "Unknown event type: #{event_type}"
      end
    end

paths_to(*args) click to toggle source

    # File lib/gxg/gxg_events.rb, line 96
    def paths_to(*args)
      @data.paths_to(*args)
    end

process(&block) click to toggle source

    # File lib/gxg/gxg_events.rb, line 87
    def process(&block)
      @data.process(&block)
    end

process!(&block) click to toggle source

    # File lib/gxg/gxg_events.rb, line 90
    def process!(&block)
      @data.process!(&block)
    end

search(&block) click to toggle source

    # File lib/gxg/gxg_events.rb, line 93
    def search(&block)
      @data.search(&block)
    end

sender() click to toggle source

    # File lib/gxg/gxg_events.rb, line 28
    def sender()
      @data[:sender]
    end

set_at_path(*args) click to toggle source

    # File lib/gxg/gxg_events.rb, line 102
    def set_at_path(*args)
      @data.set_at_path(*args)
    end

subject() click to toggle source

    # File lib/gxg/gxg_events.rb, line 32
    def subject()
      @data[:subject]
    end

succeed(input=nil) click to toggle source

    # File lib/gxg/gxg_events.rb, line 49
    def succeed(input=nil)
      if @data[:on_success].respond_to?(:call)
        @data[:on_success].call(input)
      end
    end