Class: Chamber::FileSet

Inherits:
Object
  • Object
show all
Defined in:
lib/chamber/file_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FileSet

Returns a new instance of FileSet.



121
122
123
124
125
126
127
# File 'lib/chamber/file_set.rb', line 121

def initialize(options = {})
  self.namespaces      = options[:namespaces] || {}
  self.decryption_keys = options[:decryption_keys]
  self.encryption_keys = options[:encryption_keys]
  self.paths           = options.fetch(:files)
  self.basepath        = options[:basepath]
end

Instance Attribute Details

#basepathObject

Returns the value of attribute basepath.



117
118
119
# File 'lib/chamber/file_set.rb', line 117

def basepath
  @basepath
end

#decryption_keysObject

Returns the value of attribute decryption_keys.



117
118
119
# File 'lib/chamber/file_set.rb', line 117

def decryption_keys
  @decryption_keys
end

#encryption_keysObject

Returns the value of attribute encryption_keys.



117
118
119
# File 'lib/chamber/file_set.rb', line 117

def encryption_keys
  @encryption_keys
end

#namespacesObject

Returns the value of attribute namespaces.



115
116
117
# File 'lib/chamber/file_set.rb', line 115

def namespaces
  @namespaces
end

#pathsObject

Returns the value of attribute paths.



115
116
117
# File 'lib/chamber/file_set.rb', line 115

def paths
  @paths
end

Instance Method Details

#filenamesObject

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



137
138
139
# File 'lib/chamber/file_set.rb', line 137

def filenames
  @filenames ||= files.map(&:to_s)
end

#secureObject



182
183
184
# File 'lib/chamber/file_set.rb', line 182

def secure
  files.each(&:secure)
end

#signObject



186
187
188
# File 'lib/chamber/file_set.rb', line 186

def sign
  files.each(&:sign)
end

#to_settingsObject

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>


174
175
176
177
178
179
180
# File 'lib/chamber/file_set.rb', line 174

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

#verifyObject



190
191
192
193
194
195
196
# File 'lib/chamber/file_set.rb', line 190

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