Sha256: 93812697e14d28c5fd2dd858a5b1006f7836f2daaa651ef1a9369919cb7d49c0

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Specimen
  module Utils
    class EncryptedConfigPath
      ENC_DIRECTORY = 'config/enc'

      attr_reader :name, :runtime

      def initialize(name:)
        @name = name
        @runtime = Specimen.runtime
      end

      def config_base_dir
        @config_base_dir ||= Pathname.new("#{runtime.wd_path}/#{ENC_DIRECTORY}")
      end

      def enc_dir
        return Pathname.new(config_base_dir.to_path) if config_dir.empty?

        Pathname.new("#{config_base_dir}/#{config_dir}")
      end

      def config_file_name
        "#{split_name.last}.yml.enc"
      end

      def config_dir
        split_name[0...-1].join('/')
      end

      def split_name
        name.split('/')
      end

      def full_enc_path
        @full_enc_path ||= Pathname.new("#{enc_dir}/#{config_file_name}")
      end

      def full_key_path
        @full_key_path ||= Pathname.new("#{enc_dir}/#{config_file_name.gsub('.yml.enc', '.key')}")
      end

      def config_exist?
        full_enc_path.exist?
      end

      def key_exist?
        full_key_path.exist?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
specimen-0.0.4.alpha lib/specimen/utils/encrypted_config_path.rb