Class: Shark::RSpec::FakeDoubleOptIn::ObjectCache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/shark/rspec/fake_double_opt_in/object_cache.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObjectCache

Returns a new instance of ObjectCache.



10
11
12
# File 'lib/shark/rspec/fake_double_opt_in/object_cache.rb', line 10

def initialize
  @objects = {}
end

Instance Attribute Details

#objectsObject

Returns the value of attribute objects.



8
9
10
# File 'lib/shark/rspec/fake_double_opt_in/object_cache.rb', line 8

def objects
  @objects
end

Class Method Details

.clearObject



14
15
16
# File 'lib/shark/rspec/fake_double_opt_in/object_cache.rb', line 14

def self.clear
  instance.objects = {}
end

Instance Method Details

#add_execution(attributes) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shark/rspec/fake_double_opt_in/object_cache.rb', line 18

def add_execution(attributes)
  verification_token = SecureRandom.uuid

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

  objects[verification_token]
end

#create_request(attributes) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/shark/rspec/fake_double_opt_in/object_cache.rb', line 38

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

#find_execution(verification_token) ⇒ Object



30
31
32
# File 'lib/shark/rspec/fake_double_opt_in/object_cache.rb', line 30

def find_execution(verification_token)
  objects[verification_token]
end

#remove_execution(verification_token) ⇒ Object



34
35
36
# File 'lib/shark/rspec/fake_double_opt_in/object_cache.rb', line 34

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