Sha256: f1080bc015838bb069448a6200df626d75f7afbe9afe46bb98ffa6dee2f83e5f

Contents?: true

Size: 845 Bytes

Versions: 7

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

module Roro
  module FileReflection

    def source_files(dir, pattern)
      Dir.glob("#{dir}/**/*#{pattern}")
    end

    def gather_environments(dir, ext)
      environments = source_files(dir, ext).map do |file|
        file.split('/').last.split('.').first
      end
      if environments.empty?
        raise Roro::Error, "No #{ext} files in #{dir}"
      else
        environments.uniq
      end
    end

    def get_key(environment, _dir = Roro::CLI.mise)
      env_key = "#{environment.upcase}_KEY"
      key_file = Dir.glob("#{Roro::CLI.mise}/keys/#{environment}.key").first
      if ENV[env_key]
        ENV[env_key]
      elsif key_file
        File.read(key_file).strip
      else
        raise Roro::Error, "No #{env_key} set. Please set one as a variable or in a file."
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
roro-0.3.33 lib/roro/common/file_reflection.rb
roro-0.3.30 lib/roro/common/file_reflection.rb
roro-0.3.28 lib/roro/common/file_reflection.rb
roro-0.3.27 lib/roro/common/file_reflection.rb
roro-0.3.25 lib/roro/common/file_reflection.rb
roro-0.3.24 lib/roro/common/file_reflection.rb
roro-0.3.23 lib/roro/common/file_reflection.rb