Sha256: 008b63c861093e152169709fbd035c9bd984a22d97a46be1fc854162d47ceb88

Contents?: true

Size: 834 Bytes

Versions: 3

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

require 'open3'
require 'runger/ext/hash'

using Runger::Ext::Hash

class Runger::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] == '_'
        # rubocop:disable Performance/ArraySemiInfiniteRangeSlice
        key[1..]
        # rubocop:enable Performance/ArraySemiInfiniteRangeSlice
      else
        key
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
runger_config-5.2.0 lib/runger/ejson_parser.rb
runger_config-5.1.0 lib/runger/ejson_parser.rb
runger_config-5.0.0 lib/runger/ejson_parser.rb