lib/chamber/settings.rb in chamber-2.8.0 vs lib/chamber/settings.rb in chamber-2.9.0

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true require 'hashie/mash' require 'chamber/namespace_set' require 'chamber/filters/namespace_filter' require 'chamber/filters/encryption_filter' require 'chamber/filters/decryption_filter' @@ -20,20 +21,20 @@ def initialize(options = {}) self.namespaces = options[:namespaces] || [] self.raw_data = options[:settings] || {} self.decryption_key = options[:decryption_key] self.encryption_key = options[:encryption_key] - self.pre_filters = options[:pre_filters] || [ - Filters::NamespaceFilter, - ] - self.post_filters = options[:post_filters] || [ - Filters::DecryptionFilter, - Filters::EnvironmentFilter, - Filters::FailedDecryptionFilter, - Filters::BooleanConversionFilter, - Filters::TranslateSecureKeysFilter, - ] + self.pre_filters = options[:pre_filters] || [ + Filters::NamespaceFilter, + ] + self.post_filters = options[:post_filters] || [ + Filters::DecryptionFilter, + Filters::EnvironmentFilter, + Filters::FailedDecryptionFilter, + Filters::BooleanConversionFilter, + Filters::TranslateSecureKeysFilter, + ] end ### # Internal: Converts a Settings object into a hash that is compatible as an # environment variable hash. @@ -184,11 +185,12 @@ Settings.new( encryption_key: encryption_key || other_settings.encryption_key, decryption_key: decryption_key || other_settings.decryption_key, namespaces: (namespaces + other_settings.namespaces), - settings: raw_data.merge(other_settings.raw_data)) + settings: raw_data.merge(other_settings.raw_data), + ) end ### # Internal: Determines whether a Settings is equal to another hash-like # object. @@ -203,33 +205,36 @@ # Internal: Determines whether a Settings is equal to another Settings. # # Returns a Boolean # def eql?(other) - other.is_a?(Chamber::Settings) && - data == other.data && + other.is_a?(Chamber::Settings) && + data == other.data && namespaces == other.namespaces end def securable Settings.new(metadata.merge( settings: raw_data, - pre_filters: [Filters::SecureFilter])) + pre_filters: [Filters::SecureFilter], + )) end def secure Settings.new(metadata.merge( settings: raw_data, pre_filters: [Filters::EncryptionFilter], - post_filters: [Filters::TranslateSecureKeysFilter])) + post_filters: [Filters::TranslateSecureKeysFilter], + )) end def insecure Settings.new(metadata.merge( settings: raw_data, pre_filters: [Filters::InsecureFilter], - post_filters: [Filters::TranslateSecureKeysFilter])) + post_filters: [Filters::TranslateSecureKeysFilter], + )) end protected attr_accessor :pre_filters, @@ -245,17 +250,17 @@ def namespaces=(raw_namespaces) @namespaces = NamespaceSet.new(raw_namespaces) end def raw_data - @filtered_raw_data ||= pre_filters.reduce(@raw_data) do |filtered_data, filter| + @filtered_raw_data ||= pre_filters.inject(@raw_data) do |filtered_data, filter| filter.execute({ data: filtered_data }. merge(metadata)) end end def data - @data ||= post_filters.reduce(raw_data) do |filtered_data, filter| + @data ||= post_filters.inject(raw_data) do |filtered_data, filter| filter.execute({ data: filtered_data }. merge(metadata)) end end