Sha256: 08b2696ca159e1685f6fe95efd7f75547202604b2c0e266b15570599400b2662

Contents?: true

Size: 745 Bytes

Versions: 11

Compression:

Stored size: 745 Bytes

Contents

# frozen_string_literal: true

module Shark
  module RSpec
    module FakeSurveyService
      class ObjectCache
        include Singleton
        attr_accessor :objects

        def initialize
          @objects = []
        end

        def self.clear
          instance.objects = []
        end

        def add(payload)
          payload['id'] = SecureRandom.uuid if payload['id'].blank?

          objects << payload unless objects.detect { |o| o['id'] == id }

          payload
        end

        def find(id, type)
          objects.detect { |o| o['id'] == id && o['type'] == type }
        end

        def remove(id, type)
          objects.delete_if { |o| o['id'] == id && o['type'] == type }
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bima-shark-sdk-3.1.1 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-2.5.0 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-3.1.0 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-3.0.0 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-2.4.4 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-2.4.3 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-2.4.2 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-2.4.1 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-2.4.0 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-2.3.1 lib/shark/rspec/fake_survey_service/object_cache.rb
bima-shark-sdk-2.3.0 lib/shark/rspec/fake_survey_service/object_cache.rb