Class: Console1984::Config

Inherits:
Object
  • Object
show all
Includes:
Freezeable, Messages
Defined in:
lib/console1984/config.rb

Overview

Container for config options.

These config options are accessible via first-level reader methods at Console1984.

Constant Summary collapse

PROTECTIONS_CONFIG_FILE_PATH =
Console1984::Engine.root.join("config/protections.yml")
PROPERTIES =
%i[
  session_logger username_resolver ask_for_username_if_empty shield command_executor
  protected_environments protected_urls
  production_data_warning enter_unprotected_encryption_mode_warning enter_protected_mode_warning
  incinerate incinerate_after incineration_queue
  protections_config
  base_record_class
  debug test_mode
]

Constants included from Messages

Messages::COMMANDS, Messages::DEFAULT_ENTER_PROTECTED_MODE_WARNING, Messages::DEFAULT_ENTER_UNPROTECTED_ENCRYPTION_MODE_WARNING, Messages::DEFAULT_PRODUCTION_DATA_WARNING

Instance Method Summary collapse

Methods included from Freezeable

freeze_all, included

Constructor Details

#initializeConfig

Returns a new instance of Config.



21
22
23
# File 'lib/console1984/config.rb', line 21

def initialize
  set_defaults
end

Instance Method Details

#freezeObject



36
37
38
39
# File 'lib/console1984/config.rb', line 36

def freeze
  super
  [ protected_urls, protections_config ].each(&:freeze)
end

#protections_configObject

Initialize lazily so that it only gets instantiated during console sessions



32
33
34
# File 'lib/console1984/config.rb', line 32

def protections_config
  @protections_config ||= Console1984::ProtectionsConfig.new(YAML.safe_load(File.read(PROTECTIONS_CONFIG_FILE_PATH)).symbolize_keys)
end

#set_from(properties) ⇒ Object



25
26
27
28
29
# File 'lib/console1984/config.rb', line 25

def set_from(properties)
  properties.each do |key, value|
    public_send("#{key}=", value) if value.present?
  end
end