Sha256: 6f6a075184977b6069e4ed797ab7f08dc3fa0f88a44f40473ea19bdb996f2618

Contents?: true

Size: 913 Bytes

Versions: 8

Compression:

Stored size: 913 Bytes

Contents

require "flipper/export"
require "flipper/typecast"

module Flipper
  module Exporters
    module Json
      # Raised when the contents of the export are not valid.
      class InvalidError < StandardError; end
      class JsonError < InvalidError; end

      # Internal: JSON export class that knows how to build features hash
      # from data.
      class Export < ::Flipper::Export
        def initialize(contents:, version: 1)
          super contents: contents, version: version, format: :json
        end

        # Public: The features hash identical to calling get_all on adapter.
        def features
          @features ||= begin
            features = JSON.parse(contents).fetch("features")
            Typecast.features_hash(features)
          rescue JSON::ParserError
            raise JsonError
          rescue
            raise InvalidError
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
flipper-1.0.0 lib/flipper/exporters/json/export.rb
flipper-1.0.0.pre lib/flipper/exporters/json/export.rb
flipper-0.28.3 lib/flipper/exporters/json/export.rb
flipper-0.28.2 lib/flipper/exporters/json/export.rb
flipper-0.28.1 lib/flipper/exporters/json/export.rb
flipper-0.28.0 lib/flipper/exporters/json/export.rb
flipper-0.27.1 lib/flipper/exporters/json/export.rb
flipper-0.27.0 lib/flipper/exporters/json/export.rb