Class: Xeme::Transaction

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

Overview

An object of this class provdes meta information about the request and results. It always provides a a timestamp and a unique ID for the results. It may also optionally include a request ID that was provided by the process that made the request, such as a call to a REST application. Do not directly instantiate this class; use Xeme#transaction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTransaction

Initialize does not take any parameters.



579
580
581
582
583
# File 'lib/xeme.rb', line 579

def initialize
	@timestamp = DateTime.now()
	@response = rand().to_s.sub(/\A0\./mu, '')
	@request = nil
end

Instance Attribute Details

#requestObject

Optional. An ID for the request that was sent by the calling process. Do not generate this value yourself; use the ID that was sent with the request (if one was sent).



564
565
566
# File 'lib/xeme.rb', line 564

def request
  @request
end

#responseObject (readonly)

Gives a unique ID for these results.



567
568
569
# File 'lib/xeme.rb', line 567

def response
  @response
end

#timestampObject (readonly)

Gives a timestamp for when these results were generated.



570
571
572
# File 'lib/xeme.rb', line 570

def timestamp
  @timestamp
end

Instance Method Details

#to_hObject


to_h



592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/xeme.rb', line 592

def to_h
	rv = {}
	
	# request
	if @request
		rv['request'] = @request
	end
	
	# response and timestamp
	rv['response'] = @response
	rv['timestamp'] = @timestamp.to_s
	
	# return
	return rv
end