Sha256: e4abb7ad38f168238707cba0d74bb1de77bb3992a67da4cdce79c5fdf29bf308

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Fixtury
  module LocatorBackend
    module Common

      def recognizable_key?(_locator_value)
        raise NotImplementedError
      end

      def recognizable_value?(_stored_value)
        raise NotImplementedError
      end

      def load_reference(_locator_value)
        raise NotImplementedError
      end

      def dump_value(_stored_value)
        raise NotImplementedError
      end

      def load(locator_value)
        return load_reference(locator_value) if recognizable_key?(locator_value)

        case locator_value
        when Array
          locator_value.map { |subvalue| self.load(subvalue) }
        when Hash
          locator_value.each_with_object({}) do |(k, subvalue), h|
            h[k] = self.load(subvalue)
          end
        else
          raise Errors::UnrecognizableLocatorError.new(:load, locator_value)
        end
      end

      def dump(stored_value)
        return dump_value(stored_value) if recognizable_value?(stored_value)

        case stored_value
        when Array
          stored_value.map { |subvalue| dump(subvalue) }
        when Hash
          stored_value.each_with_object({}) do |(k, subvalue), h|
            h[k] = dump(subvalue)
          end
        else
          raise Errors::UnrecognizableLocatorError.new(:dump, stored_value)
        end
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
fixtury-2.0.0 lib/fixtury/locator_backend/common.rb
fixtury-1.0.1 lib/fixtury/locator_backend/common.rb
fixtury-1.0.0 lib/fixtury/locator_backend/common.rb
fixtury-1.0.0.beta7 lib/fixtury/locator_backend/common.rb
fixtury-1.0.0.beta6 lib/fixtury/locator_backend/common.rb
fixtury-1.0.0.beta5 lib/fixtury/locator_backend/common.rb
fixtury-1.0.0.beta4 lib/fixtury/locator_backend/common.rb
fixtury-1.0.0.beta3 lib/fixtury/locator_backend/common.rb
fixtury-1.0.0.beta2 lib/fixtury/locator_backend/common.rb
fixtury-1.0.0.beta1 lib/fixtury/locator_backend/common.rb