lib/eventbus/message.rb in eventbus-0.30.2 vs lib/eventbus/message.rb in eventbus-0.31

- old
+ new

@@ -7,10 +7,12 @@ module EventBus class Message attr_reader :data + attr_accessor :default_section + attr_accessor :global_section def initialize(application_id = EventBus.application_id) raise "No application ID specified!" if application_id.nil? @@ -26,10 +28,12 @@ 'backtrace' => nil, 'message' => nil }, 'PAYLOAD' => {} } + + self.global_section = "GLOBAL" @connection_driver = ENV["EVENTBUS_CONNECTOR"] || "Stomp" driver_module = "#{@connection_driver}ConnectionDriver" @@ -39,16 +43,18 @@ conn_module = Object.const_defined?(driver_module) ? Object.const_get(driver_module) : Object.const_missing(driver_module) extend conn_module connection_driver_initialize + + end def set(key, val, opts = {}) - + # This is for convenience and to make messages more # human-readable by eliminating the !Binary encoding # in YAML messages. I'm not willing to make this method # more expensive by walking deep structures to do the # same legwork, because this isn't a functionality issue. @@ -68,12 +74,15 @@ @data['PAYLOAD'][section.to_s] = {} if @data['PAYLOAD'][section.to_s].nil? @data['PAYLOAD'][section.to_s][key.to_s] = val end def get(key, opts = {}) + raise "You must specify a key name!" if key.nil? section = opts.delete(:section) || self.default_section_name + + puts "Getting section #{section}" return @data['PAYLOAD'][section.to_s].nil? ? nil : @data['PAYLOAD'][section.to_s][key.to_s] end # opts: @@ -175,12 +184,20 @@ self.backtrace = [] self.error_message = nil end def default_section_name - return self.class.name.split(/::/).last + return self.default_section || self.class.name.split(/::/).last end + + def get_global(key) + return get(key, :section => @global_section) + end + + def set_global(key, val) + return set(key, val, :section => @global_section) + end private def set_special(block, key, val) if val.is_a?(String) @@ -191,9 +208,11 @@ end def get_special(block, key) return @data[block.to_s][key.to_s] end + + end end # module EventBus