Sha256: b6880c37ecafc47750cb1a925be034c2e7cbb5d32f4ef2d91949b74c55c0c924

Contents?: true

Size: 569 Bytes

Versions: 2

Compression:

Stored size: 569 Bytes

Contents

# frozen_string_literal: true

module RrxConfig
  module Sources
    class Base
      def read
        throw NotImplementedError
      end

      protected

      # @param [String, nil] value
      # @return [Data, nil]
      def read_json(value)
        value ? json_to_data(JSON.parse(value, { symbolize_keys: true })) : nil
      end

      # @param [Hash] json
      def json_to_data(json)
        json = json.transform_values do |v|
          v.is_a?(Hash) ? json_to_data(v) : v
        end

        Data.define(*json.keys).new(**json)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rrx_config-0.1.1 lib/rrx_config/sources/base.rb
rrx_config-0.1.0 lib/rrx_config/sources/base.rb