Class: NcsNavigator::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ncs_navigator/configuration.rb,
lib/ncs_navigator/configuration/version.rb,
lib/ncs_navigator/configuration/sampling_units.rb

Overview

The typed access point for the common configuration in the NCS Navigator suite.

Defined Under Namespace

Classes: Error, PrimarySamplingUnit, SamplingUnitArea, SecondarySamplingUnit, TertiarySamplingUnit

Constant Summary collapse

APPLICATION_SECTIONS =
['Staff Portal', 'Core', 'PSC']
VERSION =
'0.3.2'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Configuration

Creates a new Configuration.

Parameters:

  • source (String, Hash)

    the basis for this configuration. If it's a String, it's interpreted as a the filename for an INI file (sample). If it's a Hash, it should have two levels. The first level represents the sections and the second level the keys and values.



315
316
317
318
319
320
321
322
# File 'lib/ncs_navigator/configuration.rb', line 315

def initialize(source)
  case source
  when String
    init_from_ini(source)
  else
    init_from_hash(source)
  end
end

Instance Attribute Details

#ini_filenamePathname (readonly)

The file from which this configuration was initialized, if any.

Returns:

  • (Pathname)


157
158
159
# File 'lib/ncs_navigator/configuration.rb', line 157

def ini_filename
  @ini_filename
end

Class Method Details

.configuration_attribute(name, section, key, type, options = {})

This method returns an undefined value.

Defines a mapping from the configuration file to an attribute on this class.

Parameters:

  • name (Symbol)

    the name of the attribute.

  • section (String)

    the section of the configuration file from which it is read.

  • key (String)

    the configuration key within the section for the attribute.

  • type (Class)

    the type to which the configuration value should be coerced.

  • options (Hash) (defaults to: {})

    additional options controlling the behavior of the attribute.

Options Hash (options):

  • :required (Boolean) — default: false

    is the configuration property mandatory? If it is, reading the configuration will fail if it is not provided or is blank.

  • :default (Object)

    the default value for the configuration property.



72
73
74
75
# File 'lib/ncs_navigator/configuration.rb', line 72

def configuration_attribute(name, section, key, type, options={})
  configuration_attributes << ConfigurationAttribute.new(name, section, key, type, options)
  attr_accessor name
end

.section_accessor(section_name, accessor_name)

This method returns an undefined value.

Defines an attribute that exposes the raw contents of a section.

Parameters:

  • section_name (#to_s)

    the name of the section in the INI file.

  • accessor_name (#to_sym)

    the name for the generated accessor.



86
87
88
89
90
# File 'lib/ncs_navigator/configuration.rb', line 86

def section_accessor(section_name, accessor_name)
  define_method accessor_name.to_sym do
    @application_sections[section_name.to_s] ||= {}
  end
end

Instance Method Details

#action_mailer_smtp_settingsHash<Symbol, Object>

Provides a configuration hash suitable for passing to ActionMailer::Base.smtp_settings.

Returns:

  • (Hash<Symbol, Object>)


433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/ncs_navigator/configuration.rb', line 433

def action_mailer_smtp_settings
  Hash[
    {
      :address => smtp_host,
      :port => smtp_port,
      :domain => smtp_helo_domain,
      :user_name => smtp_username,
      :password => smtp_password,
      :authentication => smtp_authentication_method,
      :enable_starttls_auto => smtp_starttls
    }.select { |k, v| v }
  ]
end

#CoreObject



303
# File 'lib/ncs_navigator/configuration.rb', line 303

section_accessor 'Core', :core

#core_machine_account_passwordString

Machine account for Cases. Read from the [Core] section, key machine_account_password.

Returns:

  • (String)


244
245
# File 'lib/ncs_navigator/configuration.rb', line 244

configuration_attribute :core_machine_account_password, 'Core',
'machine_account_password', String

#core_mail_fromString

The address from which mail sent by Core will appear to come. Read from the [Core] section, key mail_from.

Returns:

  • (String)


249
250
# File 'lib/ncs_navigator/configuration.rb', line 249

configuration_attribute :core_mail_from, 'Core', 'mail_from', String,
:default => '[email protected]'

#core_uriURI

The root URI for the NCS Navigator Core deployment in this instance of the suite. Read from the [Core] section, key uri.

Returns:

  • (URI)


240
# File 'lib/ncs_navigator/configuration.rb', line 240

configuration_attribute :core_uri, 'Core', 'uri', URI, :required => true

#exception_email_recipientsArray

The e-mail addresses which will receive uncaught exceptions from any application in the suite. Read from the [Study Center] section, key exception_email_recipients.

Returns:

  • (Array)


190
191
# File 'lib/ncs_navigator/configuration.rb', line 190

configuration_attribute :exception_email_recipients, 'Study Center',
'exception_email_recipients', Array, :default => []

Converts #footer_text into equivalent HTML.

Returns:

  • (String)


418
419
420
421
422
423
424
425
426
# File 'lib/ncs_navigator/configuration.rb', line 418

def footer_center_html
  return nil unless footer_text
  html = footer_text.split("\n").join("<br>\n")
  if html.respond_to?(:html_safe)
    html.html_safe
  else
    html
  end
end

The image that should appear on the left side of the footer in Staff Portal and Core. This should be a path to a file on the deployed server. Read from the [Study Center] section, key footer_logo_left.

Returns:

  • (Pathname)


213
# File 'lib/ncs_navigator/configuration.rb', line 213

configuration_attribute :footer_logo_left, 'Study Center', 'footer_logo_left', Pathname

The image that should appear on the right side of the footer in Staff Portal and Core. This should be a path to a file on the deployed server. Read from the [Study Center] section, key footer_logo_right.

Returns:

  • (Pathname)


219
# File 'lib/ncs_navigator/configuration.rb', line 219

configuration_attribute :footer_logo_right, 'Study Center', 'footer_logo_right', Pathname

The text that should appear in the center of the footer in Staff Portal and Core. This is usually the center's contact information. Read from the [Study Center] section, key footer_text.

Returns:

  • (String)


225
# File 'lib/ncs_navigator/configuration.rb', line 225

configuration_attribute :footer_text, 'Study Center', 'footer_text', String

#primary_sampling_unitsArray<PrimarySamplingUnit> Also known as: psus

Returns the PSUs defined in #sampling_units_file.

Returns:



402
403
404
# File 'lib/ncs_navigator/configuration.rb', line 402

def primary_sampling_units
  @primary_sampling_units ||= read_primary_sampling_units
end

#PSCObject



304
# File 'lib/ncs_navigator/configuration.rb', line 304

section_accessor 'PSC', :psc

#psc_uriURI

The root URI for the PSC deployment in this instance of the suite. Read from the [PSC] section, key uri.

Returns:

  • (URI)


255
# File 'lib/ncs_navigator/configuration.rb', line 255

configuration_attribute :psc_uri, 'PSC', 'uri', URI, :required => true

#recruitment_type_idString

The recruitment strategy for this study center. The acceptable values are those from the code list recruit_type_cl1 in the MDES. Read from the [Study Center] section, key recruitment_type_id.

Returns:

  • (String)


178
179
# File 'lib/ncs_navigator/configuration.rb', line 178

configuration_attribute :recruitment_type_id, 'Study Center', 'recruitment_type_id', String,
:required => true

#sampling_unit_areasArray<SamplingUnitArea> Also known as: areas

Returns the areas defined in #sampling_units_file.

Returns:



364
365
366
# File 'lib/ncs_navigator/configuration.rb', line 364

def sampling_unit_areas
  @sampling_unit_areas ||= primary_sampling_units.collect(&:sampling_unit_areas).flatten
end

#sampling_units_filePathname

The CSV describing the PSU, "sampling areas", SSUs, and (if applicable) TSUs for this center.

The format is described in the comments in the sample INI. Read from the [Study Center] section, key sampling_units_file.

Returns:

  • (Pathname)


206
207
# File 'lib/ncs_navigator/configuration.rb', line 206

configuration_attribute :sampling_units_file, 'Study Center', 'sampling_units_file', Pathname,
:required => true

#secondary_sampling_unitsArray<SecondarySamplingUnit> Also known as: ssus

Returns the SSUs defined in #sampling_units_file.

Returns:



409
410
411
# File 'lib/ncs_navigator/configuration.rb', line 409

def secondary_sampling_units
  @secondary_sampling_units ||= primary_sampling_units.collect(&:secondary_sampling_units).flatten
end

#smtp_authentication_methodSymbol

The type of authentication needed for the SMTP server, if any. Read from the [SMTP] section, key authentication.

Returns:

  • (Symbol)


272
# File 'lib/ncs_navigator/configuration.rb', line 272

configuration_attribute :smtp_authentication_method, 'SMTP', 'authentication', Symbol

#smtp_helo_domainString

The the HELO domain for the SMTP server, if any. Read from the [SMTP] section, key domain.

Returns:

  • (String)


268
# File 'lib/ncs_navigator/configuration.rb', line 268

configuration_attribute :smtp_helo_domain, 'SMTP', 'domain', String

#smtp_hostString

The hostname of the SMTP server the suite should use to send mail. Read from the [SMTP] section, key host.

Returns:

  • (String)


260
# File 'lib/ncs_navigator/configuration.rb', line 260

configuration_attribute :smtp_host, 'SMTP', 'host', String, :default => 'localhost'

#smtp_passwordString

The password to use when authenticating to the SMTP server, if authentication is required. Read from the [SMTP] section, key password.

Returns:

  • (String)


282
# File 'lib/ncs_navigator/configuration.rb', line 282

configuration_attribute :smtp_password, 'SMTP', 'password', String

#smtp_portFixnum

The port for the SMTP server the suite should use. Read from the [SMTP] section, key port.

Returns:

  • (Fixnum)


264
# File 'lib/ncs_navigator/configuration.rb', line 264

configuration_attribute :smtp_port, 'SMTP', 'port', Fixnum, :default => 25

#smtp_starttlsBoolean

Whether to try to use STARTTLS if the SMTP server supports it. Defaults to false. Read from the [SMTP] section, key starttls.

Returns:

  • (Boolean)


287
# File 'lib/ncs_navigator/configuration.rb', line 287

configuration_attribute :smtp_starttls, 'SMTP', 'starttls', 'Boolean', :default => false

#smtp_usernameString

The username to use when authenticating to the SMTP server, if authentication is required. Read from the [SMTP] section, key username.

Returns:

  • (String)


277
# File 'lib/ncs_navigator/configuration.rb', line 277

configuration_attribute :smtp_username, 'SMTP', 'username', String

#Staff Portal($2) ⇒ Hash<String, String>

Exposes all the values from the [$1] section. This allows for flexibility in adding new options. The downside is that they are not automatically coerced or documented.

Returns:

  • (Hash<String, String>)

    the raw values from the [$1] section



302
# File 'lib/ncs_navigator/configuration.rb', line 302

section_accessor 'Staff Portal', :staff_portal

#staff_portal_mail_fromString

The address from which mail sent by Staff Portal will appear to come. Read from the [Staff Portal] section, key mail_from.

Returns:

  • (String)


234
235
# File 'lib/ncs_navigator/configuration.rb', line 234

configuration_attribute :staff_portal_mail_from, 'Staff Portal', 'mail_from', String,
:default => '[email protected]'

#staff_portal_uriURI

The root URI for the Staff Portal deployment in this instance of the suite. Read from the [Staff Portal] section, key uri.

Returns:

  • (URI)


230
# File 'lib/ncs_navigator/configuration.rb', line 230

configuration_attribute :staff_portal_uri, 'Staff Portal', 'uri', URI, :required => true

#study_center_idString Also known as: sc_id

Read from the [Study Center] section, key sc_id.

Returns:

  • (String)


169
170
# File 'lib/ncs_navigator/configuration.rb', line 169

configuration_attribute :study_center_id, 'Study Center', 'sc_id', String,
:required => true

#study_center_short_nameString

A short, human-readable name or abbreviation for the Study Center. Read from the [Study Center] section, key short_name.

Returns:

  • (String)


184
185
# File 'lib/ncs_navigator/configuration.rb', line 184

configuration_attribute :study_center_short_name, 'Study Center', 'short_name', String,
:default => 'SC'

#study_center_usernameString

The name for the institutional identity used in this deployment of NCS Navigator. For instance, for the Greater Chicago Study Center, it is "Northwestern NetID". The default is "Username". Read from the [Study Center] section, key username.

Returns:

  • (String)


197
198
# File 'lib/ncs_navigator/configuration.rb', line 197

configuration_attribute :study_center_username, 'Study Center', 'username', String,
:default => 'Username'