Sha256: b1dea9d61842e52520e198a3d4f5e21b49839bbeed3a486a977c00b702eb7965

Contents?: true

Size: 1.63 KB

Versions: 11

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

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

        def initialize
          @objects = {}
        end

        def self.clear
          instance.objects = {}
        end

        def add_execution(attributes)
          verification_token = SecureRandom.uuid

          objects[verification_token] = {
            'id' => verification_token,
            'attributes' => attributes,
            'type' => 'executions'
          }

          objects[verification_token]
        end

        def find_execution(verification_token)
          objects[verification_token]
        end

        def remove_execution(verification_token)
          objects.delete(verification_token)
        end

        def create_request(attributes)
          timeout = attributes['timeout'] || 3600
          leeway_to_terminate = attributes['leeway_to_terminate'] || 3600

          verification_expires_at = Time.now.to_i + timeout.to_i
          execution_expires_at = verification_expires_at + leeway_to_terminate.to_i

          add_execution({
                          'payload' => attributes['payload'],
                          'request_type' => attributes['request_type'],
                          'max_verifications' => attributes['max_verifications'] || 10,
                          'verifications_count' => 0,
                          'verification_expires_at' => verification_expires_at,
                          'execution_expires_at' => execution_expires_at
                        })

          attributes
        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_double_opt_in/object_cache.rb
bima-shark-sdk-2.5.0 lib/shark/rspec/fake_double_opt_in/object_cache.rb
bima-shark-sdk-3.1.0 lib/shark/rspec/fake_double_opt_in/object_cache.rb
bima-shark-sdk-3.0.0 lib/shark/rspec/fake_double_opt_in/object_cache.rb
bima-shark-sdk-2.4.4 lib/shark/rspec/fake_double_opt_in/object_cache.rb
bima-shark-sdk-2.4.3 lib/shark/rspec/fake_double_opt_in/object_cache.rb
bima-shark-sdk-2.4.2 lib/shark/rspec/fake_double_opt_in/object_cache.rb
bima-shark-sdk-2.4.1 lib/shark/rspec/fake_double_opt_in/object_cache.rb
bima-shark-sdk-2.4.0 lib/shark/rspec/fake_double_opt_in/object_cache.rb
bima-shark-sdk-2.3.1 lib/shark/rspec/fake_double_opt_in/object_cache.rb
bima-shark-sdk-2.3.0 lib/shark/rspec/fake_double_opt_in/object_cache.rb