| Class | ProjectHost |
| In: |
app/models/project_host.rb
|
| Parent: | ActiveRecord::Base |
API for interaction with the database table ‘project_hosts’, and it‘s related data model.
| page | [RW] | Accessor methods. |
DNS Agnate hostname resolution.
Obtain the project host object, based on the requested DNS name.
This method searches for an exact match using the full name of the requested host, if no match is found then the host name is truncated repeatedly - removing one segment at a time, starting from the least significant segment (the far left) - searching for a matching host. For example, using the requested host ‘cvs.archive.risto.net’:
# File app/models/project_host.rb, line 30
30: def self.get (
31: env
32: )
33: requested_host = env['HTTP_HOST']
34: protocol = env['SERVER_PROTOCOL']
35: path_info = env['PATH_INFO']
36:
37:
38: # The (application) default page is displayed when a DNS name points to
39: # this installation of Code Blue but the host was either not found in
40: # the database or is inactive.
41: if (DEFAULT_PROJECT_PAGE_PATH == path_info)
42: host = find(DEFAULT_PROJECT_HOST_ID)
43:
44: # Otherwise search for a host based on the DNS name.
45: else
46: segments = requested_host.split(':')[0].split('.')
47:
48: # Search for a matching host name, removing one octet at a time from the
49: # end of the host name.
50: while segments.size > 0
51: if (result = find_by_name_and_active(segments.join('.'), 'TRUE'))
52: host = result
53: break
54: else
55: segments.shift
56: end
57: end
58:
59: # If no match was found in the database for the requested host
60: # then obtain the default host for this installation.
61: host = find_by_id_and_active(DEFAULT_PROJECT_HOST_ID, 'TRUE') if (!host)
62: end
63:
64:
65: # Populate the project page for this request, if this is not a download
66: # request.
67: if !is_download(env['PATH_INFO'])
68: host.page = ProjectPage.get(host.project_id, host.id, path_info)
69: end
70:
71:
72: host
73: end