Module: N::App::RequestUtils

Included in:
Request
Defined in:
lib/n/app/request.rb

Overview

RequestUtils

A collection of Request utility methods. Factored out from the Request object in a separate module to allow for inclusion in generic request objects (for example WEBrick).

Instance Method Summary collapse

Instance Method Details

#expand_uri(params) ⇒ Object

Expand URI Calculates a new uri based on the request.uri that includes the additional parameters suplied.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/n/app/request.rb', line 47

def expand_uri(params)
	hash = @parameters.dup()
	hash.update(params)

	pairs = []
	hash.each { |param, value|
		pairs << "#{param}=#{value}"
	}
	
	# gmosx: hash is ALWAYS non empty!
	return "#{@translated_uri}?#{pairs.join(';')}"  
end

#full_uriObject

Full URI



35
36
37
38
39
40
41
# File 'lib/n/app/request.rb', line 35

def full_uri
	if @query_string
		return "#{@translated_uri}?#{@query_string}"
	else
		return @translated_uri
	end
end

#get_entity(oid_param, klass = nil) ⇒ Object

Uses the passed oid_param to load a managed object (entity). Enforces some form of security by checking the klass of the requested entity.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/n/app/request.rb', line 64

def get_entity(oid_param, klass = nil)
	if oid = self[oid_param]
		obj = $db.get(oid, klass)

		if klass
			if obj.is_a?(klass)
				return obj
			else
				return nil
			end
		else
			return obj
		end
	else
		# $log.error "request.get_object('#{oid_param}') failed!"
		return nil
	end
end

#get_entity_by_name(name_param, klass) ⇒ Object

Uses the passed name_param to load a managed object (entity) by name. Enforces some form of security by checking the klass of the requested entity.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/n/app/request.rb', line 88

def get_entity_by_name(name_param, klass)
	if name = self[name_param]
		obj = $db.get_by_name(name, klass)

		if klass
			if obj.is_a?(klass)
				return obj
			else
				return nil
			end
		else
			# $log.error "request.get_object_by_name('#{name_param}') failed!"
			return obj
		end
	else
		return nil
	end
end