Class: Arrow::Session::Id

Inherits:
Object
  • Object
show all
Includes:
PluginFactory
Defined in:
lib/arrow/session/id.rb

Overview

The Arrow::Session::Id class, a derivative of Arrow::Object. Instances of concrete derivatives of this class are used as session IDs in Arrow::Session objects.

Authors

Please see the file LICENSE in the top-level directory for licensing details.

Direct Known Subclasses

MD5Id, SHA1Id, UserTrackId

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

deprecate_class_method, deprecate_method, inherited

Constructor Details

#initialize(uri, request, idstring = nil) ⇒ Id

Create a new Arrow::Session::Id object. If the idstring is given, it will be used as the unique key for this session. If it is not specified, a new one will be generated.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/arrow/session/id.rb', line 65

def initialize( uri, request, idstring=nil )
	@new = true

	if idstring
		self.log.debug "Validating id %p" % [ idstring ]
		@str = self.class.validate( uri, idstring )
		self.log.debug "  validation %s" % [ @str ? "succeeded" : "failed" ]
		@new = false
	end
	
	@str ||= self.class.generate( uri, request )
	super()
end

Class Method Details

.create(uri, request, idstring = nil) ⇒ Object

Create a new Arrow::Session::Id object for the given request (an Apache::Request) of the type specified by uri.



36
37
38
39
# File 'lib/arrow/session/id.rb', line 36

def self::create( uri, request, idstring=nil )
	uri = Arrow::Session.parse_uri( uri ) if uri.is_a?( String )
	super( uri.scheme.dup, uri, request, idstring )
end

.derivativeDirsObject

Returns the Array of directories to search for derivatives; part of the PluginFactory interface.



29
30
31
# File 'lib/arrow/session/id.rb', line 29

def self::derivativeDirs
	[ 'arrow/session', 'arrow/session/id' ]
end

.generate(uri, request) ⇒ Object

Generate a new id string for the given request.

Raises:

  • (NotImplementedError)


43
44
45
46
# File 'lib/arrow/session/id.rb', line 43

def self::generate( uri, request )
	raise NotImplementedError, "%s does not implement #generate" %
		self.name
end

.validate(uri, idstring) ⇒ Object

Validate the given idstring, returning an untainted copy of it if it’s valid, or nil if it’s not.

Raises:

  • (NotImplementedError)


51
52
53
54
# File 'lib/arrow/session/id.rb', line 51

def self::validate( uri, idstring )
	raise NotImplementedError, "%s does not implement #validate" %
		self.name
end

Instance Method Details

#new?Boolean

Returns true if the id was generated for this request as opposed to being fetched from a cookie or the URL.

Returns:

  • (Boolean)


93
94
95
# File 'lib/arrow/session/id.rb', line 93

def new?
	@new ? true : false
end

#to_sObject

Return the id as a String.



86
87
88
# File 'lib/arrow/session/id.rb', line 86

def to_s
	return @str
end