Class: Contrast::Components::Config::Sources
- Defined in:
- lib/contrast/components/config/sources.rb
Overview
This component encapsulates storing the source for each entry in the config, so that we can report on where the value was set from.
Constant Summary collapse
- ENVIRONMENT_VARIABLE =
[ CORPORATE_RULE, COMMAND_LINE, JAVA_SYSTEM_PROPERTY, ENVIRONMENT_VARIABLE, APP_CONFIGURATION_FILE, USER_CONFIGURATION_FILE, CONTRAST_UI, DEFAULT_VALUE ]
'ENVIRONMENT_VARIABLE'
- COMMAND_LINE =
'COMMAND_LINE'
- CONTRAST_UI =
'CONTRAST_UI'
- DEFAULT_VALUE =
'DEFAULT_VALUE'
- APP_CONFIGURATION_FILE =
'USER_CONFIGURATION_FILE'
- APP_CONFIGURATION_EXTENSIONS =
Order matters for the Configurations files. This is read when Agent starts up and will always go through the YAML as priority. Do not change the order!
%w[yaml yml].cs__freeze
Instance Attribute Summary collapse
- #data ⇒ Hash readonly
Instance Method Summary collapse
-
#configuration_file_source?(path, source: false) ⇒ Boolean
True if the entry is from a YAML file.
-
#for(type) ⇒ Hash
Finds entries within config source data for the specified type, and returns them along with the current values for each.
-
#get(path) ⇒ String
Retrieves the current config source for the specified config path.
-
#initialize(data = {}) ⇒ Sources
constructor
A new instance of Sources.
-
#set(path, source) ⇒ String
Assigns the config source for a specified config path.
-
#source_overridden?(path) ⇒ Boolean
Check to see whether the source has been overridden by local settings.
Constructor Details
#initialize(data = {}) ⇒ Sources
Returns a new instance of Sources.
29 30 31 |
# File 'lib/contrast/components/config/sources.rb', line 29 def initialize data = {} @data = data end |
Instance Attribute Details
#data ⇒ Hash (readonly)
27 28 29 |
# File 'lib/contrast/components/config/sources.rb', line 27 def data @data end |
Instance Method Details
#configuration_file_source?(path, source: false) ⇒ Boolean
Returns true if the entry is from a YAML file.
66 67 68 69 70 71 |
# File 'lib/contrast/components/config/sources.rb', line 66 def configuration_file_source? path, source: false s = source ? path : Contrast::CONFIG.sources.get(path) return true if s.include?(APP_CONFIGURATION_EXTENSIONS[0]) || s.include?(APP_CONFIGURATION_EXTENSIONS[1]) false end |
#for(type) ⇒ Hash
Finds entries within config source data for the specified type, and returns them along with the current values for each.
58 59 60 |
# File 'lib/contrast/components/config/sources.rb', line 58 def for type deep_select(data.dup, type, []) end |
#get(path) ⇒ String
Retrieves the current config source for the specified config path. If no source is set then returns the Default value.
38 39 40 41 42 |
# File 'lib/contrast/components/config/sources.rb', line 38 def get path data.dig(*parts_for(path)) || DEFAULT_VALUE rescue TypeError DEFAULT_VALUE end |
#set(path, source) ⇒ String
Assigns the config source for a specified config path.
49 50 51 |
# File 'lib/contrast/components/config/sources.rb', line 49 def set path, source assign_value(data, parts_for(path), source) end |
#source_overridden?(path) ⇒ Boolean
Check to see whether the source has been overridden by local settings.
75 76 77 78 79 80 81 |
# File 'lib/contrast/components/config/sources.rb', line 75 def source_overridden? path source = Contrast::CONFIG.sources.get(path) return true if [ENVIRONMENT_VARIABLE, COMMAND_LINE].include?(source) return true if configuration_file_source?(source, source: true) false end |