Class: Xeme::Message

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/xeme.rb

Overview

A Xeme::Message object represents a single error, warning, or note. It is the base class for Xeme::Message::Error, Xeme::Message::Warning, and Xeme::Message::Note. Don’t instantiate Xeme::Message directly, use Xeme#error, Xeme#warning, or Xeme#note.

Each message contains at least an id. It can also have an options details hash which can be used to store misc information about the message.

The message itself can be treated like a hash to give details:

msg = xeme.error(‘my-error’) msg = 1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, details = {}) ⇒ Message

Initialize a Xeme::Message object with the id of the message. The id can be any string. The optional details hash will be stored with the message.



450
451
452
453
454
455
456
457
458
# File 'lib/xeme.rb', line 450

def initialize(id, details={})
	# $tm.hr __method__
	
	# set id
	@id = id
	
	# initialize details
	@details = details.clone
end

Instance Attribute Details

#idObject (readonly)

The id of the message.



435
436
437
# File 'lib/xeme.rb', line 435

def id
  @id
end

Instance Method Details

#to_hObject

Returns a hash structure of the message. This structure is used by Xeme#to_h.



472
473
474
475
476
477
478
479
480
481
# File 'lib/xeme.rb', line 472

def to_h
	rv = {}
	rv['id'] = @id
	
	if @details.any?
		rv['details'] = @details
	end
	
	return rv
end