Class TemplateVariable
In: app/models/template_variable.rb
Parent: ActiveRecord::Base

API for interaction with the database table ‘template_variables’, and it‘s related data model.

Methods

compose   get   set  

Public Class methods

Populate template variables.

Variables use indices of the following format:

  • <element>:<variable name>

For example:

  • ‘html:language‘

[Source]

    # File app/models/template_variable.rb, line 22
22:   def self.compose (
23:     data_type,
24:     data_id
25:   )
26:     for variable in find_all_by_data_type_and_data_id_and_active(data_type, 
27:                                                                  data_id,
28:                                                                  'TRUE')
29:       set(variable.element + ':' + variable.name, 
30:           variable.value, 
31:           variable.updated_on)
32:     end
33:   end

Construct template variables for a project page:

1. Obtain all variables for the default project (Code Blue)

2. Obtain all variables for this project, overwriting any existing variables using project specific values (which is faster than performing an array test to determine if an index exists and then adding an element to the array)

3. Obtain all variables for this project host, overwriting any existing variables using project host specific values

4. Obtain all variables for this project page, overwriting any existing variables using project page specific values

[Source]

    # File app/models/template_variable.rb, line 55
55:   def self.get (
56:     project_id,
57:     project_host_id,
58:     project_page_id,
59:     path_info
60:   )
61:     @variables = {}
62: 
63:     data_types =  []
64:     data_types << ['project',      DEFAULT_PROJECT_ID]
65:     data_types << ['project',      project_id]
66:     data_types << ['project_host', project_host_id]
67:     data_types << ['project_page', project_page_id]
68:     data_types.each { |t| compose(t[0], t[1]) }
69: 
70:     @variables
71:   end

Configure an individual template variable.

[Source]

    # File app/models/template_variable.rb, line 77
77:   def self.set (
78:     *arguments
79:   )
80:     index      = arguments[0].to_s if (arguments[0])
81:     value      = arguments[1].to_s if (arguments[1])
82:     updated_on = arguments[2]      if (arguments[2])
83: 
84:     # Store this variable's "value" and "updated_on" information.
85:     if (e(index) && e(value))
86:       @variables[index]               = {}
87:       @variables[index]['value']      = value
88:       @variables[index]['updated_on'] = updated_on || nil
89:     end
90:   end

[Validate]