Sha256: b9ed3f192bc028a834ef8fee9a98fbdd40798515b7325670932ce5adb32c7df5

Contents?: true

Size: 1.39 KB

Versions: 63

Compression:

Stored size: 1.39 KB

Contents

module Hydra #:nodoc:
  # Base message object. Used to pass messages with parameters around
  # via IO objects.
  #   class MyMessage < Hydra::Message
  #     attr_accessor :my_var
  #     def serialize
  #       super(:my_var => @my_var)
  #     end
  #   end
  #   m = MyMessage.new(:my_var => 'my value')
  #   m.my_var
  #     => "my value"
  #   m.serialize
  #     => "{:class=>TestMessage::MyMessage, :my_var=>\"my value\"}"
  #   Hydra::Message.build(eval(@m.serialize)).my_var
  #     => "my value"
  class Message
    # Create a new message. Opts is a hash where the keys
    # are attributes of the message and the values are
    # set to the attribute.
    def initialize(opts = {})
      opts.delete :class
      opts.each do |variable,value|
        self.send("#{variable}=",value)
      end
    end

    # Build a message from a hash. The hash must contain
    # the :class symbol, which is the class of the message
    # that it will build to.
    def self.build(hash)
      hash.delete(:class).new(hash)
    end

    # Serialize the message for output on an IO channel.
    # This is really just a string representation of a hash
    # with no newlines. It adds in the class automatically
    def serialize(opts = {})
      opts.merge({:class => self.class}).inspect
    end
  end
end

require 'hydra/message/runner_messages'
require 'hydra/message/worker_messages'
require 'hydra/message/master_messages'

Version data entries

63 entries across 63 versions & 8 rubygems

Version Path
ngauthier-hydra-0.24.0 lib/hydra/message.rb
nulogy-hydra-0.26.0 lib/hydra/message.rb
arturop-hydra-0.25.0 lib/hydra/message.rb
arturop-hydra-0.24.0 lib/hydra/message.rb
hydra-0.24.0 lib/hydra/message.rb
nulogy-hydra-0.23.2.1 lib/hydra/message.rb
justinf-hydra-0.23.8 lib/hydra/message.rb
justinf-hydra-0.23.7 lib/hydra/message.rb
justinf-hydra-0.23.6 lib/hydra/message.rb
justinf-hydra-0.23.5 lib/hydra/message.rb
justinf-hydra-0.23.4 lib/hydra/message.rb
arturop-hydra-0.23.4 lib/hydra/message.rb
sskirby-hydra-0.23.3 lib/hydra/message.rb
hydra-0.23.3 lib/hydra/message.rb
causes-hydra-0.21.0 lib/hydra/message.rb
hydra-0.23.2 lib/hydra/message.rb
hydra-0.23.1 lib/hydra/message.rb
hydra-0.23.0 lib/hydra/message.rb
hydra-0.22.2 lib/hydra/message.rb
hydra-0.22.1 lib/hydra/message.rb