Class: Chamber::FileSet
- Inherits:
-
Object
- Object
- Chamber::FileSet
- Defined in:
- lib/chamber/file_set.rb
Instance Attribute Summary collapse
-
#basepath ⇒ Object
Returns the value of attribute basepath.
-
#decryption_keys ⇒ Object
Returns the value of attribute decryption_keys.
-
#encryption_keys ⇒ Object
Returns the value of attribute encryption_keys.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#signature_name ⇒ Object
Returns the value of attribute signature_name.
Instance Method Summary collapse
-
#filenames ⇒ Object
Internal: Returns an Array of the ordered list of files that was processed by Chamber in order to get the resulting settings values.
-
#initialize(files:, basepath: nil, decryption_keys: nil, encryption_keys: nil, namespaces: {}, signature_name: nil) ⇒ FileSet
constructor
rubocop:disable Metrics/ParameterLists.
- #secure ⇒ Object
- #sign ⇒ Object
-
#to_settings ⇒ Object
Internal: Converts the FileSet into a Settings object which represents all the settings specified in all of the files in the FileSet.
- #unsecure ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(files:, basepath: nil, decryption_keys: nil, encryption_keys: nil, namespaces: {}, signature_name: nil) ⇒ FileSet
rubocop:disable Metrics/ParameterLists
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/chamber/file_set.rb', line 123 def initialize(files:, basepath: nil, decryption_keys: nil, encryption_keys: nil, namespaces: {}, signature_name: nil) self.basepath = basepath self.decryption_keys = decryption_keys self.encryption_keys = encryption_keys self.namespaces = namespaces self.paths = files self.signature_name = signature_name end |
Instance Attribute Details
#basepath ⇒ Object
Returns the value of attribute basepath.
115 116 117 |
# File 'lib/chamber/file_set.rb', line 115 def basepath @basepath end |
#decryption_keys ⇒ Object
Returns the value of attribute decryption_keys.
115 116 117 |
# File 'lib/chamber/file_set.rb', line 115 def decryption_keys @decryption_keys end |
#encryption_keys ⇒ Object
Returns the value of attribute encryption_keys.
115 116 117 |
# File 'lib/chamber/file_set.rb', line 115 def encryption_keys @encryption_keys end |
#namespaces ⇒ Object
Returns the value of attribute namespaces.
119 120 121 |
# File 'lib/chamber/file_set.rb', line 119 def namespaces @namespaces end |
#paths ⇒ Object
Returns the value of attribute paths.
119 120 121 |
# File 'lib/chamber/file_set.rb', line 119 def paths @paths end |
#signature_name ⇒ Object
Returns the value of attribute signature_name.
115 116 117 |
# File 'lib/chamber/file_set.rb', line 115 def signature_name @signature_name end |
Instance Method Details
#filenames ⇒ Object
Internal: Returns an Array of the ordered list of files that was processed by Chamber in order to get the resulting settings values. This is useful for debugging if a given settings value isn’t quite what you anticipated it should be.
Returns an Array of file path strings
146 147 148 |
# File 'lib/chamber/file_set.rb', line 146 def filenames @filenames ||= files.map(&:to_s) end |
#secure ⇒ Object
191 192 193 |
# File 'lib/chamber/file_set.rb', line 191 def secure files.each(&:secure) end |
#sign ⇒ Object
199 200 201 |
# File 'lib/chamber/file_set.rb', line 199 def sign files.each(&:sign) end |
#to_settings ⇒ Object
Internal: Converts the FileSet into a Settings object which represents all the settings specified in all of the files in the FileSet.
This can be used in one of two ways. You may either specify a block which will be passed each file’s settings as they are converted, or you can choose not to pass a block, in which case it will pass back a single completed Settings object to the caller.
The reason the block version is used in Chamber.settings is because we want to be able to load each settings file as it’s processed so that we can use those already-processed settings in subsequently processed settings files.
Examples:
###
# Specifying a Block
#
file_set = FileSet.new files: [ '/path/to/my/settings.yml' ]
file_set.to_settings do |settings|
# do stuff with each settings
end
###
# No Block Specified
#
file_set = FileSet.new files: [ '/path/to/my/settings.yml' ]
file_set.to_settings
# => <Chamber::Settings>
183 184 185 186 187 188 189 |
# File 'lib/chamber/file_set.rb', line 183 def to_settings files.inject(Settings.new) do |settings, file| settings.merge(file.to_settings).tap do |merged| yield merged if block_given? end end end |
#unsecure ⇒ Object
195 196 197 |
# File 'lib/chamber/file_set.rb', line 195 def unsecure files.each(&:decrypt) end |
#verify ⇒ Object
203 204 205 206 207 208 209 |
# File 'lib/chamber/file_set.rb', line 203 def verify files.each_with_object({}) do |file, memo| relative_filepath = Pathname.new(file.to_s).relative_path_from(basepath).to_s memo[relative_filepath] = file.verify end end |