Sha256: 493276374b3e3bf9af55a36f7cf3e94ece5f9adeca5d4d845927da8b669b074b

Contents?: true

Size: 820 Bytes

Versions: 3

Compression:

Stored size: 820 Bytes

Contents

# frozen_string_literal: true

require "json"

require "key_vortex/adapter"
require "key_vortex/record"
require "stashify/file"

class KeyVortex
  class Adapter
    class Stashify < KeyVortex::Adapter
      def self.build(stashify:)
        new(stashify)
      end

      def initialize(stashify)
        super()
        @stashify = stashify
      end

      def save(record)
        @stashify.write(
          ::Stashify::File.new(
            name: record.key,
            contents: JSON.generate(record)
          )
        )
      end

      def find(key)
        return unless @stashify.exists?(key)

        JSON.parse(@stashify.find(key).contents, create_additions: true)
      end

      def remove(key)
        @stashify.delete(key)
      end
    end
  end
end

KeyVortex.register(KeyVortex::Adapter::Stashify)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
key_vortex-stashify-0.2.5 lib/key_vortex/adapter/stashify.rb
key_vortex-stashify-0.2.4 lib/key_vortex/adapter/stashify.rb
key_vortex-stashify-0.2.3 lib/key_vortex/adapter/stashify.rb