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.4.0'

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.



320
321
322
323
324
325
326
327
# File 'lib/ncs_navigator/configuration.rb', line 320

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>)


439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/ncs_navigator/configuration.rb', line 439

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



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

section_accessor 'Core', :core

#core_conflict_email_recipientsArray

When a merge conflict occurs in Cases, send emails to these addresses. Read from the [Core] section, key conflict_email_recipients.

Returns:

  • (Array)


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

configuration_attribute :core_conflict_email_recipients, 'Core',
'conflict_email_recipients', Array, :default => []

#core_machine_account_passwordString

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_machine_account_usernameString

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

Returns:

  • (String)


241
242
# File 'lib/ncs_navigator/configuration.rb', line 241

configuration_attribute :core_machine_account_username, 'Core',
'machine_account_username', 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)


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

configuration_attribute :core_uri, 'Core', 'uri', URI

#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)


188
189
# File 'lib/ncs_navigator/configuration.rb', line 188

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

Converts #footer_text into equivalent HTML.

Returns:

  • (String)


424
425
426
427
428
429
430
431
432
# File 'lib/ncs_navigator/configuration.rb', line 424

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)


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

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)


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

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)


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

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:



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

def primary_sampling_units
  @primary_sampling_units ||= read_primary_sampling_units
end

#PSCObject



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

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)


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

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)


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

configuration_attribute :recruitment_type_id, 'Study Center', 'recruitment_type_id', String

#sampling_unit_areasArray<SamplingUnitArea> Also known as: areas

Returns the areas defined in #sampling_units_file.

Returns:



369
370
371
# File 'lib/ncs_navigator/configuration.rb', line 369

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)


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

configuration_attribute :sampling_units_file, 'Study Center', 'sampling_units_file', Pathname

#secondary_sampling_unitsArray<SecondarySamplingUnit> Also known as: ssus

Returns the SSUs defined in #sampling_units_file.

Returns:



415
416
417
# File 'lib/ncs_navigator/configuration.rb', line 415

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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



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

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)


231
232
# File 'lib/ncs_navigator/configuration.rb', line 231

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)


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

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
# File 'lib/ncs_navigator/configuration.rb', line 169

configuration_attribute :study_center_id, 'Study Center', 'sc_id', String

#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)


182
183
# File 'lib/ncs_navigator/configuration.rb', line 182

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)


195
196
# File 'lib/ncs_navigator/configuration.rb', line 195

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