Sha256: 8d2759f5e91195a80751053c2b83139e0d25fbdae7e25e6b8709e9321d13bcb5

Contents?: true

Size: 760 Bytes

Versions: 1

Compression:

Stored size: 760 Bytes

Contents

# frozen_string_literal: true

require "open3"
require "runger/ext/hash"

using Runger::Ext::Hash

module Runger
  class EJSONParser
    attr_reader :bin_path

    def initialize(bin_path = "ejson")
      @bin_path = bin_path
    end

    def call(file_path)
      return unless File.exist?(file_path)

      raw_content = nil

      stdout, stderr, status = Open3.capture3("#{bin_path} decrypt #{file_path}")

      if status.success?
        raw_content = JSON.parse(stdout.chomp)
      else
        Kernel.warn "Failed to decrypt #{file_path}: #{stderr}"
      end

      return unless raw_content

      raw_content.deep_transform_keys do |key|
        if key[0] == "_"
          key[1..]
        else
          key
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
runger_config-4.0.0 lib/runger/ejson_parser.rb