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



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

def initialize
  set_defaults
end

Instance Method Details

#freezeObject



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

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

#protections_configObject

Initialize lazily so that it only gets instantiated during console sessions



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

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

#set_from(properties) ⇒ Object



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

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