Sha256: 827a3a3891aff813cd78f9aaf3f184728e2541160e072f8e6b40ce950661c8e5

Contents?: true

Size: 762 Bytes

Versions: 13

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

require "open3"
require "anyway/ext/hash"

using Anyway::Ext::Hash

module Anyway
  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..-1]
        else
          key
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
anyway_config-2.6.4 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.6.3 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.6.2 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.6.1 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.6.0 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.5.4 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.5.3 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.5.2 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.5.1 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.5.0 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.4.2 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.4.1 lib/.rbnext/2.6/anyway/ejson_parser.rb
anyway_config-2.4.0 lib/.rbnext/2.6/anyway/ejson_parser.rb