Class: Shark::RSpec::FakeSurveyService::ObjectCache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/shark/rspec/fake_survey_service/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_survey_service/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_survey_service/object_cache.rb', line 8

def objects
  @objects
end

Class Method Details

.clearObject



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

def self.clear
  instance.objects = []
end

Instance Method Details

#add(payload) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/shark/rspec/fake_survey_service/object_cache.rb', line 18

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

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

  payload
end

#find(id, type) ⇒ Object



26
27
28
# File 'lib/shark/rspec/fake_survey_service/object_cache.rb', line 26

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

#remove(id, type) ⇒ Object



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

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